SqlQueryLoggerUtil { public static void logOperation(Logger logger, final String sql, final List<?> values) { if (logger.getLevel().isEqualOrLowerThan(Level.DEBUG)) { final String text = sql + " " + values.stream() .map(o -> o == null ? "null" : o.getClass().getSimpleName() + " " + o.toString()) .collect(Collectors.joining(", ", "[", "]")); logger.debug(text); } } private  SqlQueryLoggerUtil(); static void logOperation(Logger logger, final String sql, final List<?> values);  }
@Test void logOperation() { final Logger logger = mock(Logger.class); when(logger.getLevel()).thenReturn(Level.DEBUG); doNothing().when(logger).debug(anyString()); final String sql = "SELECT * FROM table WHERE id > ? AND age < ?"; final List<Integer> values = new ArrayList<>(); values.add(1); values.add(null); assertDoesNotThrow(() -> SqlQueryLoggerUtil.logOperation(logger, sql, values)); when(logger.getLevel()).thenReturn(Level.INFO); assertDoesNotThrow(() -> SqlQueryLoggerUtil.logOperation(logger, sql, values)); }