@Test public void printContextInformation_shouldPrintNameValuePairsSeparatedBySemiColonsInTheCorrectOrderFollowedByAComma() throws Exception { Map<String, String> context = new LinkedHashMap<>(); context.put("baker", "a"); context.put("able", "b"); context.put("charlie", "c"); StringBuilder sb = new StringBuilder(); new DiagnosticContext(() -> context).printContextInformation(sb); assertEquals(sb.toString(), "baker=a;able=b;charlie=c,"); }
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);  }