Skip to content

Commit

Permalink
Couple more deprecation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 5, 2016
1 parent 2b264da commit e1e78e2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 3 additions & 1 deletion res/com/dmdirc/ui/messages/format.yml
Expand Up @@ -205,6 +205,9 @@ CommandErrorEvent:
colour: 7
CommandOutputEvent:
format: "{{message}}"
UnknownCommandEvent:
format: "Unknown command {{command}}."
colour: 14

################## TODO ############################################################################
# selfCTCP=4->- [%1$s] %2$s
Expand All @@ -213,7 +216,6 @@ CommandOutputEvent:
# serverDisconnectInProgress=A disconnection attempt is in progress, please wait...
# serverConnectInProgress=A connection attempt is in progress, please wait...
# rawCommand=10>>> %1$s
# unknownCommand=14Unknown command %1$s.
# commandOutput=%1$s
# actionTooLong=Warning: action too long to be sent
# tabCompletion=14Multiple possibilities: %1$s
Expand Down
1 change: 1 addition & 0 deletions src/com/dmdirc/GroupChatManagerImpl.java
Expand Up @@ -173,6 +173,7 @@ public void closeAll() {
channels.closeAll();
}

@Deprecated
public void addLineToAll(final String messageType, final Date date, final Object... args) {
channels.addLineToAll(messageType, date, args);
}
Expand Down
4 changes: 3 additions & 1 deletion src/com/dmdirc/commandparser/commands/channel/Mode.java
Expand Up @@ -32,6 +32,7 @@
import com.dmdirc.commandparser.commands.IntelligentCommand;
import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
import com.dmdirc.commandparser.commands.context.CommandContext;
import com.dmdirc.events.ChannelModesDiscoveredEvent;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.Connection;
import com.dmdirc.interfaces.GroupChat;
Expand Down Expand Up @@ -70,7 +71,8 @@ public void execute(@Nonnull final WindowModel origin,
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();

if (args.getArguments().length == 0) {
sendLine(origin, args.isSilent(), "channelModeDiscovered", channel.getModes(), channel);
channel.getEventBus().publishAsync(new ChannelModesDiscoveredEvent(
channel, channel.getModes()));
} else {
channel.getConnection().get().getParser().get().sendRawMessage("MODE "
+ channel.getName() + ' ' + args.getArgumentsAsString());
Expand Down
12 changes: 2 additions & 10 deletions src/com/dmdirc/commandparser/parsers/CommandParser.java
Expand Up @@ -39,7 +39,6 @@
import com.dmdirc.interfaces.GroupChat;
import com.dmdirc.interfaces.WindowModel;
import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
import com.dmdirc.util.EventUtils;
import com.dmdirc.util.collections.RollingList;

import java.io.Serializable;
Expand Down Expand Up @@ -335,15 +334,8 @@ protected abstract void executeCommand(
*/
protected void handleInvalidCommand(final WindowModel origin,
final CommandArguments args) {
if (origin == null) {
eventBus.publish(new UnknownCommandEvent(null, args.getCommandName(), args.getArguments()));
} else {
final UnknownCommandEvent event = new UnknownCommandEvent(origin,
args.getCommandName(), args.getArguments());
final String format = EventUtils.postDisplayable(eventBus, event, "unknownCommand");

origin.addLine(format, args.getCommandName());
}
eventBus.publishAsync(new UnknownCommandEvent(origin, args.getCommandName(),
args.getArguments()));
}

/**
Expand Down
12 changes: 10 additions & 2 deletions test/com/dmdirc/commandparser/commands/channel/ModeTest.java
Expand Up @@ -23,9 +23,11 @@
package com.dmdirc.commandparser.commands.channel;

import com.dmdirc.Channel;
import com.dmdirc.DMDircMBassador;
import com.dmdirc.commandparser.CommandArguments;
import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
import com.dmdirc.config.InvalidIdentityFileException;
import com.dmdirc.events.ChannelModesDiscoveredEvent;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.Connection;
import com.dmdirc.interfaces.WindowModel;
Expand All @@ -36,20 +38,25 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class ModeTest {

@Mock private WindowModel origin;
@Mock private DMDircMBassador eventbus;
@Mock private CommandController controller;
@Mock private Channel channel;
@Mock private Connection connection;
@Mock private Parser parser;
@Captor private ArgumentCaptor<ChannelModesDiscoveredEvent> modeDiscoveredCaptor;
private Mode command;

@Before
Expand All @@ -58,6 +65,7 @@ public void setUp() throws InvalidIdentityFileException {
when(connection.getParser()).thenReturn(Optional.of(parser));
when(channel.getModes()).thenReturn("my mode string!");
when(channel.getName()).thenReturn("#chan");
when(channel.getEventBus()).thenReturn(eventbus);

command = new Mode(controller);
}
Expand All @@ -66,8 +74,8 @@ public void setUp() throws InvalidIdentityFileException {
public void testWithoutArgs() {
command.execute(origin, new CommandArguments(controller, "/mode"),
new ChannelCommandContext(null, Mode.INFO, channel));

verify(origin).addLine("channelModeDiscovered", "my mode string!", channel);
verify(eventbus).publishAsync(modeDiscoveredCaptor.capture());
assertEquals("my mode string!", modeDiscoveredCaptor.getValue().getModes());
}

@Test
Expand Down

0 comments on commit e1e78e2

Please sign in to comment.