Start with core
[tbgof.git] / src / test / java / net / pterodactylus / tbgof / core / CoreTest.java
1 package net.pterodactylus.tbgof.core;
2
3 import java.util.concurrent.atomic.AtomicBoolean;
4
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;
12
13 /**
14  * Unit test for {@link Core}.
15  *
16  * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
17  */
18 public class CoreTest {
19
20     private final Core core = new Core();
21     private final AtomicBoolean started = new AtomicBoolean();
22     private final AtomicBoolean stopped = new AtomicBoolean();
23
24     @Before
25     public void setupCoreListener() {
26         core.addListener(new Listener() {
27             @Override
28             public void running() {
29                 started.set(true);
30             }
31
32             @Override
33             public void terminated(State from) {
34                 stopped.set(true);
35             }
36         }, MoreExecutors.directExecutor());
37     }
38
39     @Test
40     public void coreCanStartUp() {
41         core.startAsync().awaitRunning();
42         MatcherAssert.assertThat(started.get(), Matchers.is(true));
43     }
44
45     @Test
46     public void coreCanShutDown() {
47         core.startAsync().awaitRunning();
48         core.stopAsync().awaitTerminated();
49         MatcherAssert.assertThat(stopped.get(), Matchers.is(true));
50     }
51
52 }