@Test public void testGetFieldFunctionOrThrow() { LogMessageFormatter.Builder builder = LogMessageFormatter.<Integer>builder().availableFields(TEST_FIELDS); Function plus1 = LogMessageFormatter.getFieldFunctionOrThrow("PLUS1", builder); assertThat(plus1.apply(1)).isEqualTo(2); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> LogMessageFormatter.getFieldFunctionOrThrow("NON_EXISTING_FIELD", builder)) .withMessage("Unknown log format field: NON_EXISTING_FIELD"); }
static <T> Function<T, Object> getFieldFunctionOrThrow(String field, Builder<T> builder) { if (!builder.availableFields.containsKey(field)) { throw new IllegalArgumentException("Unknown log format field: " + field); } return builder.availableFields.get(field); }
LogMessageFormatter { static <T> Function<T, Object> getFieldFunctionOrThrow(String field, Builder<T> builder) { if (!builder.availableFields.containsKey(field)) { throw new IllegalArgumentException("Unknown log format field: " + field); } return builder.availableFields.get(field); } }
LogMessageFormatter { static <T> Function<T, Object> getFieldFunctionOrThrow(String field, Builder<T> builder) { if (!builder.availableFields.containsKey(field)) { throw new IllegalArgumentException("Unknown log format field: " + field); } return builder.availableFields.get(field); } private  LogMessageFormatter(Builder<T> builder); }
LogMessageFormatter { static <T> Function<T, Object> getFieldFunctionOrThrow(String field, Builder<T> builder) { if (!builder.availableFields.containsKey(field)) { throw new IllegalArgumentException("Unknown log format field: " + field); } return builder.availableFields.get(field); } private  LogMessageFormatter(Builder<T> builder); String getLogTemplate(); Object[] getArgumentsForEntry(T logEntry); static Builder<T> builder(); }
LogMessageFormatter { static <T> Function<T, Object> getFieldFunctionOrThrow(String field, Builder<T> builder) { if (!builder.availableFields.containsKey(field)) { throw new IllegalArgumentException("Unknown log format field: " + field); } return builder.availableFields.get(field); } private  LogMessageFormatter(Builder<T> builder); String getLogTemplate(); Object[] getArgumentsForEntry(T logEntry); static Builder<T> builder();  }