1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.conf;
2021import org.junit.Test;
2223importstatic org.apache.giraph.conf.ClassConfOption.getClassesOfType;
24importstatic org.junit.Assert.assertEquals;
25importstatic org.junit.Assert.fail;
2627publicclassTestGiraphConfiguration {
28publicinterfaceIf { }
29publicclassAimplementsIf { }
30publicclassBimplementsIf { }
31publicclassCimplementsIf { }
3233 @Test
34publicvoid testSetClasses() {
35 GiraphConfiguration conf = new GiraphConfiguration();
36 conf.setClasses("foo", If.class, A.class, B.class);
37 Class<?>[] klasses = conf.getClasses("foo");
38 assertEquals(2, klasses.length);
39 assertEquals(A.class, klasses[0]);
40 assertEquals(B.class, klasses[1]);
4142try {
43 conf.setClasses("foo", A.class, B.class);
44 fail();
45 } catch (RuntimeException e) {
46 assertEquals(2, conf.getClasses("foo").length);
47 }
4849 Class<? extends If>[] klasses2 = getClassesOfType(conf, "foo", If.class);
50 assertEquals(2, klasses2.length);
51 assertEquals(A.class, klasses2[0]);
52 assertEquals(B.class, klasses2[1]);
53 }
5455 @Test
56publicvoid testAddToClasses() {
57 GiraphConfiguration conf = new GiraphConfiguration();
5859 conf.setClasses("foo", If.class, A.class, B.class);
60 ClassConfOption.addToClasses(conf, "foo", C.class, If.class);
61 Class<?>[] klasses = conf.getClasses("foo");
62 assertEquals(3, klasses.length);
63 assertEquals(A.class, klasses[0]);
64 assertEquals(B.class, klasses[1]);
65 assertEquals(C.class, klasses[2]);
6667 ClassConfOption.addToClasses(conf, "bar", B.class, If.class);
68 klasses = conf.getClasses("bar");
69 assertEquals(1, klasses.length);
70 assertEquals(B.class, klasses[0]);
71 }
72 }