package com.nurkiewicz.java8;

import org.junit.Ignore;
import org.junit.Test;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;

import static com.jayway.awaitility.Awaitility.await;
import static com.jayway.awaitility.Awaitility.to;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;

/**
 * Implement simple utility methods for running blocks of code in multiple threads
 */
@Ignore
public class J05_MultiRunnerTest {

	@Test
	public void shouldExecuteTasksInMultipleThreads() throws Exception {
		//given
		final Map<Long, String> threads = new ConcurrentHashMap<>();

		//when
		IntStream.range(0, 100).forEach(i ->
						MultiRunner.runMultiThreaded(() -> {
							final Thread thread = Thread.currentThread();
							threads.put(thread.getId(), thread.getName());
						})
		);

		//then
		await().untilCall(to(threads).size(), is(MultiRunner.THREAD_COUNT));
		assertThat(threads).doesNotContainKey(Thread.currentThread().getId());
	}

	@Test
	public void shouldRunMultipleBlocks() throws Exception {
		//given
		final LongAdder counter = new LongAdder();

		//when
		MultiRunner.runMultiThreaded(Arrays.asList(
				() -> counter.add(1),
				() -> counter.add(2),
				() -> counter.add(3)
		));

		//then
		await().untilCall(to(counter).sum(), is(1 + 2 + 3));
	}

}
@@ -987,36 +987,33 @@
 ntil
-Call(to(
+(() -%3E 
 threads
-)
 .size()
-, is(
+ == 
 Mult
@@ -1033,17 +1033,16 @@
 D_COUNT)
-)
 ;%0A%09%09asse
@@ -1428,16 +1428,19 @@
 is(1
+L
  + 2
+L
  + 3
+L
 ));%0A

Fix test specification