1 package net.pterodactylus.tbgof.core;
3 import java.util.concurrent.atomic.AtomicBoolean;
5 import com.google.common.util.concurrent.MoreExecutors;
6 import com.google.common.util.concurrent.Service.Listener;
7 import com.google.common.util.concurrent.Service.State;
8 import org.hamcrest.MatcherAssert;
9 import org.hamcrest.Matchers;
10 import org.junit.Before;
11 import org.junit.Test;
14 * Unit test for {@link Core}.
16 * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
18 public class CoreTest {
20 private final Core core = new Core();
21 private final AtomicBoolean started = new AtomicBoolean();
22 private final AtomicBoolean stopped = new AtomicBoolean();
25 public void setupCoreListener() {
26 core.addListener(new Listener() {
28 public void running() {
33 public void terminated(State from) {
36 }, MoreExecutors.directExecutor());
40 public void coreCanStartUp() {
41 core.startAsync().awaitRunning();
42 MatcherAssert.assertThat(started.get(), Matchers.is(true));
46 public void coreCanShutDown() {
47 core.startAsync().awaitRunning();
48 core.stopAsync().awaitTerminated();
49 MatcherAssert.assertThat(stopped.get(), Matchers.is(true));