+package net.pterodactylus.tbgof.core;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.Service.Listener;
+import com.google.common.util.concurrent.Service.State;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link Core}.
+ *
+ * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
+ */
+public class CoreTest {
+
+ private final Core core = new Core();
+ private final AtomicBoolean started = new AtomicBoolean();
+ private final AtomicBoolean stopped = new AtomicBoolean();
+
+ @Before
+ public void setupCoreListener() {
+ core.addListener(new Listener() {
+ @Override
+ public void running() {
+ started.set(true);
+ }
+
+ @Override
+ public void terminated(State from) {
+ stopped.set(true);
+ }
+ }, MoreExecutors.directExecutor());
+ }
+
+ @Test
+ public void coreCanStartUp() {
+ core.startAsync().awaitRunning();
+ MatcherAssert.assertThat(started.get(), Matchers.is(true));
+ }
+
+ @Test
+ public void coreCanShutDown() {
+ core.startAsync().awaitRunning();
+ core.stopAsync().awaitTerminated();
+ MatcherAssert.assertThat(stopped.get(), Matchers.is(true));
+ }
+
+}