Add test for network without servers.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Nov 2014 21:16:05 +0000 (22:16 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Nov 2014 21:16:05 +0000 (22:16 +0100)
src/test/java/net/pterodactylus/xdcc/core/CoreTest.java

index b6de4a9..6f1897c 100644 (file)
@@ -1,14 +1,22 @@
 package net.pterodactylus.xdcc.core;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.instanceOf;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
 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.core.event.GenericError;
+import net.pterodactylus.xdcc.core.event.GenericMessage;
 import net.pterodactylus.xdcc.data.Channel;
 import net.pterodactylus.xdcc.data.Network;
 
@@ -16,6 +24,7 @@ import com.google.common.eventbus.EventBus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentCaptor;
 
 public class CoreTest {
 
@@ -46,6 +55,20 @@ public class CoreTest {
        }
 
        @Test
+       public void startingTheCoreWithAnEmptyNetworkStartsButDoesNotConnect() {
+               Network firstNetwork = Network.builder("FirstNet").build();
+               Channel firstChannel = new Channel(firstNetwork, "#first");
+               core.addChannel(firstChannel);
+               core.startAndWait();
+               ArgumentCaptor<Object> eventCaptor = ArgumentCaptor.forClass(Object.class);
+               verify(eventBus, times(2)).post(eventCaptor.capture());
+               assertThat(eventCaptor.getAllValues(), containsInAnyOrder(
+                               instanceOf(GenericError.class), instanceOf(CoreStarted.class)
+               ));
+               verify(connectionFactory, never()).createConnection(anyString(), anyInt());
+       }
+
+       @Test
        public void startingTheCoreConnectsToConfiguredNetworks() {
                Network firstNetwork = Network.builder("FirstNet")
                                .addServer()