KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > stats > StatisticTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.stats;
17
18
19 import net.sf.dozer.util.mapping.DozerTestBase;
20
21 /**
22  * @author tierney.matt
23  */

24 public class StatisticTest extends DozerTestBase {
25   
26   public void testConstructor() throws Exception JavaDoc {
27     String JavaDoc type = getRandomString();
28     Statistic stat = new Statistic(type);
29     
30     assertEquals("invalid type", type, stat.getType());
31   }
32   
33   public void testEquals() throws Exception JavaDoc {
34     String JavaDoc 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 JavaDoc {
43     Statistic stat = new Statistic(getRandomString());
44     int numEntriesToAdd = 5;
45     for (int i = 0; i < numEntriesToAdd; i++) {
46       String JavaDoc 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 JavaDoc {
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 JavaDoc {
71     String JavaDoc 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 JavaDoc {
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 JavaDoc e) {
93     }
94   }
95 }
96
Popular Tags