From 380294ccebb47ae926ceffb214d691858950d435 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 17 Nov 2014 22:16:05 +0100 Subject: [PATCH] Add test for network without servers. --- .../java/net/pterodactylus/xdcc/core/CoreTest.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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() -- 2.7.4