From: David ‘Bombe’ Roden Date: Sun, 22 May 2016 09:48:36 +0000 (+0200) Subject: Add more tests for Freenet7Interface X-Git-Tag: 0.13^2~5 X-Git-Url: https://git.pterodactylus.net/?p=jSite.git;a=commitdiff_plain;h=c2f9f11b94b03764e8300e6685efce5e3240ee17 Add more tests for Freenet7Interface --- diff --git a/src/test/java/de/todesbaum/jsite/application/Freenet7InterfaceTest.java b/src/test/java/de/todesbaum/jsite/application/Freenet7InterfaceTest.java index 54de0a5..c120efa 100644 --- a/src/test/java/de/todesbaum/jsite/application/Freenet7InterfaceTest.java +++ b/src/test/java/de/todesbaum/jsite/application/Freenet7InterfaceTest.java @@ -23,7 +23,6 @@ import de.todesbaum.util.freenet.fcp2.Message; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Mockito; /** * Unit test for {@link Freenet7Interface}. @@ -52,6 +51,42 @@ public class Freenet7InterfaceTest { } @Test + public void defaultConstructorCreatesDefaultNode() { + Freenet7Interface freenet7Interface = new Freenet7Interface(); + freenet7Interface.setNode(new Node("foo", 12345)); + de.todesbaum.util.freenet.fcp2.Node node = freenet7Interface.getNode(); + assertThat(node.getHostname(), is("foo")); + assertThat(node.getPort(), is(12345)); + } + + @Test + public void withoutSettingANodeThereIsNoNode() { + assertThat(freenet7Interface.hasNode(), is(false)); + } + + @Test + public void afterSettingANodeThereIsANode() { + when(nodeSupplier.supply(anyString(), anyInt())).thenReturn(mock(de.todesbaum.util.freenet.fcp2.Node.class)); + when(connectionSupplier.supply(any(de.todesbaum.util.freenet.fcp2.Node.class), anyString())).thenReturn(mock(Connection.class)); + freenet7Interface.setNode(new Node("foo", 12345)); + assertThat(freenet7Interface.hasNode(), is(true)); + } + + @Test + public void withoutConnectionThereIsNoNode() { + when(nodeSupplier.supply(anyString(), anyInt())).thenReturn(mock(de.todesbaum.util.freenet.fcp2.Node.class)); + freenet7Interface.setNode(new Node("foo", 12345)); + assertThat(freenet7Interface.hasNode(), is(false)); + } + + @Test + public void defaultConstructorCreatesDefaultConnection() { + Freenet7Interface freenet7Interface = new Freenet7Interface(); + Connection connection = freenet7Interface.getConnection("foo"); + assertThat(connection.getName(), is("foo")); + } + + @Test public void settingNodeAddressUsesNodeAndConnectionSuppliers() { Node node = new Node(NODE_ADDRESS, NODE_PORT); freenet7Interface.setNode(node);