1010import static com .jnape .palatable .lambda .adt .hmap .HMap .hMap ;
1111import static com .jnape .palatable .lambda .adt .hmap .HMap .singletonHMap ;
1212import static com .jnape .palatable .lambda .adt .hmap .TypeSafeKey .typeSafeKey ;
13- import static java .util .Collections .emptyMap ;
14- import static java .util .Collections .singletonMap ;
1513import static org .junit .Assert .assertEquals ;
1614import static org .junit .Assert .assertFalse ;
1715import static org .junit .Assert .assertNotEquals ;
@@ -26,29 +24,30 @@ public class HMapTest {
2624 public void getForPresentKey () {
2725 TypeSafeKey <String > stringKey = typeSafeKey ();
2826 assertEquals (Optional .of ("string value" ),
29- new HMap ( singletonMap ( stringKey , "string value" ) ).get (stringKey ));
27+ singletonHMap ( stringKey , "string value" ).get (stringKey ));
3028 }
3129
3230 @ Test
3331 public void getForAbsentKey () {
3432 assertEquals (Optional .empty (),
35- new HMap (singletonMap (typeSafeKey (), "string value" )).<String >get (typeSafeKey ()));
33+ singletonHMap (typeSafeKey (), "string value" )
34+ .get (typeSafeKey ()));
3635 }
3736
3837 @ Test
3938 public void getForPresentKeyWithNullValue () {
4039 TypeSafeKey <String > stringKey = typeSafeKey ();
4140 assertEquals (Optional .empty (),
42- new HMap ( singletonMap ( stringKey , null ) ).get (stringKey ));
41+ singletonHMap ( stringKey , null ).get (stringKey ));
4342 }
4443
4544 @ Test
4645 public void put () {
4746 TypeSafeKey <String > stringKey = typeSafeKey ();
48- assertEquals (new HMap ( singletonMap ( stringKey , "string value" ) ),
47+ assertEquals (singletonHMap ( stringKey , "string value" ),
4948 emptyHMap ().put (stringKey , "string value" ));
5049
51- assertEquals (new HMap ( singletonMap ( stringKey , "new value" ) ),
50+ assertEquals (singletonHMap ( stringKey , "new value" ),
5251 emptyHMap ()
5352 .put (stringKey , "string value" )
5453 .put (stringKey , "new value" ));
@@ -75,6 +74,35 @@ public void putAll() {
7574 right .putAll (left ));
7675 }
7776
77+ @ Test
78+ public void remove () {
79+ TypeSafeKey <String > stringKey1 = typeSafeKey ();
80+ TypeSafeKey <String > stringKey2 = typeSafeKey ();
81+ assertEquals (emptyHMap (),
82+ emptyHMap ()
83+ .put (stringKey1 , "string value" )
84+ .remove (stringKey1 ));
85+
86+ assertEquals (singletonHMap (stringKey2 , "another string value" ),
87+ emptyHMap ()
88+ .put (stringKey1 , "string value" )
89+ .put (stringKey2 , "another string value" )
90+ .remove (stringKey1 ));
91+ }
92+
93+ @ Test
94+ public void removeAll () {
95+ TypeSafeKey <String > stringKey1 = typeSafeKey ();
96+ TypeSafeKey <String > stringKey2 = typeSafeKey ();
97+
98+ HMap hMap1 = hMap (stringKey1 , "foo" ,
99+ stringKey2 , "bar" );
100+ HMap hMap2 = singletonHMap (stringKey1 , "foo" );
101+
102+ assertEquals (singletonHMap (stringKey2 , "bar" ),
103+ hMap1 .removeAll (hMap2 ));
104+ }
105+
78106 @ Test
79107 public void containsKey () {
80108 TypeSafeKey <String > stringKey1 = typeSafeKey ();
@@ -127,8 +155,8 @@ public void convenienceStaticFactoryMethods() {
127155 TypeSafeKey <String > stringKey = typeSafeKey ();
128156 TypeSafeKey <Integer > intKey = typeSafeKey ();
129157 TypeSafeKey <Float > floatKey = typeSafeKey ();
130- assertEquals (new HMap ( emptyMap ()), HMap . emptyHMap ());
131- assertEquals ( new HMap ( singletonMap ( stringKey , "string value" )), HMap . singletonHMap (stringKey , "string value" ));
158+ assertEquals (emptyHMap (). put ( stringKey , "string value" ),
159+ singletonHMap (stringKey , "string value" ));
132160 assertEquals (emptyHMap ().put (stringKey , "string value" ).put (intKey , 1 ),
133161 hMap (stringKey , "string value" ,
134162 intKey , 1 ));
@@ -157,13 +185,12 @@ public void equality() {
157185 public void hashCodeUsesDecentDistribution () {
158186 assertEquals (emptyHMap ().hashCode (), emptyHMap ().hashCode ());
159187 TypeSafeKey <String > stringKey = typeSafeKey ();
160- assertEquals (new HMap (singletonMap (stringKey , "string value" )).hashCode (),
161- new HMap (singletonMap (stringKey , "string value" )).hashCode ());
162-
163- assertNotEquals (emptyHMap (), new HMap (singletonMap (stringKey , "string value" )));
164- assertNotEquals (new HMap (singletonMap (stringKey , "string value" )),
165- new HMap (singletonMap (stringKey , "another string value" )));
188+ assertEquals (singletonHMap (stringKey , "string value" ).hashCode (),
189+ singletonHMap (stringKey , "string value" ).hashCode ());
166190
191+ assertNotEquals (emptyHMap (), singletonHMap (stringKey , "string value" ));
192+ assertNotEquals (singletonHMap (stringKey , "string value" ),
193+ singletonHMap (stringKey , "another string value" ));
167194 }
168195
169196 @ Test
0 commit comments