From c2f9f11b94b03764e8300e6685efce5e3240ee17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 22 May 2016 11:48:36 +0200 Subject: [PATCH] Add more tests for Freenet7Interface --- .../jsite/application/Freenet7InterfaceTest.java | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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); -- 2.7.4