### Question:
ArtifactProblem { public static String formatProblems(Iterable<ArtifactProblem> problems) { ImmutableListMultimap<Artifact, ArtifactProblem> artifactToProblems = Multimaps.index(problems, ArtifactProblem::getArtifact); StringBuilder output = new StringBuilder(); for (Artifact artifact : artifactToProblems.keySet()) { ImmutableList<ArtifactProblem> artifactProblems = artifactToProblems.get(artifact); int otherCount = artifactProblems.size() - 1; verify(otherCount >= 0, "artifactToProblems should have at least one value for one key"); ArtifactProblem firstProblem = Iterables.getFirst(artifactProblems, null); output.append(firstProblem); if (otherCount == 1) { output.append(" and a problem on the same artifact."); } else if (otherCount > 1) { output.append(" and " + otherCount + " problems on the same artifact."); } output.append("\n"); } return output.toString(); } protected  ArtifactProblem(Artifact artifact, List<DependencyNode> dependencyPath); Artifact getArtifact(); static String formatProblems(Iterable<ArtifactProblem> problems); @Override boolean equals(Object other); @Override int hashCode();  }### Answer:
@Test public void testFormatProblems_2problems() { UnresolvableArtifactProblem problemA_B_C = new UnresolvableArtifactProblem(ImmutableList.of(nodeA, nodeB, nodeC)); UnresolvableArtifactProblem problemB_C = new UnresolvableArtifactProblem(ImmutableList.of(nodeA, nodeB, nodeC)); String actual = ArtifactProblem.formatProblems(ImmutableList.of(problemB_C, problemA_B_C)); assertEquals( "foo:c:jar:1.0.0 was not resolved. " + "Dependency path: foo:a:jar:1.0.0 (compile) > foo:b:jar:1.0.0 (provided) > " + "foo:c:jar:1.0.0 (runtime) and a problem on the same artifact.\n", actual); }
@Test public void testFormatProblems_3problems() { UnresolvableArtifactProblem problemA_B_C = new UnresolvableArtifactProblem(ImmutableList.of(nodeA, nodeB, nodeC)); UnresolvableArtifactProblem problemB_C = new UnresolvableArtifactProblem(ImmutableList.of(nodeA, nodeB, nodeC)); UnresolvableArtifactProblem problemC = new UnresolvableArtifactProblem(ImmutableList.of(nodeA, nodeB, nodeC)); String actual = ArtifactProblem.formatProblems(ImmutableList.of(problemC, problemB_C, problemA_B_C)); assertEquals( "foo:c:jar:1.0.0 was not resolved. Dependency path: " + "foo:a:jar:1.0.0 (compile) > foo:b:jar:1.0.0 (provided) > foo:c:jar:1.0.0 (runtime) " + "and 2 problems on the same artifact.\n", actual); }
@Test public void testFormatProblems_2artifacts() { UnresolvableArtifactProblem problemA = new UnresolvableArtifactProblem(ImmutableList.of(nodeA)); UnresolvableArtifactProblem problemB = new UnresolvableArtifactProblem(ImmutableList.of(nodeB)); String actual = ArtifactProblem.formatProblems(ImmutableList.of(problemA, problemB)); assertEquals( "foo:a:jar:1.0.0 was not resolved. Dependency path: foo:a:jar:1.0.0 (compile)\n" + "foo:b:jar:1.0.0 was not resolved. Dependency path: foo:b:jar:1.0.0 (provided)\n", actual); }