1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import static org.junit.Assert.*;
import org.junit.*;

public final class TestHeterogeneousHashMap {

	private HeterogeneousHashMap<String> map;
	private final String key;
	private final String value;

	public TestHeterogeneousHashMap() {
		key = "key";
		value = "value";
	}

	@Before
	public void setUp() {
		map = HeterogeneousHashMap.create();
	}

	@Test
	public void testSizeAtStartUp() {
		assertEquals(0, map.size());
	}

	@Test
	public void testSizeShouldBeOne() {
		map.put(key, value);
		assertEquals(1, map.size());
	}

	@Test
	public void testSizeShouldStillBeOne() {
		map.put(key, value);
		map.put(key, "bla");
		assertEquals(1, map.size());
	}

	@Test
	public void testPutReferenceNull() {
		map.put(key, null);
		//doesn't matter which REFERENCE type it is
		Integer actual = map.get(key);
		@SuppressWarnings("unused")
		String actualS = map.get(key);
		@SuppressWarnings("unused")
		Object actualO = map.get(key);
		assertEquals(1, map.size());
		assertNull(actual);
	}

	@Test
	public void testPutNullKey() {
		map.put(null, value);
		assertEquals(0, map.size());
	}

	@Test
	public void testShouldReplaceElementWithSameKey() {
		map.put(key, 1337);
		String expected = "expected";
		map.put(key, expected);
		String actual = map.get(key);
		assertEquals(expected, actual);
	}

	@Test
	public void testGetChar() {
		map.put(key, '3');
		assertEquals(map.get(key), map.getChar(key));
	}

	@Test
	public void testGetByte() {
		map.put(key, (byte)3);
		assertEquals(map.get(key), map.getByte(key));
	}
	
	@Test
	public void testGetShort() {
		map.put(key, (short)3);
		assertEquals(map.get(key), map.getShort(key));
	}
	
	@Test
	public void testGetInt() {
		map.put(key, 3);
		assertEquals(map.get(key), map.getInt(key));
	}
	
	@Test
	public void testGetLong() {
		map.put(key, (long)3);
		assertEquals(map.get(key), map.getLong(key));
	}
	
	@Test
	public void testGetBoolean() {
		map.put(key, true);
		assertEquals(map.get(key), map.getBoolean(key));
	}
	
	@Test
	public void testGetFloat() {
		map.put(key, 3f);
		assertEquals(map.get(key), map.getFloat(key));
	}
	
	@Test
	public void testGetDouble() {
		map.put(key, 3d);
		assertEquals(map.get(key), map.getDouble(key));
	}
	
	@Test
	public void testConvertNullToDefaultChar() {
		map.put(key, value);
		assertEquals('0', map.getChar(key));
	}

	@Test
	public void testConvertNullToDefaultByte() {
		map.put(key, value);
		assertEquals(0, map.getByte(key));
	}

	@Test
	public void testConvertNullToDefaultShort() {
		map.put(key, value);
		assertEquals(0, map.getShort(key));
	}

	@Test
	public void testConvertNullToDefaultInt() {
		map.put(key, value);
		assertEquals(0, map.getInt(key));
	}

	@Test
	public void testConvertNullToDefaultLong() {
		map.put(key, value);
		assertEquals(0, map.getLong(key));
	}

	@Test
	public void testConvertNullToDefaultBoolean() {
		map.put(key, value);
		assertEquals(false, map.getBoolean(key));
	}

	@Test
	public void testConvertNullToDefaultFloat() {
		map.put(key, value);
		assertEquals(0, Float.floatToIntBits(map.getFloat(key)));
	}

	@Test
	public void testConvertNullToDefaultDouble() {
		map.put(key, value);
		assertEquals(0, Double.doubleToLongBits(map.getDouble(key)));
	}

	@Test
	public void testSizeShouldStillBeZero() {
		map.remove(key);
		assertEquals(0, map.size());
	}

	@Test
	public void testShouldGetElement() {
		map.put(key, value);
		String actual = map.get(key);
		assertEquals(value, actual);

		String key2 = "key2";
		int value2 = 2;
		map.put(key2, value2);
		int actual2 = map.get(key2);
		assertEquals(value2, actual2);
	}

	@Test
	public void testShouldReturnNullIfElementDoesNotExist() {
		assertNull(map.get(key));
	}
	
	@Test
	public void testContains() {
		assertFalse(map.contains(key));
		map.put(key, value);
		assertTrue(map.contains(key));
	}
	
	@Test
	public void getNullKey() {
		map.put(null, value);
	}
	
}