View Javadoc
1 // $Id: KeyTest.java,v 1.1.1.1 2002/09/29 17:26:07 powerpete Exp $ 2 package de.jface.util; 3 4 import junit.framework.TestCase; 5 6 /*** 7 * The test case <code>KeyTest</code> 8 * tests the [your text here]. 9 * 10 * @author Moritz Petersen 11 * @version $Revision: 1.1.1.1 $ 12 */ 13 public class KeyTest extends TestCase 14 { 15 /*** 16 * This constructor creates a new 17 * KeyTest test case. 18 */ 19 public KeyTest(String name) 20 { 21 super(name); 22 } 23 24 /*** 25 * This method tests [your text here]. 26 */ 27 public void testValue() 28 { 29 Key key = new Key("test"); 30 String value = "foobar"; 31 32 key.setValue(value); 33 34 String result = key.getValue(); 35 36 assertEquals(value, result); 37 } 38 39 public void testCompareTo() 40 { 41 String name1 = "name1"; 42 String name2 = "name2"; 43 String name3 = "name3"; 44 45 Key norm = new Key(name2); 46 47 assertTrue("CompareTo is not positive.", 48 norm.compareTo(new Key(name1)) > 0); 49 assertTrue("CompareTo is not equal.", 50 norm.compareTo(new Key(name2)) == 0); 51 assertTrue("CompareTo is not negative.", 52 norm.compareTo(new Key(name3)) < 0); 53 } 54 55 /*** 56 * Tests the method getKey. This test doesn't just test the plain method, 57 * it also expects that the returned key is the same instance than before. 58 * To make a reality-check, the key will be assigned with a value. 59 */ 60 public void testGetKey() 61 { 62 Key root = new Key("root"); 63 String keyName = "foo"; 64 Key expectedKey = root.getKey(keyName); 65 String expectedValue = "bar"; 66 67 expectedKey.setValue(expectedValue); 68 69 Key resultKey = root.getKey(keyName); 70 71 assertEquals("Returned keys are not equal.", expectedKey, resultKey); 72 73 String resultValue = resultKey.getValue(); 74 75 assertEquals("Returned values are not equal.", expectedValue, 76 resultValue); 77 } 78 79 /*** 80 * Tests the remove method. The first part of the test will take part with 81 * a key without parent (<code>parent == null</code>). In this case the remove 82 * method should return <code>false</code>. The second part will take part 83 * with a key that has a parent, where the remove mehtod should return 84 * <code>true</code>. 85 */ 86 public void testRemove() 87 { 88 Key root = new Key("root"); 89 90 assertTrue(!root.remove()); 91 92 Key key = root.getKey("foo"); 93 94 assertTrue(key.remove()); 95 96 key = root.getKey("foo").getKey("bar"); 97 assertEquals(root.getChildren().size(), 1); 98 key.remove(); 99 assertEquals(root.getChildren().size(), 0); 100 101 key = root.getKey("foo").getKey("bar"); 102 root.getKey("foo").setValue("bar"); 103 assertEquals(root.getChildren().size(), 1); 104 key.remove(); 105 assertEquals(root.getChildren().size(), 1); 106 } 107 108 /*** 109 * The focus of this test is to test the contains() method with a deep 110 * hierarchy and with multiple instances of keys with the same name. 111 */ 112 public void testContains() 113 { 114 Key root = new Key("root"); 115 116 root.getKey("foo").getKey("bar"); 117 assertTrue("root doesn't contain root", root.contains(new Key("root"))); 118 assertTrue("root doesn't contain bar", root.contains(new Key("bar"))); 119 120 root.getKey("bar"); 121 assertTrue("root doesn't contain bar", root.contains(new Key("bar"))); 122 } 123 124 public void testToString() 125 { 126 Key key = new Key("root").getKey("foo").getKey("bar"); 127 128 System.out.println(key.toString()); 129 assertEquals("root.foo.bar", key.toString()); 130 } 131 132 public void testName() 133 { 134 // must not throw an IllegalArgumentException 135 Key key = new Key("root"); 136 137 // will throw an IllegalArgumentException 138 try 139 { 140 key = new Key("foo bar"); 141 142 143 // this assertion must not be reached. 144 assertTrue(false); 145 } 146 catch (Exception e) 147 { 148 assertNotNull(e); 149 } 150 } 151 } 152 153 // ------1---------2---------3---------4---------5---------6---------7---------8

This page was automatically generated by Maven