package org.code2bytes.samples.lambda;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class PersonListTest {

	private List<Person> persons;

	@Before
	public void setUp() throws Exception {
		persons = new ArrayList<>();
		persons.add(new Person("Test Person 1", 20));
		persons.add(new Person("Test Person 2", 21));
		persons.add(new Person("Test Person 3", 22));
		persons.add(new Person("Test Person 4", 23));
	}

	@Test
	public void testArraySize() {
		assertEquals("Array should contain 4 elements", 4, persons.size());
	}

	@Test
	public void testForEach() {
		persons.forEach(p -> System.out.println(p.getAgeInYears()));
	}
}

@@ -33,16 +33,65 @@
 ambda;%0A%0A
+import static org.hamcrest.CoreMatchers.equalTo;%0A
 import s
@@ -119,22 +119,20 @@
 t.assert
-Equals
+That
 ;%0A%0Aimpor
@@ -616,36 +616,28 @@
 sert
-Equals(%22A
+That(%22a
 rray 
-should 
 contain
+s
  4 e
@@ -653,21 +653,17 @@
  4, 
-persons.size(
+equalTo(4
 ));%0A
@@ -694,79 +694,177 @@
 test
-ForEach() %7B%0A%09%09persons.forEach(p -%3E System.out.println(p.getAgeInYears()
+Sum() %7B%0A%09%09Integer total = persons.parallelStream().map(p -%3E p.getAgeInYears())%0A%09%09%09%09.reduce((sum, p) -%3E sum + p).get();%0A%09%09assertThat(%22sum should be 86%22, 86, equalTo(total
 ));%0A

Add test for calculating sum of ages