KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > TypeTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.config;
5
6 import java.util.Set JavaDoc;
7
8 import junit.framework.TestCase;
9
10 /**
11  * Test case for Type
12  */

13 public class TypeTest extends TestCase {
14
15   private Type type;
16
17   protected void setUp() throws Exception JavaDoc {
18     super.setUp();
19     this.type = new Type();
20   }
21
22   public void testGetSetName() {
23     assertTrue(type.getName() == null);
24     type.setName("MyClassName");
25     assertNotNull(type.getName());
26     
27     try {
28       type.setName(null);
29       fail("Should have thrown an exception");
30     } catch (IllegalArgumentException JavaDoc e) {
31       // expected
32
}
33     
34     try {
35       type.setName("");
36       fail("Should have thrown an exception");
37     } catch (IllegalArgumentException JavaDoc e) {
38       // expected
39
}
40   }
41
42   public void testAddTransient() {
43     assertNotNull(type.getTransients());
44     assertEquals(0, type.getTransients().size());
45     String JavaDoc transientName = "transient1";
46     type.addTransient(transientName);
47     assertEquals(1, type.getTransients().size());
48     assertTrue(type.getTransients().contains(transientName));
49     
50     type.addTransient(transientName);
51     assertEquals(1, type.getTransients().size());
52     
53     try {
54       type.addTransient(null);
55       fail("Expected IllegalArgumentException");
56     } catch (IllegalArgumentException JavaDoc e) {
57       // expected
58
}
59     
60     try {
61       type.addTransient("");
62       fail("Expected IllegalArgumentException");
63     } catch (IllegalArgumentException JavaDoc e) {
64       // expected
65
}
66     
67     try {
68       type.addTransient(" ");
69       fail("Expected IllegalArgumentException");
70     } catch (IllegalArgumentException JavaDoc e) {
71       // expected
72
}
73   }
74
75   public void testAddTransients() {
76     String JavaDoc[] transients = new String JavaDoc[] { "test1", "test2" };
77     
78     assertEquals(0, type.getTransients().size());
79     type.addTransients(transients);
80     assertEquals(transients.length, type.getTransients().size());
81     for (int i=0; i<transients.length; i++) {
82       assertTrue(type.getTransients().contains(transients[i]));
83     }
84   }
85
86   public void testGetTransients() {
87     type.addTransient("test");
88     Set JavaDoc s1 = type.getTransients();
89     type.addTransient("test1");
90     Set JavaDoc s2 = type.getTransients();
91     
92     assertEquals(1, s1.size());
93     assertEquals(2, s2.size());
94   }
95
96   public void testCommit() {
97     // once the type has been committed, you shouldn't be able to alter it.
98
type.setName("test");
99     type.addTransient("test1");
100     type.commit();
101     try {
102       type.setName("test");
103       fail("Should throw an exception");
104     } catch (IllegalStateException JavaDoc e) {
105       // expected
106
}
107     
108     try {
109       type.addTransient("test1");
110       fail("Should have thrown an exception");
111     } catch (IllegalStateException JavaDoc e) {
112       // expected
113
}
114     
115     try {
116       type.addTransients(new String JavaDoc[] {"test"});
117       fail("Should have thrown an exception");
118     } catch (IllegalStateException JavaDoc e) {
119       // expected
120
}
121   }
122   
123   public void testValidate() {
124     type.setName("Test");
125     type.validate();
126
127     type = new Type();
128     try {
129       type.validate();
130       fail("Should have thrown an IllegalArgumentException");
131     } catch (IllegalArgumentException JavaDoc e) {
132       // expected
133
}
134   }
135
136 }
137
Popular Tags