Skip to content

Commit

Permalink
test: replace mock with builder in SmallRyeHealthCheckEnricherTest (3…
Browse files Browse the repository at this point in the history
…529)

SmallRyeHealthCheckEnricherTest seems to be using mock refactored with real object using lombok builders
---
removed unused imports
  • Loading branch information
saurabhmaurya1 authored Nov 12, 2024
1 parent f533828 commit a54f323
Showing 1 changed file with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,35 @@
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import org.eclipse.jkube.kit.common.Dependency;
import org.eclipse.jkube.kit.common.JavaProject;
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.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Supplier;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class SmallRyeHealthCheckEnricherTest {
private JKubeEnricherContext context;
private JavaProject javaProject;
private Properties properties;
private KubernetesListBuilder klb;


@BeforeEach
void setup() {
properties = new Properties();
ProcessorConfig processorConfig = new ProcessorConfig();
klb = new KubernetesListBuilder();

klb.addToItems(new DeploymentBuilder()
.editOrNewSpec()
.editOrNewTemplate()
Expand All @@ -62,14 +64,16 @@ 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"))
.dependenciesWithTransitive(new ArrayList<>())
.build();
context = JKubeEnricherContext.builder()
.log(new KitLogger.SilentLogger())
.project(javaProject)
.processorConfig(new ProcessorConfig())
.build();
}

@Test
Expand Down Expand Up @@ -157,21 +161,24 @@ void create_withMicroprofileHealthAndSmallRyeWithEnricherConfiguration_shouldPro
}

private void withMicroprofileHealthTransitiveDependency(String microProfileVersion) {
when(javaProject.getDependenciesWithTransitive()).thenReturn(Collections.singletonList(Dependency.builder()
final List<Dependency> deps = new ArrayList<>(javaProject.getDependencies());
deps.add(Dependency.builder()
.groupId("org.eclipse.microprofile.health")
.artifactId("microprofile-health-api")
.version(microProfileVersion)
.build()));
.build());
javaProject.setDependenciesWithTransitive(deps);
}

private void withSmallRyeDependency() {
when(javaProject.getDependencies()).thenReturn(Collections.singletonList(Dependency.builder()
.groupId("io.smallrye")
.artifactId("smallrye-health")
.build()));
final List<Dependency> deps = new ArrayList<>(javaProject.getDependencies());
deps.add(Dependency.builder()
.groupId("io.smallrye")
.artifactId("smallrye-health")
.build());
javaProject.setDependencies(deps);
}


private void assertProbesAdded(String livenessScheme, String livenessPath, String readyScheme, String readyPath, String startedScheme, String startedPath) {
Container container = getFirstContainerFromDeployment();
assertProbe(container::getLivenessProbe, livenessScheme, livenessPath);
Expand Down

0 comments on commit a54f323

Please sign in to comment.