IdeaJarLibraryDependencyFactory { @Nullable public JarLibraryDependency create(@NotNull IdeaSingleEntryLibraryDependency original) { File binaryPath = original.getFile(); if (binaryPath == null) { return null; } String scope = null; IdeaDependencyScope originalScope = original.getScope(); if (originalScope != null) { scope = originalScope.getScope(); } boolean resolved = JarLibraryDependency.isResolved(binaryPath.getName()); String name = JarLibraryDependency.getDependencyName(binaryPath, resolved); return new JarLibraryDependency(name, binaryPath, original.getSource(), original.getJavadoc(), scope, original.getGradleModuleVersion(), resolved); }  @Nullable JarLibraryDependency create(@NotNull IdeaSingleEntryLibraryDependency original);  }
@Test public void testCopyWithNullBinaryPath() { when(myOriginalDependency.getFile()).thenReturn(null); assertNull(myIdeaJarLibraryDependencyFactory.create(myOriginalDependency)); }
@Test public void testCopyWithResolvedDependency() { FileStub binaryPath = new FileStub("fake.jar", true); FileStub sourcePath = new FileStub("fake-src.jar", true); FileStub javadocPath = new FileStub("fake-javadoc.jar", true); IdeaDependencyScope scope = mock(IdeaDependencyScope.class); GradleModuleVersion moduleVersion = new GradleModuleVersionImpl(myModuleVersion); when(myOriginalDependency.getFile()).thenReturn(binaryPath); when(myOriginalDependency.getSource()).thenReturn(sourcePath); when(myOriginalDependency.getJavadoc()).thenReturn(javadocPath); when(myOriginalDependency.getScope()).thenReturn(scope); when(myOriginalDependency.getGradleModuleVersion()).thenReturn(moduleVersion); when(scope.getScope()).thenReturn("compile"); JarLibraryDependency dependency = myIdeaJarLibraryDependencyFactory.create(myOriginalDependency); assertNotNull(dependency); assertEquals("fake", dependency.getName()); assertEquals("compile", dependency.getScope()); assertSame(binaryPath, dependency.getBinaryPath()); assertSame(sourcePath, dependency.getSourcePath()); assertSame(javadocPath, dependency.getJavadocPath()); assertEquals(moduleVersion, dependency.getModuleVersion()); assertTrue(dependency.isResolved()); }
@Test public void testCopyWithUnresolvedDependency() { FileStub binaryPath = new FileStub("unresolved dependency - fake", true); GradleModuleVersion moduleVersion = new GradleModuleVersionImpl(myModuleVersion); when(myOriginalDependency.getFile()).thenReturn(binaryPath); when(myOriginalDependency.getSource()).thenReturn(null); when(myOriginalDependency.getJavadoc()).thenReturn(null); when(myOriginalDependency.getScope()).thenReturn(null); when(myOriginalDependency.getGradleModuleVersion()).thenReturn(moduleVersion); JarLibraryDependency dependency = myIdeaJarLibraryDependencyFactory.create(myOriginalDependency); assertNotNull(dependency); assertEquals("fake", dependency.getName()); assertNull(dependency.getScope()); assertSame(binaryPath, dependency.getBinaryPath()); assertNull(dependency.getSourcePath()); assertNull(dependency.getJavadocPath()); assertEquals(moduleVersion, dependency.getModuleVersion()); assertFalse(dependency.isResolved()); }