@Test public void printContextInformation_shouldNotPrintATrailingComma_givenAnEffectivelyEmptyMergedContext() throws Exception { Map<String, String> emptyValue = new LinkedHashMap<>(); emptyValue.put("able", ""); Map<String, String> nullValue = new LinkedHashMap<>(); nullValue.put("able", null); StringBuilder sb = new StringBuilder(); new DiagnosticContext(() -> emptyValue).printContextInformation(sb); new DiagnosticContext(() -> nullValue).printContextInformation(sb); new DiagnosticContext(() -> null).printContextInformation(sb); new DiagnosticContext(null).printContextInformation(sb); assertEquals(sb.toString(), ""); }
public void printContextInformation(StringBuilder result) { String contextInformation = context.entrySet().stream() .filter(e -> Objects.nonNull(e.getValue())) .filter(e -> !e.getValue().isEmpty()) .map(es -> es.getKey() + "=" + es.getValue()) .collect(joining(";")); result.append(contextInformation); if (!contextInformation.isEmpty()) { result.append(","); } }
DiagnosticContext { public void printContextInformation(StringBuilder result) { String contextInformation = context.entrySet().stream() .filter(e -> Objects.nonNull(e.getValue())) .filter(e -> !e.getValue().isEmpty()) .map(es -> es.getKey() + "=" + es.getValue()) .collect(joining(";")); result.append(contextInformation); if (!contextInformation.isEmpty()) { result.append(","); } } }
DiagnosticContext { public void printContextInformation(StringBuilder result) { String contextInformation = context.entrySet().stream() .filter(e -> Objects.nonNull(e.getValue())) .filter(e -> !e.getValue().isEmpty()) .map(es -> es.getKey() + "=" + es.getValue()) .collect(joining(";")); result.append(contextInformation); if (!contextInformation.isEmpty()) { result.append(","); } } DiagnosticContext(DiagnosticContextSupplier supplier); }
DiagnosticContext { public void printContextInformation(StringBuilder result) { String contextInformation = context.entrySet().stream() .filter(e -> Objects.nonNull(e.getValue())) .filter(e -> !e.getValue().isEmpty()) .map(es -> es.getKey() + "=" + es.getValue()) .collect(joining(";")); result.append(contextInformation); if (!contextInformation.isEmpty()) { result.append(","); } } DiagnosticContext(DiagnosticContextSupplier supplier); Map<String, String> getContext(); void printContextInformation(StringBuilder result); }
DiagnosticContext { public void printContextInformation(StringBuilder result) { String contextInformation = context.entrySet().stream() .filter(e -> Objects.nonNull(e.getValue())) .filter(e -> !e.getValue().isEmpty()) .map(es -> es.getKey() + "=" + es.getValue()) .collect(joining(";")); result.append(contextInformation); if (!contextInformation.isEmpty()) { result.append(","); } } DiagnosticContext(DiagnosticContextSupplier supplier); Map<String, String> getContext(); void printContextInformation(StringBuilder result);  }