--- /dev/null
+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();
+ }
+
+}