From 8ea31542ed6db7c0dfb2144cd827aae48f08a94e Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Thu, 6 Jul 2017 00:17:17 +0100 Subject: [PATCH] Code Snippet for BidiMap BAEL-963 (#2204) * added updated example codes * updated example code StringToCharStream * deleted StringToCharStream.java locally * removed redundant file * added code for apache commons collection SetUtils * refactored example code --- .../commons/collections/BidiMapUnitTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java b/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java new file mode 100644 index 0000000000..64a3932fb3 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.commons.collections; + +import org.apache.commons.collections4.BidiMap; +import org.apache.commons.collections4.bidimap.DualHashBidiMap; +import org.apache.commons.collections4.bidimap.DualLinkedHashBidiMap; +import org.apache.commons.collections4.bidimap.DualTreeBidiMap; +import org.apache.commons.collections4.bidimap.TreeBidiMap; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by smatt on 03/07/2017. + */ +public class BidiMapUnitTest { + + @Test + public void givenKeyValue_whenPut_thenAddEntryToMap() { + BidiMap map = new DualHashBidiMap<>(); + map.put("key1", "value1"); + map.put("key2", "value2"); + assertEquals(map.size(), 2); + } + + @Test + public void whenInverseBidiMap_thenInverseKeyValue() { + BidiMap map = new DualHashBidiMap<>(); + map.put("key1", "value1"); + map.put("key2", "value2"); + BidiMap rMap = map.inverseBidiMap(); + assertTrue(rMap.containsKey("value1") && rMap.containsKey("value2")); + } + + @Test + public void givenValue_whenRemoveValue_thenRemoveMatchingMapEntry() { + BidiMap map = new DualHashBidiMap<>(); + map.put("key1", "value1"); + map.put("key2", "value2"); + map.removeValue("value2"); + assertFalse(map.containsKey("key2")); + } + + @Test + public void givenValue_whenGetKey_thenMappedKey() { + BidiMap map = new DualHashBidiMap<>(); + map.put("key1", "value1"); + assertEquals(map.getKey("value1"), "key1"); + } +}