Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify command exception to use message instead of reason #357

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
import static com.hydratereminder.Commons.RUNELITE_COMMAND_PREFIX;

public class NotRecognizedCommandException extends RuntimeException {
private final String reason;
private static final long serialVersionUID = 4328743L;

public NotRecognizedCommandException(String unsupportedCommandName) {
super();
this.reason = String.format(
super(String.format(
"%s%s %s is not supported command",
RUNELITE_COMMAND_PREFIX, HYDRATE_COMMAND_ALIAS, unsupportedCommandName
);
}

public String getReason() {
return reason;
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
import static com.hydratereminder.Commons.RUNELITE_COMMAND_PREFIX;

public class NotSupportedCommandException extends RuntimeException {
private final String reason;
private static final long serialVersionUID = 4328741L;

public NotSupportedCommandException(HydrateReminderCommandArgs unrecognizedCommandName) {
super();
this.reason = String.format(
super(String.format(
"%s%s %s is not a valid command",
RUNELITE_COMMAND_PREFIX, HYDRATE_COMMAND_ALIAS, unrecognizedCommandName
);
}

public String getReason() {
return reason;
RUNELITE_COMMAND_PREFIX, HYDRATE_COMMAND_ALIAS, unrecognizedCommandName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.mock;

@ExtendWith(MockitoExtension.class)
class CommandInvokerTest {
Expand All @@ -32,7 +32,7 @@ class CommandInvokerTest {
void shouldCallCommandCreatorOnlyOnceWhenCommandWasExecutedProperly() {
// given
HydrateReminderCommandArgs commandArgs = HydrateReminderCommandArgs.HYDRATE;
Command hydrateCommand = Mockito.mock(HydrateCommand.class);
Command hydrateCommand = mock(HydrateCommand.class);
CommandExecuted commandToExecute = new CommandExecuted("hr", new String[]{"hydrate"});

given(commandCreator.createFrom(commandArgs)).willReturn(hydrateCommand);
Expand All @@ -47,8 +47,8 @@ void shouldCallCommandCreatorOnlyOnceWhenCommandWasExecutedProperly() {
@Test
void shouldSendProperMessageWhenNotRecognizedCommandExceptionIsThrown() {
// given
String expectedExceptionMessage = new NotRecognizedCommandException("wrong").getReason();
Command helpCommand = Mockito.mock(HelpCommand.class);
String expectedExceptionMessage = new NotRecognizedCommandException("wrong").getMessage();
Command helpCommand = mock(HelpCommand.class);
CommandExecuted commandToExecute = new CommandExecuted("hr", new String[]{"wrong"});

given(commandCreator.createFrom(HydrateReminderCommandArgs.HELP)).willReturn(helpCommand);
Expand All @@ -66,7 +66,7 @@ void shouldCallCommandCreatorTwiceWhenNotSupportedCommandExceptionIsThrown() {
// given
HydrateReminderCommandArgs commandArgs = HydrateReminderCommandArgs.HYDRATE;
CommandExecuted commandToExecute = new CommandExecuted("hr", new String[]{"hydrate"});
Command helpCommand = Mockito.mock(HelpCommand.class);
Command helpCommand = mock(HelpCommand.class);

given(commandCreator.createFrom(commandArgs)).willThrow(NotSupportedCommandException.class);
given(commandCreator.createFrom(HydrateReminderCommandArgs.HELP)).willReturn(helpCommand);
Expand Down