1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.archive.crawler.settings;
26
27 import junit.framework.TestCase;
28
29
30 /***
31 * Testing of the SimpleType
32 *
33 * @author John Erik Halse
34 */
35 public class SimpleTypeTest extends TestCase {
36 public void testGetName() {
37 SimpleType t1 = new SimpleType("a", "b", "c");
38 assertEquals("a", t1.getName());
39 }
40
41 public void testGetDescription() {
42 SimpleType t1 = new SimpleType("a", "b", "c");
43 assertEquals("b", t1.getDescription());
44 }
45
46 public void testGetDefaultValue() {
47 SimpleType t1 = new SimpleType("a", "b", "c");
48 assertEquals("c", t1.getDefaultValue());
49 }
50
51 public void testGetLegalValues() {
52 SimpleType t1 = new SimpleType("a", "b", "c", new String[] {"d", "e"});
53 checkArray(new String[] {"d", "e"}, t1.getLegalValues());
54 }
55
56 public void testSetLegalValues() {
57 SimpleType t1 = new SimpleType("a", "b", "c", new String[] {"d", "e"});
58 t1.setLegalValues(new String[] {"f", "g"});
59 checkArray(new String[] {"f", "g"}, t1.getLegalValues());
60 }
61
62 public void testGetConstraints() {
63 SimpleType t1 = new SimpleType("a1", "b1", "c1");
64 SimpleType t2 = new SimpleType("a2", "b2", "c2", new String[] {"d", "e"});
65 assertNotNull(t1.getConstraints());
66 assertSame(LegalValueTypeConstraint.class, t2.getConstraints().get(0)
67 .getClass());
68 assertSame(LegalValueListConstraint.class, t2.getConstraints().get(1)
69 .getClass());
70 }
71
72 public void testGetLegalValueType() {
73 SimpleType t1 = new SimpleType("a1", "b1", "c1");
74 SimpleType t2 = new SimpleType("a2", "b2", new Integer(1));
75 SimpleType t3 = new SimpleType("a3", "b3", new TextField("c3"));
76 assertSame(String.class, t1.getLegalValueType());
77 assertSame(Integer.class, t2.getLegalValueType());
78 assertSame(TextField.class, t3.getLegalValueType());
79 }
80
81 public void testEquals() {
82 SimpleType t1 = new SimpleType("a1", "b1", "c1");
83 SimpleType t2 = new SimpleType("a1", "b1", "c1");
84 SimpleType t3 = new SimpleType("a2", "b2", "c2");
85 assertTrue(t1.equals(t2));
86 assertFalse(t1.equals(t3));
87 assertTrue(t1.equals(t1));
88 assertFalse(t1.equals(null));
89 }
90
91 private void checkArray(Object a1[], Object a2[]) {
92 assertEquals("Arrays not of same length.", a1.length, a2.length);
93 for (int i = 0; i < a1.length; i++) {
94 assertEquals(a1[i], a2[i]);
95 }
96 }
97 }