From: David ‘Bombe’ Roden Date: Sun, 8 Jan 2017 00:44:45 +0000 (+0100) Subject: Convert FCP interface test to Kotlin X-Git-Tag: 0.9.7^2~356 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f55577d9fc4bb521d324a3c8848afb6600ef965d;p=Sone.git Convert FCP interface test to Kotlin --- 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 index d1c31ad..0000000 --- a/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java +++ /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 David ‘Bombe’ Roden - */ -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 index 0000000..1ec9473 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt @@ -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() + 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) + } + +}