1 package net.pterodactylus.xdcc.core;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.containsInAnyOrder;
5 import static org.hamcrest.Matchers.instanceOf;
6 import static org.mockito.Matchers.any;
7 import static org.mockito.Matchers.anyInt;
8 import static org.mockito.Matchers.anyString;
9 import static org.mockito.Mockito.mock;
10 import static org.mockito.Mockito.never;
11 import static org.mockito.Mockito.times;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.when;
15 import net.pterodactylus.irc.Connection;
16 import net.pterodactylus.irc.ConnectionFactory;
17 import net.pterodactylus.xdcc.core.event.CoreStarted;
18 import net.pterodactylus.xdcc.core.event.GenericError;
19 import net.pterodactylus.xdcc.core.event.GenericMessage;
20 import net.pterodactylus.xdcc.data.Channel;
21 import net.pterodactylus.xdcc.data.Network;
23 import com.google.common.eventbus.EventBus;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.mockito.ArgumentCaptor;
30 @Ignore("this test completely sucks")
31 public class CoreTest {
33 private static final String TEMP_DIRECTORY = "/tmp";
34 private static final String FINAL_DIRECTORY = "/final";
35 private final EventBus eventBus = mock(EventBus.class);
36 private final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
37 private final Core core =
38 new Core(eventBus, connectionFactory, TEMP_DIRECTORY, FINAL_DIRECTORY);
39 private final Connection firstConnection = mock(Connection.class);
40 private final Connection secondConnection = mock(Connection.class);
43 public void setupConnections() {
44 when(firstConnection.username(anyString())).thenReturn(firstConnection);
45 when(secondConnection.username(anyString())).thenReturn(secondConnection);
49 public void setupConnectionFactory() {
50 when(connectionFactory.createConnection("first.net", 6667)).thenReturn(firstConnection);
51 when(connectionFactory.createConnection("second.net", 6667)).thenReturn(secondConnection);
55 public void tearDown() {
60 public void startingTheCoreWithAnEmptyNetworkStartsButDoesNotConnect() {
61 Network firstNetwork = Network.builder("FirstNet").build();
62 Channel firstChannel = new Channel(firstNetwork, "#first");
63 core.addChannel(firstChannel);
65 ArgumentCaptor<Object> eventCaptor = ArgumentCaptor.forClass(Object.class);
66 verify(eventBus, times(2)).post(eventCaptor.capture());
67 assertThat(eventCaptor.getAllValues(), containsInAnyOrder(
68 instanceOf(GenericError.class), instanceOf(CoreStarted.class)
70 verify(connectionFactory, never()).createConnection(anyString(), anyInt());
74 public void startingTheCoreConnectsToConfiguredNetworks() {
75 Network firstNetwork = Network.builder("FirstNet")
81 Channel firstChannel = new Channel(firstNetwork, "#first");
82 Network secondNetwork = Network.builder("SecondNet")
88 Channel secondChannel = new Channel(secondNetwork, "#second");
89 core.addChannel(firstChannel);
90 core.addChannel(secondChannel);
92 verify(eventBus).post(any(CoreStarted.class));
93 verify(firstConnection).open();
94 verify(secondConnection).open();