blob: fb3f1950248f0820b6f5609c0d0208c950121122 [file] [log] [blame]
Simon Hunt95d56fd2015-11-12 11:06:44 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Hunt95d56fd2015-11-12 11:06:44 -08003 *
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
17package org.onlab.util;
18
19import org.junit.Test;
20
21import static org.junit.Assert.assertEquals;
22
23/**
24 * Unit tests for {@link DefaultHashMap}.
25 */
26public class DefaultHashMapTest {
27
28 private static final String ONE = "one";
29 private static final String TWO = "two";
30 private static final String THREE = "three";
31 private static final String FOUR = "four";
32
33 private static final String ALPHA = "Alpha";
34 private static final String BETA = "Beta";
35 private static final String OMEGA = "Omega";
36
37 private DefaultHashMap<String, Integer> map;
38 private DefaultHashMap<String, String> chartis;
39
40 private void loadMap() {
41 map.put(ONE, 1);
42 map.put(TWO, 2);
43 }
44
45 private void fortioCharti() {
46 chartis.put(ONE, ALPHA);
47 chartis.put(TWO, BETA);
48 }
49
50 @Test
51 public void nullDefaultIsAllowed() {
52 // but makes this class behave no different than HashMap
53 map = new DefaultHashMap<>(null);
54 loadMap();
55 assertEquals("missing 1", 1, (int) map.get(ONE));
56 assertEquals("missing 2", 2, (int) map.get(TWO));
57 assertEquals("three?", null, map.get(THREE));
58 assertEquals("four?", null, map.get(FOUR));
59 }
60
61 @Test
62 public void defaultToFive() {
63 map = new DefaultHashMap<>(5);
64 loadMap();
65 assertEquals("missing 1", 1, (int) map.get(ONE));
66 assertEquals("missing 2", 2, (int) map.get(TWO));
67 assertEquals("three?", 5, (int) map.get(THREE));
68 assertEquals("four?", 5, (int) map.get(FOUR));
69 }
70
71 @Test
72 public void defaultToOmega() {
73 chartis = new DefaultHashMap<>(OMEGA);
74 fortioCharti();
75 assertEquals("missing 1", ALPHA, chartis.get(ONE));
76 assertEquals("missing 2", BETA, chartis.get(TWO));
77 assertEquals("three?", OMEGA, chartis.get(THREE));
78 assertEquals("four?", OMEGA, chartis.get(FOUR));
79 }
80
81}