Console { public void log(Log logger, List<Entry<Class<?>, String>> messages) { if (messages.isEmpty()) { return; } logger.info("-------------------------------------------------------------"); consumer.accept(logger, "RESOLUTION " + header + ":"); logger.info("-------------------------------------------------------------"); for (var message : messages) { if (message.getKey() != null) { consumer.accept(logger, message.getKey().getName() + ": " + message.getValue()); } else { consumer.accept(logger, message.getValue()); } } logger.info(messages.size() + " " + (messages.size() == 1 ? count : count + "s")); logger.info("-------------------------------------------------------------"); } Console(BiConsumer<Log, String> consumer, String header, String count); void log(Log logger, List<Entry<Class<?>, String>> messages); static final Console WARNINGS; static final Console ERRORS; }
@Test void log() { Console.WARNINGS.log(log, List.of(new SimpleEntry<>(Console.class, "First"), new SimpleEntry<>(null, "Second"))); verify(log, times(3)).info("-------------------------------------------------------------"); verify(log).warn("RESOLUTION WARNING:"); verify(log).warn(Console.class.getName() + ": First"); verify(log).warn("Second"); verify(log).info("2 warnings"); }
@Test void log_empty() { Console.ERRORS.log(log, List.of()); verifyNoInteractions(log); }