### Question:
PurgeCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List<String> arguments) { String daysStr = arguments.get(0); int days; try { days = Integer.parseInt(daysStr); } catch (NumberFormatException ex) { sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!"); return; } if (days < MINIMUM_LAST_SEEN_DAYS) { sender.sendMessage(ChatColor.RED + "You can only purge data older than " + MINIMUM_LAST_SEEN_DAYS + " days"); return; } Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -days); long until = calendar.getTimeInMillis(); purgeService.runPurge(sender, until); }  @Override void executeCommand(CommandSender sender, List<String> arguments);  }### Answer:
@Test public void shouldHandleInvalidNumber() { String interval = "invalid"; CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(interval)); verify(sender).sendMessage(argThat(containsString("The value you've entered is invalid"))); verifyZeroInteractions(purgeService); }
@Test public void shouldRejectTooSmallInterval() { String interval = "29"; CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(interval)); verify(sender).sendMessage(argThat(containsString("You can only purge data older than 30 days"))); verifyZeroInteractions(purgeService); }
@Test public void shouldForwardToService() { String interval = "45"; CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(interval)); ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class); verify(purgeService).runPurge(eq(sender), captor.capture()); int toleranceMillis = 100; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -Integer.valueOf(interval)); assertIsCloseTo(captor.getValue(), calendar.getTimeInMillis(), toleranceMillis); }