3
3
import org .junit .Test ;
4
4
5
5
import static java .util .Arrays .asList ;
6
+ import static java .util .Collections .emptyList ;
6
7
import static java .util .Collections .singletonList ;
7
8
import static org .assertj .core .api .Assertions .assertThat ;
8
9
@@ -15,65 +16,105 @@ public void setUp() {
15
16
flattener = new Flattener ();
16
17
}
17
18
19
+ @ Test
20
+ public void testEmpty () {
21
+ assertThat (flattener .flatten (emptyList ()))
22
+ .isEmpty ();
23
+ }
24
+
25
+ @ Ignore ("Remove to run test" )
18
26
@ Test
19
27
public void testFlatListIsPreserved () {
20
28
assertThat (flattener .flatten (asList (0 , '1' , "two" )))
21
- .containsExactly (0 , '1' , "two" );
29
+ .containsExactly (0 , '1' , "two" );
30
+ }
31
+
32
+ @ Ignore ("Remove to run test" )
33
+ @ Test
34
+ public void testNestedList () {
35
+ assertThat (flattener .flatten (singletonList (emptyList ())))
36
+ .isEmpty ();
22
37
}
23
38
24
39
@ Ignore ("Remove to run test" )
25
40
@ Test
26
41
public void testASingleLevelOfNestingWithNoNulls () {
27
42
assertThat (flattener .flatten (asList (1 , asList ('2' , 3 , 4 , 5 , "six" , "7" ), 8 )))
28
- .containsExactly (1 , '2' , 3 , 4 , 5 , "six" , "7" , 8 );
43
+ .containsExactly (1 , '2' , 3 , 4 , 5 , "six" , "7" , 8 );
29
44
}
30
45
31
46
@ Ignore ("Remove to run test" )
32
47
@ Test
33
48
public void testFiveLevelsOfNestingWithNoNulls () {
34
- assertThat (flattener .flatten (asList (0 ,
35
- '2' ,
36
- asList (asList (2 , "three" ),
37
- '8' ,
38
- 100 ,
39
- "four" ,
40
- singletonList (singletonList (singletonList (50 )))), "-2" )))
41
- .containsExactly (0 , '2' , 2 , "three" , '8' , 100 , "four" , 50 , "-2" );
49
+ assertThat (flattener .flatten (
50
+ asList (0 ,
51
+ '2' ,
52
+ asList (asList (2 , "three" ),
53
+ '8' ,
54
+ 100 ,
55
+ "four" ,
56
+ singletonList (singletonList (singletonList (50 )))), "-2" )))
57
+ .containsExactly (0 , '2' , 2 , "three" , '8' , 100 , "four" , 50 , "-2" );
42
58
}
43
59
44
60
@ Ignore ("Remove to run test" )
45
61
@ Test
46
62
public void testSixLevelsOfNestingWithNoNulls () {
47
- assertThat (flattener .flatten (asList ("one" ,
48
- asList ('2' ,
49
- singletonList (singletonList (3 )),
50
- asList ('4' ,
51
- singletonList (singletonList (5 ))), "six" , 7 ), "8" )))
52
- .containsExactly ("one" , '2' , 3 , '4' , 5 , "six" , 7 , "8" );
63
+ assertThat (flattener .flatten (
64
+ asList ("one" ,
65
+ asList ('2' ,
66
+ singletonList (singletonList (3 )),
67
+ asList ('4' ,
68
+ singletonList (singletonList (5 ))), "six" , 7 ), "8" )))
69
+ .containsExactly ("one" , '2' , 3 , '4' , 5 , "six" , 7 , "8" );
70
+ }
71
+
72
+ @ Ignore ("Remove to run test" )
73
+ @ Test
74
+ public void testNullValuesAreOmitted () {
75
+ assertThat (flattener .flatten (asList ("1" , "two" , null )))
76
+ .containsExactly ("1" , "two" );
77
+ }
78
+
79
+ @ Ignore ("Remove to run test" )
80
+ @ Test
81
+ public void testConsecutiveNullValuesAtFrontOfListAreOmitted () {
82
+ assertThat (flattener .flatten (asList (null , null , 3 )))
83
+ .containsExactly (3 );
84
+ }
85
+
86
+ @ Ignore ("Remove to run test" )
87
+ @ Test
88
+ public void testConsecutiveNullValuesInMiddleOfListAreOmitted () {
89
+ assertThat (flattener .flatten (asList (1 , null , null , "4" )))
90
+ .containsExactly (1 , "4" );
53
91
}
54
92
55
93
@ Ignore ("Remove to run test" )
56
94
@ Test
57
95
public void testSixLevelsOfNestingWithNulls () {
58
- assertThat (flattener .flatten (asList ("0" ,
59
- 2 ,
60
- asList (asList ("two" , '3' ),
61
- "8" ,
62
- singletonList (singletonList ("one hundred" )),
63
- null ,
64
- singletonList (singletonList (null ))),
65
- "negative two" )))
66
- .containsExactly ("0" , 2 , "two" , '3' , "8" , "one hundred" , "negative two" );
96
+ assertThat (flattener .flatten (
97
+ asList ("0" ,
98
+ 2 ,
99
+ asList (asList ("two" , '3' ),
100
+ "8" ,
101
+ singletonList (singletonList ("one hundred" )),
102
+ null ,
103
+ singletonList (singletonList (null ))),
104
+ "negative two" )))
105
+ .containsExactly ("0" , 2 , "two" , '3' , "8" , "one hundred" , "negative two" );
67
106
}
68
107
69
108
@ Ignore ("Remove to run test" )
70
109
@ Test
71
110
public void testNestedListsFullOfNullsOnly () {
72
- assertThat (flattener .flatten (asList (null ,
73
- singletonList (singletonList (singletonList (null ))),
74
- null ,
75
- null ,
76
- asList (asList (null , null ), null ), null ))).isEmpty ();
111
+ assertThat (flattener .flatten (
112
+ asList (null ,
113
+ singletonList (singletonList (singletonList (null ))),
114
+ null ,
115
+ null ,
116
+ asList (asList (null , null ), null ), null )))
117
+ .isEmpty ();
77
118
}
78
119
79
120
}
0 commit comments