From: David ‘Bombe’ Roden Date: Mon, 17 Nov 2014 21:16:05 +0000 (+0100) Subject: Add test for network without servers. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=380294ccebb47ae926ceffb214d691858950d435;p=xudocci.git Add test for network without servers. --- diff --git a/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java b/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java index b6de4a9..6f1897c 100644 --- a/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java +++ b/src/test/java/net/pterodactylus/xdcc/core/CoreTest.java @@ -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 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()