1 4 package com.tc.object.config; 5 6 import java.util.Set ; 7 8 import junit.framework.TestCase; 9 10 13 public class TypeTest extends TestCase { 14 15 private Type type; 16 17 protected void setUp() throws Exception { 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 e) { 31 } 33 34 try { 35 type.setName(""); 36 fail("Should have thrown an exception"); 37 } catch (IllegalArgumentException e) { 38 } 40 } 41 42 public void testAddTransient() { 43 assertNotNull(type.getTransients()); 44 assertEquals(0, type.getTransients().size()); 45 String 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 e) { 57 } 59 60 try { 61 type.addTransient(""); 62 fail("Expected IllegalArgumentException"); 63 } catch (IllegalArgumentException e) { 64 } 66 67 try { 68 type.addTransient(" "); 69 fail("Expected IllegalArgumentException"); 70 } catch (IllegalArgumentException e) { 71 } 73 } 74 75 public void testAddTransients() { 76 String [] transients = new String [] { "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 s1 = type.getTransients(); 89 type.addTransient("test1"); 90 Set s2 = type.getTransients(); 91 92 assertEquals(1, s1.size()); 93 assertEquals(2, s2.size()); 94 } 95 96 public void testCommit() { 97 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 e) { 105 } 107 108 try { 109 type.addTransient("test1"); 110 fail("Should have thrown an exception"); 111 } catch (IllegalStateException e) { 112 } 114 115 try { 116 type.addTransients(new String [] {"test"}); 117 fail("Should have thrown an exception"); 118 } catch (IllegalStateException e) { 119 } 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 e) { 132 } 134 } 135 136 } 137 | Popular Tags |