From 0428deb0f9c6399318eddd1caa38e3a1bf1e590f Mon Sep 17 00:00:00 2001 From: David Roden Date: Tue, 2 Jun 2015 09:00:42 +0200 Subject: [PATCH] Start with core --- build.gradle | 3 ++ .../java/net/pterodactylus/tbgof/core/Core.java | 20 +++++++++ .../net/pterodactylus/tbgof/core/CoreTest.java | 52 ++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/main/java/net/pterodactylus/tbgof/core/Core.java create mode 100644 src/test/java/net/pterodactylus/tbgof/core/CoreTest.java diff --git a/build.gradle b/build.gradle index 486c4b5..8ed3277 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,10 @@ repositories { } dependencies { + compile "com.google.guava:guava:18.0" + testCompile "junit:junit:4.12" + testCompile "org.hamcrest:hamcrest-all:1.3" } apply from: "ide.gradle" diff --git a/src/main/java/net/pterodactylus/tbgof/core/Core.java b/src/main/java/net/pterodactylus/tbgof/core/Core.java new file mode 100644 index 0000000..3fbb547 --- /dev/null +++ b/src/main/java/net/pterodactylus/tbgof/core/Core.java @@ -0,0 +1,20 @@ +package net.pterodactylus.tbgof.core; + +import com.google.common.util.concurrent.AbstractIdleService; + +/** + * The core of TBGOF. + * + * @author David Roden + */ +public class Core extends AbstractIdleService { + + @Override + protected void startUp() throws Exception { + } + + @Override + protected void shutDown() throws Exception { + } + +} diff --git a/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java b/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java new file mode 100644 index 0000000..8605339 --- /dev/null +++ b/src/test/java/net/pterodactylus/tbgof/core/CoreTest.java @@ -0,0 +1,52 @@ +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 David Roden + */ +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)); + } + +} -- 2.7.4