11package com .baeldung .eclipsecollections ;
22
3+ import org .assertj .core .api .Assertions ;
34import org .eclipse .collections .api .list .MutableList ;
45import org .eclipse .collections .impl .list .mutable .FastList ;
5- import static org .junit .Assert .assertEquals ;
6+
7+ import java .util .ArrayList ;
8+ import java .util .List ;
9+
610import org .junit .Before ;
711import org .junit .Test ;
812
@@ -13,6 +17,7 @@ public class FlatCollectTest {
1317 MutableList <String > addresses3 ;
1418 MutableList <String > addresses4 ;
1519
20+ List <String > expectedAddresses ;
1621 MutableList <Student > students ;
1722
1823 @ Before
@@ -28,15 +33,18 @@ public void setup() {
2833 Student student2 = new Student ("George" , "Adams" , addresses2 );
2934 this .addresses2 = FastList .newListWith (address3 , address4 );
3035 this .students = FastList .newListWith (student1 , student2 );
36+ this .expectedAddresses = new ArrayList <>();
37+ this .expectedAddresses .add ("73 Pacific St., Forest Hills, NY 11375" );
38+ this .expectedAddresses .add ("93 Bayport Ave., South Richmond Hill, NY 11419" );
39+ this .expectedAddresses .add ("548 Market St, San Francisco, CA 94104" );
40+ this .expectedAddresses .add ("8605 Santa Monica Blvd, West Hollywood, CA 90069" );
3141 }
3242
3343 @ Test
3444 public void whenFlatCollect_thenCorrect () {
3545 MutableList <String > addresses = students .flatCollect (Student ::getAddresses );
3646
37- assertEquals ("73 Pacific St., Forest Hills, NY 11375" , addresses .get (0 ));
38- assertEquals ("93 Bayport Ave., South Richmond Hill, NY 11419" , addresses .get (1 ));
39- assertEquals ("548 Market St, San Francisco, CA 94104" , addresses .get (2 ));
40- assertEquals ("8605 Santa Monica Blvd, West Hollywood, CA 90069" , addresses .get (3 ));
47+ Assertions .assertThat (addresses )
48+ .containsExactlyElementsOf (this .expectedAddresses );
4149 }
4250}
0 commit comments