1 package org.jboss.cache.notifications; 2 3 import junit.framework.TestCase; 4 import org.jboss.cache.util.Util; 5 6 import java.util.HashMap ; 7 import java.util.Map ; 8 9 15 public class NodeMapDiffTest extends TestCase 16 { 17 public void testDataAdded() 18 { 19 Util.MapModifications expected = new Util.MapModifications(); 20 expected.addedEntries.put("key", "value"); 21 expected.addedEntries.put("key1", "value1"); 22 23 Map pre = new HashMap (); 24 pre.put("oldKey", "oldValue"); 25 26 Map post = new HashMap (); 27 post.putAll(pre); 28 post.put("key", "value"); 29 post.put("key1", "value1"); 30 31 assertEquals(expected, Util.diffNodeData(pre, post)); 32 } 33 34 public void testDataRemoved() 35 { 36 Util.MapModifications expected = new Util.MapModifications(); 37 expected.removedEntries.put("key", "value"); 38 expected.removedEntries.put("key1", "value1"); 39 40 Map post = new HashMap (); 41 post.put("oldKey", "oldValue"); 42 43 Map pre = new HashMap (); 44 pre.putAll(post); 45 pre.put("key", "value"); 46 pre.put("key1", "value1"); 47 48 assertEquals(expected, Util.diffNodeData(pre, post)); 49 } 50 51 public void testDataChanged() 52 { 53 Util.MapModifications expected = new Util.MapModifications(); 54 expected.modifiedEntries.put("key", "value"); 55 expected.modifiedEntries.put("key1", "value1"); 56 57 Map pre = new HashMap (); 58 pre.put("oldKey", "oldValue"); 59 pre.put("key", "valueOLD"); 60 pre.put("key1", "value1OLD"); 61 62 Map post = new HashMap (); 63 post.putAll(pre); 64 post.put("key", "value"); 65 post.put("key1", "value1"); 66 67 assertEquals(expected, Util.diffNodeData(pre, post)); 68 } 69 70 public void testNullMaps() 71 { 72 try 73 { 74 Util.diffNodeData(null, null); 75 fail("Expected NPE"); 76 } 77 catch (NullPointerException npe) 78 { 79 } 81 82 try 83 { 84 Util.diffNodeData(new HashMap (), null); 85 fail("Expected NPE"); 86 } 87 catch (NullPointerException npe) 88 { 89 } 91 92 try 93 { 94 Util.diffNodeData(null, new HashMap ()); 95 fail("Expected NPE"); 96 } 97 catch (NullPointerException npe) 98 { 99 } 101 102 } 103 104 public void testEmptyMaps() 105 { 106 Util.MapModifications expected = new Util.MapModifications(); 107 108 Map pre = new HashMap (); 109 Map post = new HashMap (); 110 111 assertEquals(expected, Util.diffNodeData(pre, post)); 112 } 113 114 public void testNoChange() 115 { 116 Util.MapModifications expected = new Util.MapModifications(); 117 118 Map pre = new HashMap (); 119 pre.put("a", "b"); 120 pre.put("c", "d"); 121 pre.put("e", "f"); 122 123 Map post = new HashMap (); 124 post.put("a", "b"); 125 post.put("c", "d"); 126 post.put("e", "f"); 127 128 assertEquals(expected, Util.diffNodeData(pre, post)); 129 } 130 131 public void testMultipleChanges() 132 { 133 Util.MapModifications expected = new Util.MapModifications(); 134 expected.modifiedEntries.put("key", "value"); 135 expected.modifiedEntries.put("key1", "value1"); 136 expected.addedEntries.put("key2", "value2"); 137 expected.addedEntries.put("key3", "value3"); 138 expected.removedEntries.put("key4", "value4"); 139 expected.removedEntries.put("key5", "value5"); 140 141 Map pre = new HashMap (); 142 pre.put("oldKey", "oldValue"); 143 pre.put("key", "valueOLD"); 144 pre.put("key1", "value1OLD"); 145 pre.put("key4", "value4"); 146 pre.put("key5", "value5"); 147 148 Map post = new HashMap (); 149 post.put("oldKey", "oldValue"); 150 post.put("key", "value"); 151 post.put("key1", "value1"); 152 post.put("key2", "value2"); 153 post.put("key3", "value3"); 154 155 assertEquals(expected, Util.diffNodeData(pre, post)); 156 } 157 158 } 159 | Popular Tags |