1 16 package net.sf.dozer.util.mapping.stats; 17 18 19 import net.sf.dozer.util.mapping.DozerTestBase; 20 21 24 public class StatisticTest extends DozerTestBase { 25 26 public void testConstructor() throws Exception { 27 String type = getRandomString(); 28 Statistic stat = new Statistic(type); 29 30 assertEquals("invalid type", type, stat.getType()); 31 } 32 33 public void testEquals() throws Exception { 34 String type = getRandomString(); 35 Statistic stat = new Statistic(type); 36 Statistic stat2 = new Statistic(type); 37 38 assertEquals("objects should be equal", stat, stat2); 39 assertEquals("objects hashcode should be equal", stat.hashCode(), stat2.hashCode()); 40 } 41 42 public void testAddGetEntries() throws Exception { 43 Statistic stat = new Statistic(getRandomString()); 44 int numEntriesToAdd = 5; 45 for (int i = 0; i < numEntriesToAdd; i++) { 46 String key = "testkey" + String.valueOf(i); 47 StatisticEntry entry = new StatisticEntry(key); 48 stat.addEntry(entry); 49 50 assertEquals("invalid entry size", i + 1, stat.getEntries().size()); 51 52 StatisticEntry entry2 = stat.getEntry(key); 53 assertNotNull("stat entry should not be null", entry2); 54 assertEquals("stat entries should be equal", entry, entry2); 55 assertSame("stat entries should be same instance", entry, entry2); 56 } 57 assertEquals("invlid stat size", numEntriesToAdd, stat.getEntries().size()); 58 } 59 60 public void testClear() throws Exception { 61 Statistic stat = new Statistic(getRandomString()); 62 StatisticEntry entry = new StatisticEntry(getRandomString()); 63 stat.addEntry(entry); 64 65 assertEquals("stat should contain entry", 1, stat.getEntries().size()); 66 stat.clear(); 67 assertEquals("stat entries should have been cleared", 0, stat.getEntries().size()); 68 } 69 70 public void testGetEntryWithDefaultKey() throws Exception { 71 String type = getRandomString(); 72 Statistic stat = new Statistic(type); 73 StatisticEntry entry = new StatisticEntry(type); 74 stat.addEntry(entry); 75 76 assertEquals("invalid entry found", entry, stat.getEntry()); 77 } 78 79 public void testGetEntryWithDefaultKeyNotFound() throws Exception { 80 Statistic stat = new Statistic(getRandomString()); 81 StatisticEntry entry = new StatisticEntry(getRandomString()); 82 stat.addEntry(entry); 83 84 assertNull("entry should not have been found", stat.getEntry()); 85 } 86 87 public void testAddNull() { 88 Statistic stat = new Statistic(getRandomString()); 89 try { 90 stat.addEntry(null); 91 fail("should have thrown exception"); 92 } catch (IllegalArgumentException e) { 93 } 94 } 95 } 96 | Popular Tags |