return null;
}
- private void dumpNetworkStats(Writer outputWriter, ConnectedNetwork network) throws IOException {
- outputWriter.write(format("Connected to %s via %s:%d.\n", network.getNetwork().name(), network.getHostname(), network.getPort(), network.getNickname()));
+ private void dumpNetworkStats(Writer outputWriter,
+ ConnectedNetwork network) throws IOException {
+ outputWriter.write(format("Connected to %s via %s:%d.\n",
+ network.getNetwork().name(), network.getHostname(),
+ network.getPort(), network.getNickname()));
+ String joinedChannels = joinChannelNames(network.getChannels());
+ String forcedChannels = joinChannelNames(network.getForcedChannels());
+ if (forcedChannels.isEmpty()) {
+ if (!joinedChannels.isEmpty()) {
+ outputWriter.write(format(" Joined %s.\n", joinedChannels));
+ }
+ } else {
+ if (joinedChannels.isEmpty()) {
+ outputWriter.write(
+ format(" Force-joined %s.\n", forcedChannels));
+ } else {
+ outputWriter.write(format(" Joined %s, force-joined %s.\n",
+ joinedChannels, forcedChannels));
+ }
+ }
+ outputWriter.write(
+ format(" %d bots serving %d packs.\n", network.getBotCount(),
+ network.getPackCount()));
+ }
+
+ private String joinChannelNames(Collection<String> channels) {
StringJoiner joinedChannels = new StringJoiner(", ");
- network.getChannels().stream().forEach(
- (channel) -> joinedChannels.add(channel));
- StringJoiner forceJoinedChannels = new StringJoiner(", ");
- network.getForcedChannels().stream().forEach((channel) -> forceJoinedChannels.add(channel));
- outputWriter.write(format(" Joined %s, force-joined %s.\n",
- joinedChannels, forceJoinedChannels));
- outputWriter.write(format(" %d bots serving %d packs.\n", network.getBotCount(), network.getPackCount()));
+ channels.stream().forEach((channel) -> joinedChannels.add(channel));
+ return joinedChannels.toString();
}
}
6667,
"Nickname1",
asList("#channel1", "#channel2"),
- asList("#forced"),
+ emptyList(),
17,
445
);
65,
234
);
- when(core.connectedNetworks()).thenReturn(asList(network1, network2));
+ ConnectedNetwork network3 = new ConnectedNetwork(
+ builder("FooNet").build(),
+ "irc.foo.net",
+ 7000,
+ "Nickname3",
+ emptyList(),
+ emptyList(),
+ 118,
+ 1234
+ );
+ ConnectedNetwork network4 = new ConnectedNetwork(
+ builder("BarNet").build(),
+ "irc.bar.net",
+ 7001,
+ "Nickname4",
+ emptyList(),
+ asList("#foo", "#bar"),
+ 4,
+ 21
+ );
+ when(core.connectedNetworks()).thenReturn(asList(network1, network2, network3, network4));
}
@Test
String result = writer.toString();
assertThat(result, is(
"Connected to TestNet via irc.test.net:6667.\n" +
- " Joined #channel1, #channel2, force-joined #forced.\n" +
+ " Joined #channel1, #channel2.\n" +
" 17 bots serving 445 packs.\n" +
"Connected to DummyNet via irc.dummy.net:6789.\n" +
" Joined #dummy1, #dummy2, force-joined #foo, #bar.\n" +
" 65 bots serving 234 packs.\n" +
- "Total: 82 bots, 679 packs.\n"
+ "Connected to FooNet via irc.foo.net:7000.\n" +
+ " 118 bots serving 1234 packs.\n" +
+ "Connected to BarNet via irc.bar.net:7001.\n" +
+ " Force-joined #foo, #bar.\n" +
+ " 4 bots serving 21 packs.\n" +
+ "Total: 204 bots, 1934 packs.\n"
));
}