### Question:
Utils { public static void logAndSendMessage(CommandSender sender, String message) { ConsoleLogger.info(message); if (sender != null && !(sender instanceof ConsoleCommandSender)) { sender.sendMessage(message); } } private  Utils(); static Pattern safePatternCompile(String pattern); static boolean isClassLoaded(String className); static void logAndSendMessage(CommandSender sender, String message); static void logAndSendWarning(CommandSender sender, String message); static boolean isCollectionEmpty(Collection<?> coll); static boolean isEmailEmpty(String email); static final long MILLIS_PER_MINUTE; static final long MILLIS_PER_HOUR; }### Answer:
@Test public void shouldLogAndSendMessage() { Logger logger = TestHelper.setupLogger(); Player player = mock(Player.class); String message = "Finished adding foo to the bar"; Utils.logAndSendMessage(player, message); verify(logger).info(message); verify(player).sendMessage(message); }
@Test public void shouldHandleNullAsCommandSender() { Logger logger = TestHelper.setupLogger(); String message = "Test test, test."; Utils.logAndSendMessage(null, message); verify(logger).info(message); }
@Test public void shouldNotSendToCommandSenderTwice() { Logger logger = TestHelper.setupLogger(); CommandSender sender = mock(ConsoleCommandSender.class); String message = "Test test, test."; Utils.logAndSendMessage(sender, message); verify(logger).info(message); verifyZeroInteractions(sender); }