X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FFreenet7InterfaceTest.java;h=1f199774c3ba93079ee3dade73b15df8de17bfda;hb=5d8a613a2606018ecf1df1ff6f2a4486949c3f4f;hp=54de0a52ffffcdaf7b3d7fffba72b940f0be0557;hpb=674b7e5c95467f6e31125fea6b00bf01b74cda36;p=jSite.git diff --git a/src/test/java/de/todesbaum/jsite/application/Freenet7InterfaceTest.java b/src/test/java/de/todesbaum/jsite/application/Freenet7InterfaceTest.java index 54de0a5..1f19977 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); @@ -149,7 +184,7 @@ public class Freenet7InterfaceTest { message.put("RequestURI", REQUEST_URI); Client client = mock(Client.class); when(client.readMessage()).thenReturn(message); - when(clientSupplier.supply(eq(connection), Mockito.any(GenerateSSK.class))).thenReturn(client); + when(clientSupplier.supply(eq(connection), any(GenerateSSK.class))).thenReturn(client); String[] keyPair = freenet7Interface.generateKeyPair(); assertThat(keyPair[0], is(INSERT_URI)); assertThat(keyPair[1], is(REQUEST_URI));