LiveCommandFactory { @Nonnull public LiveCommand getLiveCommand(@Nonnull final Command<?> command) { checkNotNull(command, "command"); final String commandType = command.getType(); final Function<Command, LiveCommand> commandToLiveCommand = mappingStrategies.get(commandType); if (null == commandToLiveCommand) { final String msgTemplate = "No mapping strategy for command <{0}> available!" + " The command type <{1}> is unknown!"; throw new IllegalArgumentException(MessageFormat.format(msgTemplate, command, commandType)); } return commandToLiveCommand.apply(command); } private  LiveCommandFactory(); @Nonnull static LiveCommandFactory getInstance(); @Nonnull LiveCommand getLiveCommand(@Nonnull final Command<?> command);  }
@SuppressWarnings("ConstantConditions") @Test public void tryToGetLiveCommandForNullCommand() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> underTest.getLiveCommand(null)) .withMessage(MessageFormat.format("The {0} must not be null!", "command")) .withNoCause(); }
@Test public void tryToGetLiveCommandForCommandWithUnknownType() { final Command<?> commandMock = Mockito.mock(Command.class); Mockito.when(commandMock.getType()).thenReturn("Harambe"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.getLiveCommand(commandMock)) .withMessage("No mapping strategy for command <%s> available! The command type <%s> is unknown!", commandMock, commandMock.getType()) .withNoCause(); }