BAEL-965 - CollectionUtil

This commit is contained in:
slavisa-baeldung 2017-06-30 15:53:54 +01:00
parent 6f198df9db
commit 03c7ee9b2a
1 changed files with 4 additions and 6 deletions

View File

@ -51,13 +51,11 @@ public class CollectionUtilsGuideTest {
@Test @Test
public void givenListOfCustomers_whenTransformed_thenListOfAddress() { public void givenListOfCustomers_whenTransformed_thenListOfAddress() {
Collection<Address> addressCol = CollectionUtils.collect(list1, new Transformer<Customer, Address>() { Collection<Address> addressCol = CollectionUtils.collect(list1, customer -> {
public Address transform(Customer customer) {
return new Address(customer.getLocality(), customer.getCity(), customer.getZip()); return new Address(customer.getLocality(), customer.getCity(), customer.getZip());
}
}); });
List<Address> addressList = new ArrayList<Address>(addressCol); List<Address> addressList = new ArrayList<>(addressCol);
assertTrue(addressList.size() == 3); assertTrue(addressList.size() == 3);
assertTrue(addressList.get(0).getLocality().equals("locality1")); assertTrue(addressList.get(0).getLocality().equals("locality1"));
} }
@ -91,7 +89,7 @@ public class CollectionUtilsGuideTest {
@Test @Test
public void givenNonEmptyList_whenCheckedIsNotEmpty_thenTrue() { public void givenNonEmptyList_whenCheckedIsNotEmpty_thenTrue() {
List<Customer> emptyList = new ArrayList<Customer>(); List<Customer> emptyList = new ArrayList<>();
List<Customer> nullList = null; List<Customer> nullList = null;
//Very handy at times where we want to check if a collection is not null and not empty too. //Very handy at times where we want to check if a collection is not null and not empty too.