JavaModuleDependency implements Serializable { @Nullable public static JavaModuleDependency copy(IdeaModuleDependency original) { IdeaModule module = original.getDependencyModule(); if (module != null && isNotEmpty(module.getName())) { String scope = null; IdeaDependencyScope originalScope = original.getScope(); if (originalScope != null) { scope = originalScope.getScope(); } return new JavaModuleDependency(module.getName(), scope, original.getExported()); } return null; } JavaModuleDependency(@NotNull String moduleName, @Nullable String scope, boolean exported); @Nullable static JavaModuleDependency copy(IdeaModuleDependency original); @NotNull String getModuleName(); @Nullable String getScope(); boolean isExported();  }
@Test public void testCopyWithNullIdeaModule() { expect(myOriginalDependency.getDependencyModule()).andStubReturn(null); replay(myOriginalDependency, myIdeaModule); assertNull(JavaModuleDependency.copy(myOriginalDependency)); verify(myOriginalDependency, myIdeaModule); }
@Test public void testCopyWithNullModuleName() { expect(myOriginalDependency.getDependencyModule()).andStubReturn(myIdeaModule); expect(myIdeaModule.getName()).andStubReturn(null); replay(myOriginalDependency, myIdeaModule); assertNull(JavaModuleDependency.copy(myOriginalDependency)); verify(myOriginalDependency, myIdeaModule); }
@Test public void testCopyWithEmptyModuleName() { expect(myOriginalDependency.getDependencyModule()).andStubReturn(myIdeaModule); expect(myIdeaModule.getName()).andStubReturn(""); replay(myOriginalDependency, myIdeaModule); assertNull(JavaModuleDependency.copy(myOriginalDependency)); verify(myOriginalDependency, myIdeaModule); }
@Test public void testCopy() { String moduleName = "lib"; IdeaDependencyScope scope = createMock(IdeaDependencyScope.class); expect(myOriginalDependency.getDependencyModule()).andStubReturn(myIdeaModule); expect(myIdeaModule.getName()).andStubReturn(moduleName); expect(myOriginalDependency.getScope()).andStubReturn(scope); expect(myOriginalDependency.getExported()).andStubReturn(true); expect(scope.getScope()).andStubReturn("compile"); replay(myOriginalDependency, myIdeaModule, scope); JavaModuleDependency copy = JavaModuleDependency.copy(myOriginalDependency); assertNotNull(copy); assertEquals(moduleName, copy.getModuleName()); assertSame("compile", copy.getScope()); assertTrue(copy.isExported()); verify(myOriginalDependency, myIdeaModule, scope); }