package io.datakernel.async;

import io.datakernel.eventloop.Eventloop;
import io.datakernel.eventloop.FatalErrorHandlers;
import org.junit.Before;
import org.junit.Test;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class StagesTest {

	private Eventloop eventloop;

	@Before
	public void before() {
		eventloop = Eventloop.create().withFatalErrorHandler(FatalErrorHandlers.rethrowOnAnyError());
	}

	@Test
	public void testSequence() {
		final SettableStage<Void> stage1 = SettableStage.create();
		final SettableStage<Void> stage2 = SettableStage.create();
		final SettableStage<Void> sequenceStage = SettableStage.create();

		Stages.sequence(asList(() -> stage1, () -> stage2))
				.whenComplete(AsyncCallbacks.forwardTo(sequenceStage));

		eventloop.run();
		assertFalse(stage1.isDone());
		assertFalse(stage2.isDone());
		assertFalse(sequenceStage.isDone());

		stage1.setResult(null);
		eventloop.run();
		assertTrue(stage1.isDone());
		assertFalse(stage2.isDone());
		assertFalse(sequenceStage.isDone());

		stage2.setResult(null);
		eventloop.run();
		assertTrue(stage1.isDone());
		assertTrue(stage2.isDone());
		assertTrue(sequenceStage.isDone());
	}

}
@@ -860,36 +860,35 @@
 tFalse(stage1.is
-Done
+Set
 ());%0A%09%09assertFal
@@ -891,36 +891,35 @@
 tFalse(stage2.is
-Done
+Set
 ());%0A%09%09assertFal
@@ -929,36 +929,35 @@
 sequenceStage.is
-Done
+Set
 ());%0A%0A%09%09stage1.s
@@ -954,30 +954,24 @@
 %09%09stage1.set
-Result
 (null);%0A%09%09ev
@@ -999,36 +999,35 @@
 rtTrue(stage1.is
-Done
+Set
 ());%0A%09%09assertFal
@@ -1030,36 +1030,35 @@
 tFalse(stage2.is
-Done
+Set
 ());%0A%09%09assertFal
@@ -1072,28 +1072,27 @@
 enceStage.is
-Done
+Set
 ());%0A%0A%09%09stag
@@ -1101,14 +1101,8 @@
 .set
-Result
 (nul
@@ -1146,20 +1146,19 @@
 tage1.is
-Done
+Set
 ());%0A%09%09a
@@ -1176,20 +1176,19 @@
 tage2.is
-Done
+Set
 ());%0A%09%09a
@@ -1217,12 +1217,11 @@
 e.is
-Done
+Set
 ());

Fix Stages sequence method