use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.
the class GradleUtilTest method extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystemPropertyShouldHaveMorePrecedence.
@Test
public void extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystemPropertyShouldHaveMorePrecedence() {
// Given
final Map<String, Object> gradleProperties = new HashMap<>();
gradleProperties.put("foo.property", "gradlevalue");
System.setProperty("foo.property", "systemvalue");
when(project.getProperties()).thenAnswer(i -> gradleProperties);
// When
final JavaProject result = convertGradleProject(project);
// Then
assertThat(result.getProperties()).hasFieldOrPropertyWithValue("foo.property", null).hasEntrySatisfying("foo.property", e -> assertThat(e).isEqualTo("systemvalue"));
System.clearProperty("foo.property");
}
use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.
the class GradleUtilTest method findClassesOutputDirectory_withNotFoundSourceSet_shouldReturnDefault.
@Test
public void findClassesOutputDirectory_withNotFoundSourceSet_shouldReturnDefault() {
// Given
when(javaPlugin.getSourceSets().getByName("main")).thenThrow(new UnknownDomainObjectException("Not found"));
// When
final JavaProject result = convertGradleProject(project);
// Then
assertThat(result.getOutputDirectory()).isEqualTo(folder.getRoot().toPath().resolve("build").resolve("classes").resolve("java").resolve("main").toFile());
}
use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.
the class GradleUtilTest method findArtifact_withExistentFile_shouldReturnValidArtifact.
@Test
public void findArtifact_withExistentFile_shouldReturnValidArtifact() throws IOException {
// Given
final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS);
when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty());
when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of(folder.newFile("final-artifact.jar")).collect(Collectors.toSet()));
projectConfigurations.add(c);
// When
final JavaProject result = convertGradleProject(project);
// Then
assertThat(result.getArtifact()).isNotNull().hasName("final-artifact.jar");
}
use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.
the class GradleUtilTest method findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLargestSize.
@Test
public void findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLargestSize() throws IOException {
// Given
final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS);
File jar1 = folder.newFile("final-artifact.jar");
Files.write(jar1.toPath(), "FatJar".getBytes());
File jar2 = folder.newFile("final-artifact-plain.jar");
when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty());
when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of(jar2, jar1).collect(Collectors.toSet()));
projectConfigurations.add(c);
// When
final JavaProject result = convertGradleProject(project);
// Then
assertThat(result.getArtifact()).isNotNull().hasName("final-artifact.jar");
}
use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.
the class GradleUtilTest method extractDependencies_withMultipleAndDuplicateDependencies_shouldReturnValidDependencies.
@Test
public void extractDependencies_withMultipleAndDuplicateDependencies_shouldReturnValidDependencies() {
// Given
final Function<String[], Configuration> mockConfiguration = configurationDependencyMock();
projectConfigurations.add(mockConfiguration.apply(new String[] { "api", "com.example", "artifact", null }));
projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example.sub", "duplicate-artifact", "1.33.7" }));
projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example.sub", "duplicate-artifact", "1.33.7" }));
projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example", "other.artifact", "1.0.0" }));
projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example", "other.artifact", "1.1.0" }));
projectConfigurations.add(mockConfiguration.apply(new String[] { "testImplementation", "com.example", "other.artifact", "1.1.0" }));
// When
final JavaProject result = convertGradleProject(project);
// Then
assertThat(result.getDependencies()).hasSize(5).satisfies(l -> assertThat(l).first().extracting("file").hasFieldOrPropertyWithValue("name", "artifact.jar")).extracting("groupId", "artifactId", "version", "scope").containsExactlyInAnyOrder(tuple("com.example", "artifact", null, "compile"), tuple("com.example.sub", "duplicate-artifact", "1.33.7", "compile"), tuple("com.example", "other.artifact", "1.0.0", "compile"), tuple("com.example", "other.artifact", "1.1.0", "compile"), tuple("com.example", "other.artifact", "1.1.0", "test"));
}
Aggregations