### Question:
MissingDependency extends LinkageProblemCause { @Override public String toString() { String missingReason = ""; for (int i = 0; i < pathToMissingArtifact.size() - 1; i++) { Dependency dependency = pathToMissingArtifact.getDependency(i); if (dependency.isOptional()) { missingReason = " because the path contains an optional dependency"; break; } if ("provided".equals(dependency.getScope())) { missingReason = " because the path contains a provided-scope dependency"; break; } } Artifact artifactContainingValidSymbol = pathToMissingArtifact.getLeaf(); return "The valid symbol is in " + artifactContainingValidSymbol + " at " + pathToMissingArtifact + " but it was not selected" + missingReason; } MissingDependency(DependencyPath pathToMissingArtifact); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode();  }### Answer:
@Test public void testToString_optional() { Artifact root = new DefaultArtifact("a:b:1"); Artifact foo = new DefaultArtifact("com.google:foo:1"); Artifact bar = new DefaultArtifact("com.google:bar:1"); DependencyPath pathRootFooBar = new DependencyPath(root) .append(new Dependency(foo, "test", false)) .append(new Dependency(bar, "compile", true)); MissingDependency missingDependency = new MissingDependency(pathRootFooBar); assertEquals( "The valid symbol is in com.google:bar:jar:1 at a:b:jar:1 / " + "com.google:foo:1 (test) / com.google:bar:1 (compile, optional) " + "but it was not selected because the path contains an optional dependency", missingDependency.toString()); }
@Test public void testToString_provided() { Artifact root = new DefaultArtifact("a:b:1"); Artifact foo = new DefaultArtifact("com.google:foo:1"); Artifact bar = new DefaultArtifact("com.google:bar:1"); DependencyPath pathRootFooBar = new DependencyPath(root) .append(new Dependency(foo, "test", false)) .append(new Dependency(bar, "provided", false)); MissingDependency missingDependency = new MissingDependency(pathRootFooBar); assertEquals( "The valid symbol is in com.google:bar:jar:1 at a:b:jar:1 / " + "com.google:foo:1 (test) / com.google:bar:1 (provided) " + "but it was not selected because the path contains a provided-scope dependency", missingDependency.toString()); }