From 4ad83f7c73d1198049feb3665e28b3f2d29966b0 Mon Sep 17 00:00:00 2001 From: Abhishek Tripathi <42455093+abhishektripathi66@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:56:09 +0530 Subject: [PATCH] test: replace mock with builder in AbstractMicroprofileHealthCheckEnricherTest (3577) AbstractMicroprofileHealthCheckEnricherTest : Replace Mockito.mock by creating actual object --- removin not required changes --- ...ctMicroprofileHealthCheckEnricherTest.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/jkube-kit/jkube-kit-microprofile/src/test/java/org/eclipse/jkube/microprofile/enricher/AbstractMicroprofileHealthCheckEnricherTest.java b/jkube-kit/jkube-kit-microprofile/src/test/java/org/eclipse/jkube/microprofile/enricher/AbstractMicroprofileHealthCheckEnricherTest.java index 529b40e0e0..45cc66852c 100644 --- a/jkube-kit/jkube-kit-microprofile/src/test/java/org/eclipse/jkube/microprofile/enricher/AbstractMicroprofileHealthCheckEnricherTest.java +++ b/jkube-kit/jkube-kit-microprofile/src/test/java/org/eclipse/jkube/microprofile/enricher/AbstractMicroprofileHealthCheckEnricherTest.java @@ -22,6 +22,7 @@ import org.eclipse.jkube.kit.common.Dependency; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; +import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.config.resource.PlatformMode; import org.eclipse.jkube.kit.config.resource.ProcessorConfig; import org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext; @@ -29,14 +30,12 @@ import org.junit.jupiter.api.Test; import java.io.File; -import java.util.Collections; import java.util.Properties; +import java.util.ArrayList; +import java.util.List; import java.util.function.Supplier; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.mockito.Answers.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class AbstractMicroprofileHealthCheckEnricherTest { private JKubeEnricherContext context; @@ -46,9 +45,7 @@ class AbstractMicroprofileHealthCheckEnricherTest { @BeforeEach public void setUp() { - context = mock(JKubeEnricherContext.class, RETURNS_DEEP_STUBS); properties = new Properties(); - ProcessorConfig processorConfig = new ProcessorConfig(); klb = new KubernetesListBuilder(); klb.addToItems(new DeploymentBuilder() .editOrNewSpec() @@ -65,14 +62,18 @@ public void setUp() { .endSpec() .build()); - context = mock(JKubeEnricherContext.class, RETURNS_DEEP_STUBS); - javaProject = mock(JavaProject.class, RETURNS_DEEP_STUBS); - when(context.getProject()).thenReturn(javaProject); - when(context.getProperties()).thenReturn(properties); - when(context.getConfiguration().getProcessorConfig()).thenReturn(processorConfig); - when(javaProject.getProperties()).thenReturn(properties); - when(javaProject.getBaseDirectory()).thenReturn(new File("/tmp/ignore")); - when(javaProject.getOutputDirectory()).thenReturn(new File("/tmp/ignore")); + javaProject = JavaProject.builder() + .properties(properties) + .outputDirectory(new File("/tmp/ignore")) + .baseDirectory(new File("/tmp/ignore")) + .dependenciesWithTransitive(new ArrayList<>()) + .build(); + + context = JKubeEnricherContext.builder() + .log(new KitLogger.SilentLogger()) + .project(javaProject) + .processorConfig(new ProcessorConfig()) + .build(); } @Test @@ -161,18 +162,22 @@ void create_withMicroprofileHealthAndMicroprofileImplWithEnricherConfiguration_s } private void withMicroprofileHealthTransitiveDependency(String microProfileVersion) { - when(javaProject.getDependenciesWithTransitive()).thenReturn(Collections.singletonList(Dependency.builder() - .groupId("org.eclipse.microprofile.health") - .artifactId("microprofile-health-api") - .version(microProfileVersion) - .build())); + List dependencies = new ArrayList<>(javaProject.getDependencies()); + dependencies.add(Dependency.builder() + .groupId("org.eclipse.microprofile.health") + .artifactId("microprofile-health-api") + .version(microProfileVersion) + .build()); + javaProject.setDependenciesWithTransitive(dependencies); } private void withMicroprofileImplDependency() { - when(javaProject.getDependencies()).thenReturn(Collections.singletonList(Dependency.builder() - .groupId("org.example") - .artifactId("microprofile-fooimpl") - .build())); + List dependencies = new ArrayList<>(javaProject.getDependencies()); + dependencies.add(Dependency.builder() + .groupId("org.example") + .artifactId("microprofile-fooimpl") + .build()); + javaProject.setDependencies(dependencies); } private void assertProbesAdded(String livenessScheme, String livenessPath, String readyScheme, String readyPath, String startedScheme, String startedPath) {