1 package net.pterodactylus.tbgof.core;
3 import java.util.concurrent.CountDownLatch;
4 import java.util.concurrent.TimeUnit;
6 import com.google.common.util.concurrent.MoreExecutors;
7 import com.google.common.util.concurrent.Service.Listener;
8 import com.google.common.util.concurrent.Service.State;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.Before;
12 import org.junit.Test;
15 * Unit test for {@link Core}.
17 * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
19 public class CoreTest {
21 private final Core core = new Core();
22 private final CountDownLatch started = new CountDownLatch(1);
23 private final CountDownLatch stopped = new CountDownLatch(1);
26 public void setupCoreListener() {
27 core.addListener(new Listener() {
29 public void running() {
34 public void terminated(State from) {
37 }, MoreExecutors.directExecutor());
41 public void coreCanStartUp() throws InterruptedException {
42 core.startAsync().awaitRunning();
43 MatcherAssert.assertThat(started.await(1, TimeUnit.SECONDS), Matchers.is(true));
47 public void coreCanShutDown() throws InterruptedException {
48 core.startAsync().awaitRunning();
49 core.stopAsync().awaitTerminated();
50 MatcherAssert.assertThat(stopped.await(1, TimeUnit.SECONDS), Matchers.is(true));