Convert FCP interface test to Kotlin
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 8 Jan 2017 00:44:45 +0000 (01:44 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 8 Jan 2017 00:44:45 +0000 (01:44 +0100)
src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java [deleted file]
src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java
deleted file mode 100644 (file)
index d1c31ad..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-package net.pterodactylus.sone.fcp;
-
-import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS;
-import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO;
-import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
-import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent;
-import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent;
-import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link FcpInterface} and its subclasses.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class FcpInterfaceTest {
-
-       private final FcpInterface fcpInterface = new FcpInterface(null);
-
-       @Test
-       public void fcpInterfaceCanBeActivated() {
-               fcpInterface.fcpInterfaceActivated(new FcpInterfaceActivatedEvent());
-               assertThat(fcpInterface.isActive(), is(true));
-       }
-
-       @Test
-       public void fcpInterfaceCanBeDeactivated() {
-               fcpInterface.fcpInterfaceDeactivated(new FcpInterfaceDeactivatedEvent());
-               assertThat(fcpInterface.isActive(), is(false));
-       }
-
-       private void setAndVerifyAccessRequired(FullAccessRequired fullAccessRequired) {
-               fcpInterface.fullAccessRequiredChanged(new FullAccessRequiredChanged(fullAccessRequired));
-               assertThat(fcpInterface.getFullAccessRequired(), is(fullAccessRequired));
-       }
-
-       @Test
-       public void setFullAccessRequiredCanSetAccessToNo() {
-               setAndVerifyAccessRequired(NO);
-       }
-
-       @Test
-       public void setFullAccessRequiredCanSetAccessToWriting() {
-               setAndVerifyAccessRequired(WRITING);
-       }
-
-       @Test
-       public void setFullAccessRequiredCanSetAccessToAlways() {
-               setAndVerifyAccessRequired(ALWAYS);
-       }
-
-}
diff --git a/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt
new file mode 100644 (file)
index 0000000..1ec9473
--- /dev/null
@@ -0,0 +1,56 @@
+package net.pterodactylus.sone.fcp
+
+import net.pterodactylus.sone.core.Core
+import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired
+import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS
+import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO
+import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING
+import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent
+import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent
+import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged
+import net.pterodactylus.sone.test.mock
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+
+/**
+ * Unit test for [FcpInterface] and its subclasses.
+ */
+class FcpInterfaceTest {
+
+       private val core = mock<Core>()
+       private val fcpInterface = FcpInterface(core)
+
+       @Test
+       fun `fcp interface can be activated`() {
+               fcpInterface.fcpInterfaceActivated(FcpInterfaceActivatedEvent())
+               assertThat(fcpInterface.isActive, equalTo(true))
+       }
+
+       @Test
+       fun `fcp interface can be deactivated`() {
+               fcpInterface.fcpInterfaceDeactivated(FcpInterfaceDeactivatedEvent())
+               assertThat(fcpInterface.isActive, equalTo(false))
+       }
+
+       private fun setAndVerifyAccessRequired(fullAccessRequired: FullAccessRequired) {
+               fcpInterface.fullAccessRequiredChanged(FullAccessRequiredChanged(fullAccessRequired))
+               assertThat(fcpInterface.fullAccessRequired, equalTo(fullAccessRequired))
+       }
+
+       @Test
+       fun `set full access required can set access to no`() {
+               setAndVerifyAccessRequired(NO)
+       }
+
+       @Test
+       fun `set full access required can set access to writing`() {
+               setAndVerifyAccessRequired(WRITING)
+       }
+
+       @Test
+       fun `set full access required can set access to always`() {
+               setAndVerifyAccessRequired(ALWAYS)
+       }
+
+}