Skip to content

Commit

Permalink
test: replace mock with builder in AbstractMicroprofileHealthCheckEnr…
Browse files Browse the repository at this point in the history
…icherTest (3577)

AbstractMicroprofileHealthCheckEnricherTest : Replace Mockito.mock by creating actual object
---
removin not required changes
  • Loading branch information
abhishektripathi66 authored Dec 2, 2024
1 parent 271c88b commit 4ad83f7
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@
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;
import org.junit.jupiter.api.BeforeEach;
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;
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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<Dependency> 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<Dependency> 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) {
Expand Down

0 comments on commit 4ad83f7

Please sign in to comment.