1 package net.sourceforge.pmd.util;
2
3 import static org.junit.Assert.fail;
4
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import junit.framework.Assert;
10
11 import org.junit.Test;
12
13
14
15
16
17
18 public class TypeMapTest {
19
20 @Test
21 public void testAddClassOfQ() {
22
23 TypeMap map = new TypeMap(2);
24 map.add(java.util.List.class);
25
26 try {
27 map.add(java.awt.List.class);
28 } catch (IllegalArgumentException ex) {
29 return;
30 }
31
32 fail("Uncaught error inserting type with same root names");
33 }
34
35 @Test
36 public void testContainsClassOfQ() {
37
38 TypeMap map = new TypeMap(2);
39 map.add(String.class);
40 map.add(List.class);
41
42 Assert.assertTrue(map.contains(String.class));
43 Assert.assertTrue(map.contains(List.class));
44 Assert.assertFalse(map.contains(Map.class));
45 }
46
47 @Test
48 public void testContainsString() {
49
50 TypeMap map = new TypeMap(2);
51 map.add(String.class);
52 map.add(List.class);
53
54 Assert.assertTrue(map.contains("String"));
55 Assert.assertTrue(map.contains("java.lang.String"));
56 }
57
58 @Test
59 public void testTypeFor() {
60
61 TypeMap map = new TypeMap(2);
62 map.add(String.class);
63 map.add(List.class);
64
65 Assert.assertTrue(map.typeFor("String") == String.class);
66 Assert.assertTrue(map.typeFor("java.lang.String") == String.class);
67 Assert.assertTrue(map.typeFor("List") == List.class);
68 Assert.assertTrue(map.typeFor("java.util.List") == List.class);
69 }
70
71 @Test
72 public void testSize() {
73
74 TypeMap map = new TypeMap(4);
75 map.add(String.class);
76 map.add(HashMap.class);
77 map.add(Integer.class);
78
79 Assert.assertTrue(map.size() == 6);
80 }
81
82 public static junit.framework.Test suite() {
83 return new junit.framework.JUnit4TestAdapter(TypeMapTest.class);
84 }
85
86 }