X-Git-Url: https://git.pterodactylus.net/?p=tbgof.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Ftbgof%2Fcore%2FCoreTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Ftbgof%2Fcore%2FCoreTest.java;h=199dc781c015be34660b3f356de132c4e8d244c2;hp=860533919bb28f4579a935b9e8a5fc5d514f081d;hb=36b543817840a0557aac69f7b4303ef6bd663595;hpb=0428deb0f9c6399318eddd1caa38e3a1bf1e590f diff --git a/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java b/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java index 8605339..199dc78 100644 --- a/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java +++ b/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java @@ -1,6 +1,7 @@ package net.pterodactylus.tbgof.core; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Service.Listener; @@ -17,36 +18,36 @@ import org.junit.Test; */ 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)); - } + private final Core core = new Core(); + private final CountDownLatch started = new CountDownLatch(1); + private final CountDownLatch stopped = new CountDownLatch(1); + + @Before + public void setupCoreListener() { + core.addListener(new Listener() { + @Override + public void running() { + started.countDown(); + } + + @Override + public void terminated(State from) { + stopped.countDown(); + } + }, MoreExecutors.directExecutor()); + } + + @Test + public void coreCanStartUp() throws InterruptedException { + core.startAsync().awaitRunning(); + MatcherAssert.assertThat(started.await(1, TimeUnit.SECONDS), Matchers.is(true)); + } + + @Test + public void coreCanShutDown() throws InterruptedException { + core.startAsync().awaitRunning(); + core.stopAsync().awaitTerminated(); + MatcherAssert.assertThat(stopped.await(1, TimeUnit.SECONDS), Matchers.is(true)); + } }