From: David ‘Bombe’ Roden Date: Mon, 17 Nov 2014 20:32:27 +0000 (+0100) Subject: Add first test for the core. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=3339958e63b4422e90fb27d73f8d05095002dc85;p=xudocci.git Add first test for the core. --- diff --git a/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java b/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java new file mode 100644 index 0000000..4ae2b0f --- /dev/null +++ b/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java @@ -0,0 +1,66 @@ +package net.pterodactylus.xdcc.core; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import net.pterodactylus.irc.Connection; +import net.pterodactylus.irc.ConnectionFactory; +import net.pterodactylus.xdcc.core.event.CoreStarted; +import net.pterodactylus.xdcc.data.Channel; +import net.pterodactylus.xdcc.data.Network; + +import com.google.common.eventbus.EventBus; +import org.junit.Before; +import org.junit.Test; + +public class CoreTest { + + private static final String TEMP_DIRECTORY = "/tmp"; + private static final String FINAL_DIRECTORY = "/final"; + private final EventBus eventBus = mock(EventBus.class); + private final ConnectionFactory connectionFactory = mock(ConnectionFactory.class); + private final Core core = + new Core(eventBus, connectionFactory, TEMP_DIRECTORY, FINAL_DIRECTORY); + private final Connection firstConnection = mock(Connection.class); + private final Connection secondConnection = mock(Connection.class); + + @Before + public void setupConnections() { + when(firstConnection.username(anyString())).thenReturn(firstConnection); + when(secondConnection.username(anyString())).thenReturn(secondConnection); + } + + @Before + public void setupConnectionFactory() { + when(connectionFactory.createConnection("first.net", 6667)).thenReturn(firstConnection); + when(connectionFactory.createConnection("second.net", 6667)).thenReturn(secondConnection); + } + + @Test + public void startingTheCoreConnectsToConfiguredNetworks() { + Network firstNetwork = Network.builder("FirstNet") + .addServer() + .at("first.net") + .port(6667) + .endServer() + .build(); + Channel firstChannel = new Channel(firstNetwork, "#first"); + Network secondNetwork = Network.builder("SecondNet") + .addServer() + .at("second.net") + .port(6667) + .endServer() + .build(); + Channel secondChannel = new Channel(secondNetwork, "#second"); + core.addChannel(firstChannel); + core.addChannel(secondChannel); + core.startAndWait(); + verify(eventBus).post(any(CoreStarted.class)); + verify(firstConnection).open(); + verify(secondConnection).open(); + } + +}