5
5
import java .util .Collections ;
6
6
import java .util .List ;
7
7
8
- import static org .junit . Assert . assertEquals ;
8
+ import static org .assertj . core . api . Assertions . assertThat ;
9
9
10
10
public class ListOpsTest {
11
11
12
12
@ Test
13
13
public void testAppendingEmptyLists () {
14
- assertEquals (
15
- Collections .emptyList (),
16
- ListOps .append (Collections .emptyList (), Collections .emptyList ())
17
- );
14
+ assertThat (ListOps .append (Collections .emptyList (), Collections .emptyList ())).isEmpty ();
18
15
}
19
16
20
17
@ Ignore ("Remove to run test" )
21
18
@ Test
22
19
public void testAppendingListToEmptyList () {
23
- assertEquals (
24
- Arrays .asList ('1' , '2' , '3' , '4' ),
25
- ListOps .append (Collections .emptyList (), Arrays .asList ('1' , '2' , '3' , '4' ))
26
- );
20
+ assertThat (ListOps .append (Collections .emptyList (), Arrays .asList ('1' , '2' , '3' , '4' )))
21
+ .containsExactly ('1' , '2' , '3' , '4' );
27
22
}
28
23
29
24
@ Ignore ("Remove to run test" )
30
25
@ Test
31
26
public void testAppendingNonEmptyLists () {
32
- assertEquals (
33
- Arrays .asList ("1" , "2" , "2" , "3" , "4" , "5" ),
34
- ListOps .append (Arrays .asList ("1" , "2" ), Arrays .asList ("2" , "3" , "4" , "5" ))
35
- );
27
+ assertThat (ListOps .append (Arrays .asList ("1" , "2" ), Arrays .asList ("2" , "3" , "4" , "5" )))
28
+ .containsExactly ("1" , "2" , "2" , "3" , "4" , "5" );
36
29
}
37
30
38
31
@ Ignore ("Remove to run test" )
39
32
@ Test
40
33
public void testConcatEmptyList () {
41
- assertEquals (
42
- Collections .emptyList (),
43
- ListOps .concat (Collections .emptyList ())
44
- );
34
+ assertThat (ListOps .concat (Collections .emptyList ())).isEmpty ();
45
35
}
46
36
47
37
@ Ignore ("Remove to run test" )
@@ -54,10 +44,7 @@ public void testConcatListOfLists() {
54
44
Arrays .asList ('4' , '5' , '6' )
55
45
);
56
46
57
- assertEquals (
58
- Arrays .asList ('1' , '2' , '3' , '4' , '5' , '6' ),
59
- ListOps .concat (listOfLists )
60
- );
47
+ assertThat (ListOps .concat (listOfLists )).containsExactly ('1' , '2' , '3' , '4' , '5' , '6' );
61
48
}
62
49
63
50
@ Ignore ("Remove to run test" )
@@ -79,160 +66,131 @@ public void testConcatListOfNestedLists() {
79
66
)
80
67
);
81
68
82
- assertEquals (
83
- Arrays . asList (
69
+ assertThat ( ListOps . concat ( listOfNestedLists ))
70
+ . containsExactly (
84
71
Collections .singletonList ('1' ),
85
72
Collections .singletonList ('2' ),
86
73
Collections .singletonList ('3' ),
87
74
Collections .emptyList (),
88
- Arrays .asList ('4' , '5' , '6' )
89
- ),
90
- ListOps .concat (listOfNestedLists )
91
- );
75
+ Arrays .asList ('4' , '5' , '6' ));
92
76
}
93
77
94
78
@ Ignore ("Remove to run test" )
95
79
@ Test
96
80
public void testFilteringEmptyList () {
97
- assertEquals (
98
- Collections .emptyList (),
99
- ListOps .filter (Collections .<Integer >emptyList (), integer -> integer % 2 == 1 )
100
- );
81
+ assertThat (ListOps .filter (Collections .<Integer >emptyList (), integer -> integer % 2 == 1 ))
82
+ .isEmpty ();
101
83
}
102
84
103
85
@ Ignore ("Remove to run test" )
104
86
@ Test
105
87
public void testFilteringNonEmptyList () {
106
- assertEquals (
107
- Arrays .asList (1 , 3 , 5 ),
108
- ListOps .filter (Arrays .asList (1 , 2 , 3 , 5 ), integer -> integer % 2 == 1 )
109
- );
88
+ assertThat (ListOps .filter (Arrays .asList (1 , 2 , 3 , 5 ), integer -> integer % 2 == 1 ))
89
+ .containsExactly (1 , 3 , 5 );
110
90
}
111
91
112
92
@ Ignore ("Remove to run test" )
113
93
@ Test
114
94
public void testSizeOfEmptyList () {
115
- assertEquals ( 0 , ListOps .size (Collections .emptyList ()));
95
+ assertThat ( ListOps .size (Collections .emptyList ())). isEqualTo ( 0 );
116
96
}
117
97
118
98
@ Ignore ("Remove to run test" )
119
99
@ Test
120
100
public void testSizeOfNonEmptyList () {
121
- assertEquals ( 4 , ListOps .size (Arrays .asList ("one" , "two" , "three" , "four" )));
101
+ assertThat ( ListOps .size (Arrays .asList ("one" , "two" , "three" , "four" ))). isEqualTo ( 4 );
122
102
}
123
103
124
104
@ Ignore ("Remove to run test" )
125
105
@ Test
126
106
public void testTransformingEmptyList () {
127
- assertEquals (
128
- Collections .emptyList (),
129
- ListOps .map (Collections .<Integer >emptyList (), integer -> integer + 1 )
130
- );
107
+ assertThat (ListOps .map (Collections .<Integer >emptyList (), integer -> integer + 1 )).isEmpty ();
131
108
}
132
109
133
110
@ Ignore ("Remove to run test" )
134
111
@ Test
135
112
public void testTransformingNonEmptyList () {
136
- assertEquals (
137
- Arrays .asList (2 , 4 , 6 , 8 ),
138
- ListOps .map (Arrays .asList (1 , 3 , 5 , 7 ), integer -> integer + 1 )
139
- );
113
+ assertThat (ListOps .map (Arrays .asList (1 , 3 , 5 , 7 ), integer -> integer + 1 ))
114
+ .containsExactly (2 , 4 , 6 , 8 );
140
115
}
141
116
142
117
@ Ignore ("Remove to run test" )
143
118
@ Test
144
119
public void testFoldLeftEmptyList () {
145
- assertEquals (
146
- new Double (2.0 ), // Boxing required for method overload disambiguation.
120
+ assertThat (
147
121
ListOps .foldLeft (
148
122
Collections .<Double >emptyList (),
149
123
2.0 ,
150
- (x , y ) -> x * y
151
- )
152
- );
124
+ (x , y ) -> x * y ))
125
+ .isEqualTo (2.0 );
153
126
}
154
127
155
128
@ Ignore ("Remove to run test" )
156
129
@ Test
157
130
public void testFoldLeftDirectionIndependentFunctionAppliedToNonEmptyList () {
158
- assertEquals (
159
- new Integer (15 ), // Boxing required for method overload disambiguation.
131
+ assertThat (
160
132
ListOps .foldLeft (
161
133
Arrays .asList (1 , 2 , 3 , 4 ),
162
134
5 ,
163
- (x , y ) -> x + y
164
- )
165
- );
135
+ (x , y ) -> x + y ))
136
+ .isEqualTo (15 );
166
137
}
167
138
168
139
@ Ignore ("Remove to run test" )
169
140
@ Test
170
141
public void testFoldLeftDirectionDependentFunctionAppliedToNonEmptyList () {
171
- assertEquals (
172
- new Integer (0 ), // Boxing required for method overload disambiguation.
142
+ assertThat (
173
143
ListOps .foldLeft (
174
144
Arrays .asList (2 , 5 ),
175
145
5 ,
176
- (x , y ) -> x / y
177
- )
178
- );
146
+ (x , y ) -> x / y ))
147
+ .isEqualTo (0 );
179
148
}
180
149
181
150
@ Ignore ("Remove to run test" )
182
151
@ Test
183
152
public void testFoldRightEmptyList () {
184
- assertEquals (
185
- new Double (2.0 ), // Boxing required for method overload disambiguation.
153
+ assertThat (
186
154
ListOps .foldRight (
187
155
Collections .<Double >emptyList (),
188
156
2.0 ,
189
- (x , y ) -> x * y
190
- )
191
- );
157
+ (x , y ) -> x * y ))
158
+ .isEqualTo (2.0 );
192
159
}
193
160
194
161
@ Ignore ("Remove to run test" )
195
162
@ Test
196
163
public void testFoldRightDirectionIndependentFunctionAppliedToNonEmptyList () {
197
- assertEquals (
198
- new Integer (15 ), // Boxing required for method overload disambiguation.
164
+ assertThat (
199
165
ListOps .foldRight (
200
166
Arrays .asList (1 , 2 , 3 , 4 ),
201
167
5 ,
202
- (x , y ) -> x + y
203
- )
204
- );
168
+ (x , y ) -> x + y ))
169
+ .isEqualTo (15 );
205
170
}
206
171
207
172
@ Ignore ("Remove to run test" )
208
173
@ Test
209
174
public void testFoldRightDirectionDependentFunctionAppliedToNonEmptyList () {
210
- assertEquals (
211
- new Integer (2 ), // Boxing required for method overload disambiguation.
175
+ assertThat (
212
176
ListOps .foldRight (
213
177
Arrays .asList (2 , 5 ),
214
178
5 ,
215
- (x , y ) -> x / y
216
- )
217
- );
179
+ (x , y ) -> x / y ))
180
+ .isEqualTo (2 );
218
181
}
219
182
220
183
@ Ignore ("Remove to run test" )
221
184
@ Test
222
185
public void testReversingEmptyList () {
223
- assertEquals (
224
- Collections .emptyList (),
225
- ListOps .reverse (Collections .emptyList ())
226
- );
186
+ assertThat (ListOps .reverse (Collections .emptyList ())).isEmpty ();
227
187
}
228
188
229
189
@ Ignore ("Remove to run test" )
230
190
@ Test
231
191
public void testReversingNonEmptyList () {
232
- assertEquals (
233
- Arrays .asList ('7' , '5' , '3' , '1' ),
234
- ListOps .reverse (Arrays .asList ('1' , '3' , '5' , '7' ))
235
- );
192
+ assertThat (ListOps .reverse (Arrays .asList ('1' , '3' , '5' , '7' )))
193
+ .containsExactly ('7' , '5' , '3' , '1' );
236
194
}
237
195
238
196
@ Ignore ("Remove to run test" )
@@ -245,15 +203,12 @@ public void testReversingListOfListIsNotFlattened() {
245
203
Arrays .asList ('4' , '5' , '6' )
246
204
);
247
205
248
- assertEquals (
249
- Arrays . asList (
206
+ assertThat ( ListOps . reverse ( listOfLists ))
207
+ . containsExactly (
250
208
Arrays .asList ('4' , '5' , '6' ),
251
209
Collections .emptyList (),
252
210
Collections .singletonList ('3' ),
253
- Arrays .asList ('1' , '2' )
254
- ),
255
- ListOps .reverse (listOfLists )
256
- );
211
+ Arrays .asList ('1' , '2' ));
257
212
}
258
213
259
214
}
0 commit comments