DependencyContainerImpl implements DependencyContainer { @NonNull @Override public DependencyContainer flatten( @Nullable AndroidLibrary testedLibrary, @Nullable DependencyContainer testedDependencyContainer) { List<AndroidLibrary> flatAndroidLibs = Lists.newArrayList(); Set<JavaLibrary> flatJavaLibs = Sets.newLinkedHashSet(); computeFlatLibraryList(mLibraryDependencies, flatAndroidLibs, flatJavaLibs); if (testedLibrary != null) { computeFlatLibraryList(testedLibrary, flatAndroidLibs, flatJavaLibs); } computeFlatJarList(mJavaDependencies, flatJavaLibs); List<JavaLibrary> localJars = mLocalJars; if (testedDependencyContainer != null && testedLibrary != null) { Collection<JavaLibrary> testedLocalJars = testedDependencyContainer.getLocalDependencies(); localJars = Lists.newArrayListWithExpectedSize(mLocalJars.size()); for (JavaLibrary javaLibrary : mLocalJars) { if (!testedLocalJars.contains(javaLibrary)) { localJars.add(javaLibrary); } } } return new DependencyContainerImpl(flatAndroidLibs, flatJavaLibs, localJars); } DependencyContainerImpl(
            @NonNull List<? extends AndroidLibrary> aars,
            @NonNull Collection<? extends JavaLibrary> jars,
            @NonNull Collection<? extends JavaLibrary> localJars); static DependencyContainer getEmpty(); @NonNull @Override ImmutableList<AndroidLibrary> getAndroidDependencies(); @NonNull @Override ImmutableList<JavaLibrary> getJarDependencies(); @NonNull @Override ImmutableList<JavaLibrary> getLocalDependencies(); @NonNull @Override DependencyContainer flatten(
            @Nullable AndroidLibrary testedLibrary,
            @Nullable DependencyContainer testedDependencyContainer); @Override String toString();  }
@Test public void testFlatten() throws Exception { JavaLibrary guava = mockJavaLibrary( new File("guava.jar"), new MavenCoordinatesImpl("com.google.guava", "guava", "18.0"), ImmutableList.of(), null); JavaLibrary jarModule = mockJavaLibrary( new File("jar.jar"), new MavenCoordinatesImpl("project", "jar", "unspecified"), ImmutableList.of(guava), ":jar"); AndroidLibrary libraryModule = mockAndroidLibrary( new File("library.jar"), new MavenCoordinatesImpl("project", "library", "unspecified"), ImmutableList.of(), ImmutableList.of(jarModule), ":library"); DependencyContainerImpl container = new DependencyContainerImpl( ImmutableList.of(libraryModule), ImmutableList.of(), ImmutableList.of()); DependencyContainer flatContainer = container.flatten(null, null); ImmutableList<AndroidLibrary> androidLibraries = flatContainer.getAndroidDependencies(); assertThat(androidLibraries).containsExactly(libraryModule); ImmutableList<JavaLibrary> javaLibraries = flatContainer.getJarDependencies(); assertThat(javaLibraries).containsExactly(jarModule, guava); }