### Question:
Utils { public static void logAndSendWarning(CommandSender sender, String message) { ConsoleLogger.warning(message); if (sender != null && !(sender instanceof ConsoleCommandSender)) { sender.sendMessage(ChatColor.RED + 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 shouldLogAndSendWarning() { Logger logger = TestHelper.setupLogger(); String message = "Error while performing action"; CommandSender sender = mock(CommandSender.class); Utils.logAndSendWarning(sender, message); verify(logger).warning(message); verify(sender).sendMessage(ChatColor.RED + message); }
@Test public void shouldLogWarningAndNotSendToConsoleSender() { Logger logger = TestHelper.setupLogger(); String message = "Error while performing action"; CommandSender sender = mock(ConsoleCommandSender.class); Utils.logAndSendWarning(sender, message); verify(logger).warning(message); verifyZeroInteractions(sender); }
@Test public void shouldLogWarningAndHandleNullCommandSender() { Logger logger = TestHelper.setupLogger(); String message = "Error while performing action"; CommandSender sender = null; Utils.logAndSendWarning(sender, message); verify(logger).warning(message); }