import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.mockito.Mockito;
/**
* Unit test for {@link Freenet7Interface}.
}
@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);