1616import static org .hamcrest .collection .IsMapContaining .hasEntry ;
1717import static org .hamcrest .collection .IsMapWithSize .aMapWithSize ;
1818import static org .hamcrest .collection .IsMapWithSize .anEmptyMap ;
19- import static org .junit .Assert .*;
19+ import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertThat ;
21+ import static org .junit .Assert .assertTrue ;
2022
2123public class MapUtilsTest {
2224
23- private String [][] color2DArray = new String [][] {
24- {"RED" , "#FF0000" },
25- {"GREEN" , "#00FF00" },
26- {"BLUE" , "#0000FF" }
25+ private String [][] color2DArray = new String [][]{
26+ {"RED" , "#FF0000" },
27+ {"GREEN" , "#00FF00" },
28+ {"BLUE" , "#0000FF" }
2729 };
28- private String [] color1DArray = new String [] {
29- "RED" , "#FF0000" ,
30- "GREEN" , "#00FF00" ,
31- "BLUE" , "#0000FF"
30+ private String [] color1DArray = new String []{
31+ "RED" , "#FF0000" ,
32+ "GREEN" , "#00FF00" ,
33+ "BLUE" , "#0000FF"
3234 };
3335 private Map <String , String > colorMap ;
34-
36+
3537 @ Before
3638 public void createMap () {
3739 this .colorMap = MapUtils .putAll (new HashMap <String , String >(), this .color2DArray );
3840 }
39-
41+
4042 @ Test
4143 public void whenCreateMapFrom2DArray_theMapIsCreated () {
4244 this .colorMap = MapUtils .putAll (new HashMap <String , String >(), this .color2DArray );
4345
4446 assertThat (this .colorMap , is (aMapWithSize (this .color2DArray .length )));
45-
47+
4648 assertThat (this .colorMap , hasEntry ("RED" , "#FF0000" ));
4749 assertThat (this .colorMap , hasEntry ("GREEN" , "#00FF00" ));
4850 assertThat (this .colorMap , hasEntry ("BLUE" , "#0000FF" ));
@@ -51,26 +53,26 @@ public void whenCreateMapFrom2DArray_theMapIsCreated() {
5153 @ Test
5254 public void whenCreateMapFrom1DArray_theMapIsCreated () {
5355 this .colorMap = MapUtils .putAll (new HashMap <String , String >(), this .color1DArray );
54-
56+
5557 assertThat (this .colorMap , is (aMapWithSize (this .color1DArray .length / 2 )));
5658
5759 assertThat (this .colorMap , hasEntry ("RED" , "#FF0000" ));
5860 assertThat (this .colorMap , hasEntry ("GREEN" , "#00FF00" ));
5961 assertThat (this .colorMap , hasEntry ("BLUE" , "#0000FF" ));
6062 }
61-
63+
6264 @ Test
6365 public void whenVerbosePrintMap_thenMustPrintFormattedMap () {
6466 ByteArrayOutputStream out = new ByteArrayOutputStream ();
6567 PrintStream outPrint = new PrintStream (out );
66-
68+
6769 outPrint .println ("Optional Label = " );
6870 outPrint .println ("{" );
6971 outPrint .println (" RED = #FF0000" );
7072 outPrint .println (" BLUE = #0000FF" );
7173 outPrint .println (" GREEN = #00FF00" );
7274 outPrint .println ("}" );
73-
75+
7476 out .reset ();
7577
7678 MapUtils .verbosePrint (outPrint , "Optional Label" , this .colorMap );
@@ -80,65 +82,65 @@ public void whenVerbosePrintMap_thenMustPrintFormattedMap() {
8082 public void whenGetKeyNotPresent_thenMustReturnDefaultValue () {
8183 String defaultColorStr = "COLOR_NOT_FOUND" ;
8284 String color = MapUtils .getString (this .colorMap , "BLACK" , defaultColorStr );
83-
85+
8486 assertEquals (color , defaultColorStr );
8587 }
86-
88+
8789 @ Test
8890 public void whenGetOnNullMap_thenMustReturnDefaultValue () {
8991 String defaultColorStr = "COLOR_NOT_FOUND" ;
9092 String color = MapUtils .getString (null , "RED" , defaultColorStr );
91-
93+
9294 assertEquals (color , defaultColorStr );
9395 }
9496
9597 @ Test
9698 public void whenInvertMap_thenMustReturnInvertedMap () {
9799 Map <String , String > invColorMap = MapUtils .invertMap (this .colorMap );
98100 assertEquals (this .colorMap .size (), invColorMap .size ());
99-
100- MapIterator <String , String > itColorMap
101+
102+ MapIterator <String , String > itColorMap
101103 = MapUtils .iterableMap (this .colorMap ).mapIterator ();
102-
104+
103105 while (itColorMap .hasNext ()) {
104106 String colorMapKey = itColorMap .next ();
105107 String colorMapValue = itColorMap .getValue ();
106108
107109 String invColorMapValue = MapUtils .getString (invColorMap , colorMapValue );
108-
110+
109111 assertTrue (invColorMapValue .equals (colorMapKey ));
110112 }
111113 }
112-
114+
113115 @ Test (expected = IllegalArgumentException .class )
114116 public void whenCreateFixedSizedMapAndAdd_thenMustThrowException () {
115117 Map <String , String > rgbMap = MapUtils .fixedSizeMap (MapUtils .putAll (
116- new HashMap <String , String >(),
117- this .color1DArray ));
118-
118+ new HashMap <String , String >(),
119+ this .color1DArray ));
120+
119121 rgbMap .put ("ORANGE" , "#FFA500" );
120122 }
121-
123+
122124 @ Test (expected = IllegalArgumentException .class )
123125 public void whenAddDuplicateToUniqueValuesPredicateMap_thenMustThrowException () {
124- Map <String , String > uniqValuesMap
126+ Map <String , String > uniqValuesMap
125127 = MapUtils .predicatedMap (this .colorMap , null , PredicateUtils .uniquePredicate ());
126-
128+
127129 uniqValuesMap .put ("NEW_RED" , "#FF0000" );
128130 }
129131
130132 @ Test
131133 public void whenCreateLazyMap_theMapIsCreated () {
132134 Map <Integer , String > intStrMap = MapUtils .lazyMap (
133- new HashMap <Integer , String >(),
134- TransformerUtils .stringValueTransformer ());
135-
135+ new HashMap <Integer , String >(),
136+ TransformerUtils .stringValueTransformer ());
137+
136138 assertThat (intStrMap , is (anEmptyMap ()));
137-
139+
138140 intStrMap .get (1 );
139141 intStrMap .get (2 );
140142 intStrMap .get (3 );
141-
143+
142144 assertThat (intStrMap , is (aMapWithSize (3 )));
143145 }
144146}
0 commit comments