From fe297450a4173f15656d45383a0c62e637edc8bf Mon Sep 17 00:00:00 2001 From: Anurag Rajawat Date: Thu, 6 Oct 2022 11:58:19 +0530 Subject: [PATCH] refactor (org.eclipse.jkube.kubernetes.gradle.plugin): Migrate tests from JUnit4 to JUnit5 (#1581) Signed-off-by: Anurag Rajawat --- gradle-plugin/kubernetes/pom.xml | 10 +- .../jkube/gradle/plugin/GradleUtilTest.java | 64 ++-- .../jkube/gradle/plugin/GroovyUtilTest.java | 12 +- .../jkube/gradle/plugin/JKubePluginTest.java | 6 +- .../KubernetesExtensionPropertyTest.java | 314 ++++++++++-------- .../plugin/KubernetesExtensionTest.java | 16 +- .../KubernetesPluginRegisterTaskTest.java | 58 ++-- .../gradle/plugin/KubernetesPluginTest.java | 14 +- .../plugin/task/KubernetesApplyTaskTest.java | 54 ++- .../plugin/task/KubernetesBuildTaskTest.java | 54 ++- .../task/KubernetesConfigViewTaskTest.java | 19 +- .../plugin/task/KubernetesDebugTaskTest.java | 37 +-- .../task/KubernetesHelmPushTaskTest.java | 51 ++- .../plugin/task/KubernetesHelmTaskTest.java | 50 ++- .../plugin/task/KubernetesLogTaskTest.java | 43 ++- .../plugin/task/KubernetesPushTaskTest.java | 29 +- .../task/KubernetesResourceTaskTest.java | 22 +- .../task/KubernetesUndeployTaskTest.java | 40 ++- .../plugin/task/KubernetesWatchTaskTest.java | 39 ++- ...ent.java => TaskEnvironmentExtension.java} | 44 ++- .../gradle/plugin/task/TaskUtilTest.java | 18 +- 21 files changed, 512 insertions(+), 482 deletions(-) rename gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/{TaskEnvironment.java => TaskEnvironmentExtension.java} (61%) diff --git a/gradle-plugin/kubernetes/pom.xml b/gradle-plugin/kubernetes/pom.xml index 7dca1a5bc1..f9fec1b56d 100644 --- a/gradle-plugin/kubernetes/pom.xml +++ b/gradle-plugin/kubernetes/pom.xml @@ -168,8 +168,14 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test org.mockito diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GradleUtilTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GradleUtilTest.java index 0bd879c61d..33dfef5ad7 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GradleUtilTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GradleUtilTest.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -43,10 +44,9 @@ import org.gradle.api.internal.provider.DefaultProvider; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.internal.deprecation.DeprecatableConfiguration; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.stubbing.Answer; import static org.assertj.core.api.Assertions.assertThat; @@ -58,10 +58,10 @@ import static org.mockito.Mockito.when; @SuppressWarnings("unused") -public class GradleUtilTest { +class GradleUtilTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + Path folder; private Project project; @@ -69,8 +69,8 @@ public class GradleUtilTest { private List projectConfigurations; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { project = mock(Project.class, RETURNS_DEEP_STUBS); javaPlugin = mock(JavaPluginConvention.class, RETURNS_DEEP_STUBS); when(javaPlugin.getSourceSets().stream()).thenReturn(Stream.empty()); @@ -83,13 +83,13 @@ public void setUp() throws IOException { when(project.getBuildscript().getConfigurations().stream()).thenAnswer(i -> Stream.empty()); when(project.getProperties()).thenReturn(Collections.emptyMap()); - when(project.getBuildDir()).thenReturn(folder.newFolder("build")); + when(project.getBuildDir()).thenReturn(Files.createDirectory(folder.resolve("build")).toFile()); when(project.getPlugins()).thenReturn(new DefaultPluginContainer(null, null, null)); when(project.getConvention().getPlugin(JavaPluginConvention.class)).thenReturn(javaPlugin); } @Test - public void extractProperties_withComplexMap_shouldReturnValidProperties() { + void extractProperties_withComplexMap_shouldReturnValidProperties() { // Given final Map complexProperties = new HashMap<>(); when(project.getProperties()).thenAnswer(i -> complexProperties); @@ -106,7 +106,7 @@ public void extractProperties_withComplexMap_shouldReturnValidProperties() { } @Test - public void extractProperties_shouldContainSystemProperties() { + void extractProperties_shouldContainSystemProperties() { // Given System.setProperty("foo.property", "somevalue"); when(project.getProperties()).thenReturn(Collections.emptyMap()); @@ -121,7 +121,7 @@ public void extractProperties_shouldContainSystemProperties() { } @Test - public void extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystemPropertyShouldHaveMorePrecedence() { + void extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystemPropertyShouldHaveMorePrecedence() { // Given final Map gradleProperties = new HashMap<>(); gradleProperties.put("foo.property", "gradlevalue"); @@ -138,7 +138,7 @@ public void extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystem } @Test - public void extractDependencies_withMultipleAndDuplicateDependencies_shouldReturnValidDependencies() { + void extractDependencies_withMultipleAndDuplicateDependencies_shouldReturnValidDependencies() { // Given final Function mockConfiguration = configurationDependencyMock(); projectConfigurations.add(mockConfiguration.apply(new String[] { "api", "com.example", "artifact", null })); @@ -164,7 +164,7 @@ public void extractDependencies_withMultipleAndDuplicateDependencies_shouldRetur } @Test - public void extractPlugins_withMultipleAndBuildScriptDuplicateDependencies_shouldReturnValidPlugins() { + void extractPlugins_withMultipleAndBuildScriptDuplicateDependencies_shouldReturnValidPlugins() { // Given final ConfigurationContainer cc = mock(ConfigurationContainer.class); when(project.getBuildscript().getConfigurations()).thenReturn(cc); @@ -196,7 +196,7 @@ public void extractPlugins_withMultipleAndBuildScriptDuplicateDependencies_shoul * into an ArrayList. */ @Test - public void convertGradleProject_withConcurrentConfigurationModifications_shouldReturnValidProject() { + void convertGradleProject_withConcurrentConfigurationModifications_shouldReturnValidProject() { // Given final Configuration mockConfiguration = mock(Configuration.class, RETURNS_DEEP_STUBS); projectConfigurations.add(mockConfiguration); @@ -216,18 +216,18 @@ public void convertGradleProject_withConcurrentConfigurationModifications_should } @Test - public void findClassesOutputDirectory_withNotFoundSourceSet_shouldReturnDefault() { + 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()); + .isEqualTo(folder.resolve("build").resolve("classes").resolve("java").resolve("main").toFile()); } @Test - public void findClassesOutputDirectory_withValidSourceSet_shouldReturnFromSourceSet() { + void findClassesOutputDirectory_withValidSourceSet_shouldReturnFromSourceSet() { // Given when(javaPlugin.getSourceSets().getByName("main").getJava().getDestinationDirectory().getAsFile()) .thenReturn(new DefaultProvider<>(() -> new File("classes"))); @@ -238,23 +238,23 @@ public void findClassesOutputDirectory_withValidSourceSet_shouldReturnFromSource } @Test - public void findClassesOutputDirectory_withNoSourceSets_shouldReturnDefault() { + void findClassesOutputDirectory_withNoSourceSets_shouldReturnDefault() { // Given when(javaPlugin.getSourceSets()).thenReturn(null); // When final JavaProject result = convertGradleProject(project); // Then assertThat(result.getOutputDirectory()) - .isEqualTo(folder.getRoot().toPath().resolve("build").resolve("classes").resolve("java").resolve("main").toFile()); + .isEqualTo(folder.resolve("build").resolve("classes").resolve("java").resolve("main").toFile()); } @Test - public void findArtifact_withExistentFile_shouldReturnValidArtifact() throws IOException { + 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") + Files.createFile(folder.resolve("final-artifact.jar")).toFile() ).collect(Collectors.toSet())); projectConfigurations.add(c); // When @@ -264,12 +264,12 @@ public void findArtifact_withExistentFile_shouldReturnValidArtifact() throws IOE } @Test - public void findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLargestSize() throws IOException { + void findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLargestSize() throws IOException { // Given final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS); - File jar1 = folder.newFile("final-artifact.jar"); + File jar1 = Files.createFile(folder.resolve("final-artifact.jar")).toFile(); Files.write(jar1.toPath(), "FatJar".getBytes()); - File jar2 = folder.newFile("final-artifact-plain.jar"); + File jar2 = Files.createFile(folder.resolve("final-artifact-plain.jar")).toFile(); when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty()); when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of( jar2, jar1 @@ -282,12 +282,12 @@ public void findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLarge } @Test - public void findArtifact_withMultipleArchiveFiles_shouldReturnJavaArchiveOnly() throws IOException { + void findArtifact_withMultipleArchiveFiles_shouldReturnJavaArchiveOnly() throws IOException { // Given final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS); - File jar1 = folder.newFile("final-artifact.jar"); - File jar2 = folder.newFile("final-artifact.tar"); - File jar3 = folder.newFile("final-artifact.zip"); + File jar1 = Files.createFile(folder.resolve("final-artifact.jar")).toFile(); + File jar2 = Files.createFile(folder.resolve("final-artifact.tar")).toFile(); + File jar3 = Files.createFile(folder.resolve("final-artifact.zip")).toFile(); when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty()); when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of(jar1, jar2, jar3).collect(Collectors.toSet())); projectConfigurations.add(c); @@ -298,7 +298,7 @@ public void findArtifact_withMultipleArchiveFiles_shouldReturnJavaArchiveOnly() } @Test - public void canBeResolved_withDeprecatedAndResolutionAlternatives_shouldReturnFalse() { + void canBeResolved_withDeprecatedAndResolutionAlternatives_shouldReturnFalse() { // Given final DeprecatableConfiguration c = mock(DeprecatableConfiguration.class); when(c.getResolutionAlternatives()).thenReturn(Collections.emptyList()); @@ -309,7 +309,7 @@ public void canBeResolved_withDeprecatedAndResolutionAlternatives_shouldReturnFa } @Test - public void canBeResolved_DeprecatedAndNullResolutionAlternativesAndResolvable_shouldReturnTrue() { + void canBeResolved_DeprecatedAndNullResolutionAlternativesAndResolvable_shouldReturnTrue() { // Given final DeprecatableConfiguration c = mock(DeprecatableConfiguration.class); when(c.isCanBeResolved()).thenReturn(true); diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GroovyUtilTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GroovyUtilTest.java index c2b6eea395..8367b561d4 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GroovyUtilTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/GroovyUtilTest.java @@ -22,15 +22,15 @@ import groovy.lang.Closure; import org.codehaus.groovy.runtime.GStringImpl; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.eclipse.jkube.gradle.plugin.GroovyUtil.closureTo; import static org.eclipse.jkube.gradle.plugin.GroovyUtil.invokeOrParseClosureList; -@SuppressWarnings({ "unused", "serial" }) -public class GroovyUtilTest { +@SuppressWarnings("unused") +class GroovyUtilTest { /** *
@@ -45,7 +45,7 @@ public class GroovyUtilTest {
    * 
*/ @Test - public void closureTo_withNestedClosure_shouldReturnStructuredClass() { + void closureTo_withNestedClosure_shouldReturnStructuredClass() { // Given final Closure closure = closure(this, "property", new GStringImpl(new Object[] { "lue" }, new String[] { "va" }), @@ -67,7 +67,7 @@ public void closureTo_withNestedClosure_shouldReturnStructuredClass() { */ @SuppressWarnings("unchecked") @Test - public void closureTo_withNestedClosureCollection_shouldReturnMap() { + void closureTo_withNestedClosureCollection_shouldReturnMap() { // Given final Closure closure = closure(this, "array", Arrays.asList("one", "two", closure(this, "nested", "closure"))); @@ -95,7 +95,7 @@ public void closureTo_withNestedClosureCollection_shouldReturnMap() { * */ @Test - public void invokeOrParseClosureList_namedClosureListTo_withNamedListNestedClosure_shouldReturnOrderedList() { + void invokeOrParseClosureList_namedClosureListTo_withNamedListNestedClosure_shouldReturnOrderedList() { // Given final Closure element1 = closure(this, "property", "value", "nested", closure(this, "nestedProperty", "nestedValue")); diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/JKubePluginTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/JKubePluginTest.java index a12539292f..551eb9a1c5 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/JKubePluginTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/JKubePluginTest.java @@ -17,16 +17,16 @@ import java.util.Map; import org.gradle.api.Task; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class JKubePluginTest { +class JKubePluginTest { @Test - public void getTaskPrecedence_withDefaults_shouldReturnEmpty() { + void getTaskPrecedence_withDefaults_shouldReturnEmpty() { // Given final JKubePlugin partial = mock(JKubePlugin.class); when(partial.getTaskPrecedence()).thenCallRealMethod(); diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionPropertyTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionPropertyTest.java index d3ff9c999f..f21b0a8393 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionPropertyTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionPropertyTest.java @@ -15,8 +15,7 @@ import java.io.File; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import org.eclipse.jkube.kit.build.service.docker.helper.ContainerNamingUtil; import org.eclipse.jkube.kit.common.JavaProject; @@ -24,144 +23,21 @@ import org.eclipse.jkube.kit.common.ResourceFileType; import org.eclipse.jkube.kit.config.image.WatchMode; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) -public class KubernetesExtensionPropertyTest { - - public static File BASE = new File(""); - - @Parameterized.Parameters(name = "{index} {0}, returns {4}, or with property {1}={2} returns {3}") - public static Collection data() { - return Arrays.asList( - new Object[] { "getOfflineOrDefault", "jkube.offline", "true", true, false }, - new Object[] { "getFailOnValidationErrorOrDefault", "jkube.failOnValidationError", "true", true, false }, - new Object[] { "getMergeWithDekorateOrDefault", "jkube.mergeWithDekorate", "true", true, false }, - new Object[] { "getInterpolateTemplateParametersOrDefault", "jkube.interpolateTemplateParameters", "false", false, - true }, - new Object[] { "getSkipResourceValidationOrDefault", "jkube.skipResourceValidation", "true", true, false }, - new Object[] { "getSkipResourceOrDefault", "jkube.skip.resource", "true", true, false}, - new Object[] { "getSkipBuildOrDefault", "jkube.skip.build", "true", true, false}, - new Object[] { "getLogFollowOrDefault", "jkube.log.follow", "false", false, true }, - new Object[] { "getRecreateOrDefault", "jkube.recreate", "true", true, false }, - new Object[] { "getSkipApplyOrDefault", "jkube.skip.apply", "true", true, false }, - new Object[] { "getFailOnNoKubernetesJsonOrDefault", "jkube.deploy.failOnNoKubernetesJson", "true", true, false - }, - new Object[] { "getCreateNewResourcesOrDefault", "jkube.deploy.create", "false", false, true }, - new Object[] { "getServicesOnlyOrDefault", "jkube.deploy.servicesOnly", "true", true, false }, - new Object[] { "getIgnoreServicesOrDefault", "jkube.deploy.ignoreServices", "true", true, false }, - new Object[] { "getJsonLogDirOrDefault", "jkube.deploy.jsonLogDir", - Paths.get("build", "jkube", "other").toString(), - Paths.get("build", "jkube", "other").toFile(), - new File(BASE, "build").toPath().resolve(Paths.get("jkube", "applyJson")).toFile() }, - new Object[] { "getDeletePodsOnReplicationControllerUpdateOrDefault", "jkube.deploy.deletePods", "false", false, - true }, - new Object[] { "getRollingUpgradesOrDefault", "jkube.rolling", "true", true, false }, - new Object[] { "getServiceUrlWaitTimeSecondsOrDefault", "jkube.serviceUrl.waitSeconds", "1337", 1337, 5 }, - new Object[] { "getKubernetesManifestOrDefault", "jkube.kubernetesManifest", - Paths.get("META-INF", "jkube", "other.yml").toString(), - Paths.get("META-INF", "jkube", "other.yml").toFile(), - new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "kubernetes.yml")).toFile() }, - new Object[] { "getSkipOrDefault", "jkube.skip", "true", true, false }, - new Object[] { "getIgnoreRunningOAuthClientsOrDefault", "jkube.deploy.ignoreRunningOAuthClients", "false", false, - true }, - new Object[] { "getProcessTemplatesLocallyOrDefault", "jkube.deploy.processTemplatesLocally", "false", false, - true }, - new Object[] { "getRollingUpgradePreserveScaleOrDefault", "jkube.rolling.preserveScale", "true", true, false }, - new Object[] { "getSkipPushOrDefault", "jkube.skip.push", "true", true, false }, - new Object[] { "getPushRegistryOrNull", "jkube.docker.push.registry", "https://custom:5000", "https://custom:5000", null }, - new Object[] { "getSkipTagOrDefault", "jkube.skip.tag", "true", true, false }, - new Object[] { "getPushRetriesOrDefault", "jkube.docker.push.retries", "1337", 1337, 0 }, - new Object[] { "getSkipExtendedAuthOrDefault", "jkube.docker.skip.extendedAuth", "true", true, false }, - new Object[] { "getBuildRecreateOrDefault", "jkube.build.recreate", "changed", "changed", "none" }, - new Object[] { "getUseColorOrDefault", "jkube.useColor", "false", false, true }, - new Object[] { "getMaxConnectionsOrDefault", "jkube.docker.maxConnections", "1337", 1337, 100 }, - new Object[] { "getFilterOrNull", "jkube.image.filter", "foo", "foo", null }, - new Object[] { "getApiVersionOrNull", "jkube.docker.apiVersion", "1.24", "1.24", null }, - new Object[] { "getImagePullPolicyOrNull", "jkube.docker.imagePullPolicy", "Always", "Always", null }, - new Object[] { "getAutoPullOrNull", "jkube.docker.autoPull", "true", "true", null }, - new Object[] { "getDockerHostOrNull", "jkube.docker.host", "unix:///var/run/docker.sock", - "unix:///var/run/docker.sock", null }, - new Object[] { "getCertPathOrNull", "jkube.docker.certPath", "~/.docker", "~/.docker", null }, - new Object[] { "getSkipMachineOrDefault", "jkube.docker.skip.machine", "true", true, false }, - new Object[] { "getForcePullOrDefault", "jkube.build.forcePull", "true", true, false }, - new Object[] { "getRegistryOrDefault", "jkube.docker.registry", "quay.io", "quay.io", "docker.io" }, - new Object[] { "getPullRegistryOrDefault", "jkube.docker.pull.registry", "quay.io", "quay.io", "docker.io" }, - new Object[] { "getBuildSourceDirectoryOrDefault", "jkube.build.source.dir", "src/main/other", "src/main/other", - "src/main/docker" }, - new Object[] { "getBuildOutputDirectoryOrDefault", "jkube.build.target.dir", "build/other", "build/other", - "build/docker" }, - new Object[] { "getResourceSourceDirectoryOrDefault", "jkube.resourceDir", - Paths.get("src", "main", "other").toString(), - Paths.get("src", "main", "other").toFile(), - BASE.toPath().resolve(Paths.get("src", "main", "jkube")).toFile() - }, - new Object[] { "getResourceTargetDirectoryOrDefault", "jkube.targetDir", - Paths.get("META-INF", "jkube", "other").toString(), - Paths.get("META-INF", "jkube", "other").toFile(), - new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube")).toFile() - }, - new Object[] { "getResourceEnvironmentOrNull", "jkube.environment", "dev", "dev", null }, - new Object[] { "getWorkDirectoryOrDefault", "jkube.workDir", - Paths.get("jkube-work-other").toString(), - Paths.get("jkube-work-other").toFile(), - new File(BASE, "build").toPath().resolve(Paths.get("jkube")).toFile() }, - new Object[] { "getProfileOrNull", "jkube.profile", "default", "default", null }, - new Object[] { "getNamespaceOrNull", "jkube.namespace", "test", "test", null }, - new Object[] { "getBuildStrategyOrDefault", "jkube.build.strategy", "s2i", JKubeBuildStrategy.s2i, - JKubeBuildStrategy.docker }, - new Object[] { "getBuildStrategyOrDefault", "jkube.build.strategy", "jib", JKubeBuildStrategy.jib, - JKubeBuildStrategy.docker }, - new Object[] { "getResourceFileTypeOrDefault", "jkube.resourceType", "json", ResourceFileType.json, - ResourceFileType.yaml }, - new Object[] { "getLogPodNameOrNull", "jkube.log.pod", "test", "test", null }, - new Object[] { "getLogDateOrNull", "jkube.docker.logDate", "test", "test", null }, - new Object[] { "getLogStdoutOrDefault", "jkube.docker.logStdout", "true", true, false }, - new Object[] { "getLogContainerNameOrNull", "jkube.log.container", "test", "test", null }, - new Object[] { "getUseProjectClassPathOrDefault", "jkube.useProjectClasspath", "true", true, false }, - new Object[] { "getLocalDebugPortOrDefault", "jkube.debug.port", "1337", 1337, 5005 }, - new Object[] { "getDebugSuspendOrDefault", "jkube.debug.suspend", "true", true, false }, - new Object[] { "getKubernetesTemplateOrDefault", "jkube.kubernetesTemplate", - Paths.get("META-INF", "jkube", "other").toString(), - Paths.get("META-INF", "jkube", "other").toFile(), - new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "kubernetes")).toFile() - }, - new Object[] { "getWatchModeOrDefault", "jkube.watch.mode", "copy", WatchMode.copy, WatchMode.both}, - new Object[] { "getWatchIntervalOrDefault", "jkube.watch.interval", "10000", 10000, 5000}, - new Object[] { "getWatchKeepRunningOrDefault", "jkube.watch.keepRunning", "true", true, false}, - new Object[] { "getWatchPostExecOrNull", "jkube.watch.postExec", "ls -lt", "ls -lt", null}, - new Object[] { "getWatchAutoCreateCustomNetworksOrDefault", "jkube.watch.autoCreateCustomNetworks", "true", true, false}, - new Object[] { "getWatchKeepContainerOrDefault", "jkube.watch.keepContainer", "true", true, false}, - new Object[] { "getWatchRemoveVolumesOrDefault", "jkube.watch.removeVolumes", "true", true, false}, - new Object[] { "getWatchContainerNamePatternOrDefault", "jkube.watch.containerNamePattern", "%n-%g", "%n-%g", ContainerNamingUtil.DEFAULT_CONTAINER_NAME_PATTERN}, - new Object[] { "getWatchFollowOrDefault", "jkube.watch.follow", "true", true, false}, - new Object[] { "getWatchShowLogsOrNull", "jkube.watch.showLogs", "true", "true", null}); - } - - @Parameterized.Parameter - public String method; - - @Parameterized.Parameter(1) - public String property; - - @Parameterized.Parameter(2) - public String propertyValue; - - @Parameterized.Parameter(3) - public Object expectedValue; - - @Parameterized.Parameter(4) - public Object expectedDefault; +class KubernetesExtensionPropertyTest { + private static final File BASE = new File(""); private TestKubernetesExtension extension; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { extension = new TestKubernetesExtension(); extension.javaProject = JavaProject.builder() .artifactId("artifact-id") @@ -171,16 +47,91 @@ public void setUp() throws Exception { .build(); } - @Test - public void getValue_withDefaults_shouldReturnDefaultValue() throws Exception { + @ParameterizedTest(name = "{index}: {0} with defaults returns ''{1}''") + @MethodSource("defaultValues") + void getValue_withDefaults_shouldReturnDefaultValue(String method, Object expectedDefault) throws Exception { // When final Object result = extension.getClass().getMethod(method).invoke(extension); // Then assertThat(result).isEqualTo(expectedDefault); } - @Test - public void getValue_withProperty_shouldReturnFromPropertyValue() throws Exception { + static Stream defaultValues() { + return Stream.of( + arguments("getOfflineOrDefault", false), + arguments("getFailOnValidationErrorOrDefault", false), + arguments("getMergeWithDekorateOrDefault", false), + arguments("getInterpolateTemplateParametersOrDefault", true), + arguments("getSkipResourceValidationOrDefault", false), + arguments("getSkipResourceOrDefault", false), + arguments("getSkipBuildOrDefault", false), + arguments("getLogFollowOrDefault", true), + arguments("getRecreateOrDefault", false), + arguments("getSkipApplyOrDefault", false), + arguments("getFailOnNoKubernetesJsonOrDefault", false), + arguments("getCreateNewResourcesOrDefault", true), + arguments("getServicesOnlyOrDefault", false), + arguments("getIgnoreServicesOrDefault", false), + arguments("getJsonLogDirOrDefault", new File(BASE, "build").toPath().resolve(Paths.get("jkube", "applyJson")).toFile()), + arguments("getDeletePodsOnReplicationControllerUpdateOrDefault", true), + arguments("getRollingUpgradesOrDefault", false), + arguments("getServiceUrlWaitTimeSecondsOrDefault", 5), + arguments("getKubernetesManifestOrDefault", new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "kubernetes.yml")).toFile()), + arguments("getSkipOrDefault", false), + arguments("getIgnoreRunningOAuthClientsOrDefault", true), + arguments("getProcessTemplatesLocallyOrDefault", true), + arguments("getRollingUpgradePreserveScaleOrDefault", false), + arguments("getSkipPushOrDefault", false), + arguments("getPushRegistryOrNull", null), + arguments("getSkipTagOrDefault", false), + arguments("getPushRetriesOrDefault", 0), + arguments("getSkipExtendedAuthOrDefault", false), + arguments("getBuildRecreateOrDefault", "none"), + arguments("getUseColorOrDefault", true), + arguments("getMaxConnectionsOrDefault", 100), + arguments("getFilterOrNull", null), + arguments("getApiVersionOrNull", null), + arguments("getImagePullPolicyOrNull", null), + arguments("getAutoPullOrNull", null), + arguments("getDockerHostOrNull", null), + arguments("getCertPathOrNull", null), + arguments("getSkipMachineOrDefault", false), + arguments("getForcePullOrDefault", false), + arguments("getRegistryOrDefault", "docker.io"), + arguments("getPullRegistryOrDefault", "docker.io"), + arguments("getBuildSourceDirectoryOrDefault", "src/main/docker"), + arguments("getBuildOutputDirectoryOrDefault", "build/docker"), + arguments("getResourceSourceDirectoryOrDefault", BASE.toPath().resolve(Paths.get("src", "main", "jkube")).toFile()), + arguments("getResourceTargetDirectoryOrDefault", new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube")).toFile()), + arguments("getResourceEnvironmentOrNull", null), + arguments("getWorkDirectoryOrDefault", new File(BASE, "build").toPath().resolve(Paths.get("jkube")).toFile()), + arguments("getProfileOrNull", null), + arguments("getNamespaceOrNull", null), + arguments("getBuildStrategyOrDefault", JKubeBuildStrategy.docker), + arguments("getResourceFileTypeOrDefault", ResourceFileType.yaml), + arguments("getLogPodNameOrNull", null), + arguments("getLogDateOrNull", null), + arguments("getLogStdoutOrDefault", false), + arguments("getLogContainerNameOrNull", null), + arguments("getUseProjectClassPathOrDefault", false), + arguments("getLocalDebugPortOrDefault", 5005), + arguments("getDebugSuspendOrDefault", false), + arguments("getKubernetesTemplateOrDefault", new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "kubernetes")).toFile()), + arguments("getWatchModeOrDefault", WatchMode.both), + arguments("getWatchIntervalOrDefault", 5000), + arguments("getWatchKeepRunningOrDefault", false), + arguments("getWatchPostExecOrNull", null), + arguments("getWatchAutoCreateCustomNetworksOrDefault", false), + arguments("getWatchKeepContainerOrDefault", false), + arguments("getWatchRemoveVolumesOrDefault", false), + arguments("getWatchContainerNamePatternOrDefault", ContainerNamingUtil.DEFAULT_CONTAINER_NAME_PATTERN), + arguments("getWatchFollowOrDefault", false), + arguments("getWatchShowLogsOrNull", null)); + } + + @ParameterizedTest(name = "{index}: {0} with property ''{1}={2}'' returns ''{3}''") + @MethodSource("propertiesAndValues") + void getValue_withProperty_shouldReturnFromPropertyValue(String method, String property, String propertyValue, Object expectedValue) throws Exception { // Given extension.javaProject.getProperties().setProperty(property, propertyValue); // When @@ -188,4 +139,91 @@ public void getValue_withProperty_shouldReturnFromPropertyValue() throws Excepti // Then assertThat(result).isEqualTo(expectedValue); } + + static Stream propertiesAndValues() { + return Stream.of( + arguments("getOfflineOrDefault", "jkube.offline", "true", true), + arguments("getFailOnValidationErrorOrDefault", "jkube.failOnValidationError", "true", true), + arguments("getMergeWithDekorateOrDefault", "jkube.mergeWithDekorate", "true", true), + arguments("getInterpolateTemplateParametersOrDefault", "jkube.interpolateTemplateParameters", "false", false), + arguments("getSkipResourceValidationOrDefault", "jkube.skipResourceValidation", "true", true), + arguments("getSkipResourceOrDefault", "jkube.skip.resource", "true", true), + arguments("getSkipBuildOrDefault", "jkube.skip.build", "true", true), + arguments("getLogFollowOrDefault", "jkube.log.follow", "false", false), + arguments("getRecreateOrDefault", "jkube.recreate", "true", true), + arguments("getSkipApplyOrDefault", "jkube.skip.apply", "true", true), + arguments("getFailOnNoKubernetesJsonOrDefault", "jkube.deploy.failOnNoKubernetesJson", "true", true), + arguments("getCreateNewResourcesOrDefault", "jkube.deploy.create", "false", false), + arguments("getServicesOnlyOrDefault", "jkube.deploy.servicesOnly", "true", true), + arguments("getIgnoreServicesOrDefault", "jkube.deploy.ignoreServices", "true", true), + arguments("getJsonLogDirOrDefault", "jkube.deploy.jsonLogDir", + Paths.get("build", "jkube", "other").toString(), + Paths.get("build", "jkube", "other").toFile()), + arguments("getDeletePodsOnReplicationControllerUpdateOrDefault", "jkube.deploy.deletePods", "false", false), + arguments("getRollingUpgradesOrDefault", "jkube.rolling", "true", true), + arguments("getServiceUrlWaitTimeSecondsOrDefault", "jkube.serviceUrl.waitSeconds", "1337", 1337), + arguments("getKubernetesManifestOrDefault", "jkube.kubernetesManifest", + Paths.get("META-INF", "jkube", "other.yml").toString(), + Paths.get("META-INF", "jkube", "other.yml").toFile()), + arguments("getSkipOrDefault", "jkube.skip", "true", true), + arguments("getIgnoreRunningOAuthClientsOrDefault", "jkube.deploy.ignoreRunningOAuthClients", "false", false), + arguments("getProcessTemplatesLocallyOrDefault", "jkube.deploy.processTemplatesLocally", "false", false), + arguments("getRollingUpgradePreserveScaleOrDefault", "jkube.rolling.preserveScale", "true", true), + arguments("getSkipPushOrDefault", "jkube.skip.push", "true", true), + arguments("getPushRegistryOrNull", "jkube.docker.push.registry", "https://custom:5000", "https://custom:5000"), + arguments("getSkipTagOrDefault", "jkube.skip.tag", "true", true), + arguments("getPushRetriesOrDefault", "jkube.docker.push.retries", "1337", 1337), + arguments("getSkipExtendedAuthOrDefault", "jkube.docker.skip.extendedAuth", "true", true), + arguments("getBuildRecreateOrDefault", "jkube.build.recreate", "changed", "changed"), + arguments("getUseColorOrDefault", "jkube.useColor", "false", false), + arguments("getMaxConnectionsOrDefault", "jkube.docker.maxConnections", "1337", 1337), + arguments("getFilterOrNull", "jkube.image.filter", "foo", "foo"), + arguments("getApiVersionOrNull", "jkube.docker.apiVersion", "1.24", "1.24"), + arguments("getImagePullPolicyOrNull", "jkube.docker.imagePullPolicy", "Always", "Always"), + arguments("getAutoPullOrNull", "jkube.docker.autoPull", "true", "true"), + arguments("getDockerHostOrNull", "jkube.docker.host", "unix:///var/run/docker.sock", "unix:///var/run/docker.sock"), + arguments("getCertPathOrNull", "jkube.docker.certPath", "~/.docker", "~/.docker"), + arguments("getSkipMachineOrDefault", "jkube.docker.skip.machine", "true", true), + arguments("getForcePullOrDefault", "jkube.build.forcePull", "true", true), + arguments("getRegistryOrDefault", "jkube.docker.registry", "quay.io", "quay.io"), + arguments("getPullRegistryOrDefault", "jkube.docker.pull.registry", "quay.io", "quay.io"), + arguments("getBuildSourceDirectoryOrDefault", "jkube.build.source.dir", "src/main/other", "src/main/other"), + arguments("getBuildOutputDirectoryOrDefault", "jkube.build.target.dir", "build/other", "build/other"), + arguments("getResourceSourceDirectoryOrDefault", "jkube.resourceDir", + Paths.get("src", "main", "other").toString(), + Paths.get("src", "main", "other").toFile()), + arguments("getResourceTargetDirectoryOrDefault", "jkube.targetDir", + Paths.get("META-INF", "jkube", "other").toString(), + Paths.get("META-INF", "jkube", "other").toFile()), + arguments("getResourceEnvironmentOrNull", "jkube.environment", "dev", "dev"), + arguments("getWorkDirectoryOrDefault", "jkube.workDir", + Paths.get("jkube-work-other").toString(), + Paths.get("jkube-work-other").toFile()), + arguments("getProfileOrNull", "jkube.profile", "default", "default"), + arguments("getNamespaceOrNull", "jkube.namespace", "test", "test"), + arguments("getBuildStrategyOrDefault", "jkube.build.strategy", "s2i", JKubeBuildStrategy.s2i), + arguments("getBuildStrategyOrDefault", "jkube.build.strategy", "jib", JKubeBuildStrategy.jib), + arguments("getBuildStrategyOrDefault", "jkube.build.strategy", "docker", JKubeBuildStrategy.docker), + arguments("getResourceFileTypeOrDefault", "jkube.resourceType", "json", ResourceFileType.json), + arguments("getLogPodNameOrNull", "jkube.log.pod", "test", "test"), + arguments("getLogDateOrNull", "jkube.docker.logDate", "test", "test"), + arguments("getLogStdoutOrDefault", "jkube.docker.logStdout", "true", true), + arguments("getLogContainerNameOrNull", "jkube.log.container", "test", "test"), + arguments("getUseProjectClassPathOrDefault", "jkube.useProjectClasspath", "true", true), + arguments("getLocalDebugPortOrDefault", "jkube.debug.port", "1337", 1337), + arguments("getDebugSuspendOrDefault", "jkube.debug.suspend", "true", true), + arguments("getKubernetesTemplateOrDefault", "jkube.kubernetesTemplate", + Paths.get("META-INF", "jkube", "other").toString(), + Paths.get("META-INF", "jkube", "other").toFile()), + arguments("getWatchModeOrDefault", "jkube.watch.mode", "copy", WatchMode.copy), + arguments("getWatchIntervalOrDefault", "jkube.watch.interval", "10000", 10000), + arguments("getWatchKeepRunningOrDefault", "jkube.watch.keepRunning", "true", true), + arguments("getWatchPostExecOrNull", "jkube.watch.postExec", "ls -lt", "ls -lt"), + arguments("getWatchAutoCreateCustomNetworksOrDefault", "jkube.watch.autoCreateCustomNetworks", "true", true), + arguments("getWatchKeepContainerOrDefault", "jkube.watch.keepContainer", "true", true), + arguments("getWatchRemoveVolumesOrDefault", "jkube.watch.removeVolumes", "true", true), + arguments("getWatchContainerNamePatternOrDefault", "jkube.watch.containerNamePattern", "%n-%g", "%n-%g"), + arguments("getWatchFollowOrDefault", "jkube.watch.follow", "true", true), + arguments("getWatchShowLogsOrNull", "jkube.watch.showLogs", "true", "true")); + } } diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionTest.java index ff8477cc09..e2f3230788 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesExtensionTest.java @@ -20,17 +20,17 @@ import org.eclipse.jkube.kit.config.resource.RuntimeMode; import groovy.lang.Closure; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@SuppressWarnings({ "serial", "unused" }) -public class KubernetesExtensionTest { +@SuppressWarnings("unused") +class KubernetesExtensionTest { @Test - public void getRuntimeMode_withDefaults_shouldReturnKubernetes() { + void getRuntimeMode_withDefaults_shouldReturnKubernetes() { // Given final KubernetesExtension partial = mock(KubernetesExtension.class); when(partial.getRuntimeMode()).thenCallRealMethod(); @@ -41,14 +41,14 @@ public void getRuntimeMode_withDefaults_shouldReturnKubernetes() { } @Test - public void getBuildStrategy_withDefaults_shouldReturnDocker() { + void getBuildStrategy_withDefaults_shouldReturnDocker() { assertThat(new TestKubernetesExtension()) .extracting(TestKubernetesExtension::getBuildStrategyOrDefault) .isEqualTo(JKubeBuildStrategy.docker); } @Test - public void images_withCallableClosure_shouldSetImagesInClosureExecution() { + void images_withCallableClosure_shouldSetImagesInClosureExecution() { // Given final KubernetesExtension extension = new TestKubernetesExtension(); // When @@ -69,7 +69,7 @@ public Void doCall(Object... args) { } @Test - public void images_withMapListClosure_shouldSetImagesUsingConfigObjectParsing() { + void images_withMapListClosure_shouldSetImagesUsingConfigObjectParsing() { // Given final KubernetesExtension extension = new TestKubernetesExtension(); // When @@ -97,7 +97,7 @@ public Void doCall(Object... args) { } @Test - public void images_withListOfClosures_shouldSetImages() { + void images_withListOfClosures_shouldSetImages() { // Given final KubernetesExtension extension = new TestKubernetesExtension(); // When diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginRegisterTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginRegisterTaskTest.java index 5277bc29fa..475b30f003 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginRegisterTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginRegisterTaskTest.java @@ -13,8 +13,7 @@ */ package org.eclipse.jkube.gradle.plugin; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import org.eclipse.jkube.gradle.plugin.task.KubernetesApplyTask; import org.eclipse.jkube.gradle.plugin.task.KubernetesBuildTask; @@ -30,50 +29,45 @@ import org.eclipse.jkube.gradle.plugin.task.KubernetesWatchTask; import org.gradle.api.Project; import org.gradle.api.Task; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -@RunWith(Parameterized.class) -public class KubernetesPluginRegisterTaskTest { +class KubernetesPluginRegisterTaskTest { - @Parameterized.Parameters(name = "{index} {0}") - public static Collection data() { - return Arrays.asList( - new Object[] { "k8sApply", KubernetesApplyTask.class }, - new Object[] { "k8sBuild", KubernetesBuildTask.class }, - new Object[] { "k8sConfigView", KubernetesConfigViewTask.class }, - new Object[] { "k8sDebug", KubernetesDebugTask.class }, - new Object[] { "k8sLog", KubernetesLogTask.class }, - new Object[] { "k8sPush", KubernetesPushTask.class }, - new Object[] { "k8sResource", KubernetesResourceTask.class }, - new Object[] { "k8sUndeploy", KubernetesUndeployTask.class }, - new Object[] { "k8sHelm", KubernetesHelmTask.class }, - new Object[] { "k8sHelmPush", KubernetesHelmPushTask.class }, - new Object[] { "k8sWatch", KubernetesWatchTask.class}); + static Stream data() { + return Stream.of( + arguments("k8sApply", KubernetesApplyTask.class), + arguments("k8sBuild", KubernetesBuildTask.class), + arguments("k8sConfigView", KubernetesConfigViewTask.class), + arguments("k8sDebug", KubernetesDebugTask.class), + arguments("k8sLog", KubernetesLogTask.class), + arguments("k8sPush", KubernetesPushTask.class), + arguments("k8sResource", KubernetesResourceTask.class), + arguments("k8sUndeploy", KubernetesUndeployTask.class), + arguments("k8sHelm", KubernetesHelmTask.class), + arguments("k8sHelmPush", KubernetesHelmPushTask.class), + arguments("k8sWatch", KubernetesWatchTask.class) + ); } - @Parameterized.Parameter - public String task; - - @Parameterized.Parameter(1) - public Class taskClass; - private Project project; - @Before - public void setUp() { + @BeforeEach + void setUp() { project = mock(Project.class, RETURNS_DEEP_STUBS); } - @Test - public void apply_withValidProject_shouldCreateExtensionAndRegisterTask() { + @ParameterizedTest(name = "{index}: with valid project, should create extension and register task ''{0}'' ") + @MethodSource("data") + void apply_withValidProject_shouldCreateExtensionAndRegisterTask(String task, Class taskClass) { // When new KubernetesPlugin().apply(project); // Then diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginTest.java index cbfb695f99..14440ed8e3 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/KubernetesPluginTest.java @@ -29,8 +29,8 @@ import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.tasks.TaskProvider; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -42,18 +42,18 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesPluginTest { +class KubernetesPluginTest { private Project project; - @Before - public void setUp() { + @BeforeEach + void setUp() { project = mock(Project.class, RETURNS_DEEP_STUBS); } @SuppressWarnings("unchecked") @Test - public void apply_withValidProject_shouldConfigureTasks() { + void apply_withValidProject_shouldConfigureTasks() { // Given final JKubeTask mockTask = mock(JKubeTask.class, RETURNS_DEEP_STUBS); final AtomicReference> action = new AtomicReference<>(); @@ -76,7 +76,7 @@ public void apply_withValidProject_shouldConfigureTasks() { } @Test - public void getTaskPrecedence_withValidProject_shouldReturnTaskPrecedence() { + void getTaskPrecedence_withValidProject_shouldReturnTaskPrecedence() { //When final Map>> result = new KubernetesPlugin().getTaskPrecedence(); // Then diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesApplyTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesApplyTaskTest.java index 6c2d71da8c..77c6cb55e1 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesApplyTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesApplyTaskTest.java @@ -25,14 +25,15 @@ import org.gradle.api.internal.provider.DefaultProperty; import org.gradle.api.provider.Property; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -41,17 +42,17 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesApplyTaskTest { +class KubernetesApplyTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private MockedConstruction clusterAccessMockedConstruction; private MockedConstruction applyServiceMockedConstruction; private TestKubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { clusterAccessMockedConstruction = mockConstruction(ClusterAccess.class, (mock, ctx) -> { // OpenShiftClient instance needed due to OpenShift checks performed in KubernetesApply final OpenShiftClient kubernetesClient = mock(OpenShiftClient.class); @@ -65,40 +66,37 @@ public void setUp() throws IOException { extension.isFailOnNoKubernetesJson = false; } - @After - public void tearDown() { + @AfterEach + void tearDown() { applyServiceMockedConstruction.close(); clusterAccessMockedConstruction.close(); } @Test - public void runTask_withOffline_shouldThrowException() { + void runTask_withOffline_shouldThrowException() { // Given extension.isOffline = true; final KubernetesApplyTask applyTask = new KubernetesApplyTask(KubernetesExtension.class); - // When - final IllegalArgumentException result = assertThrows(IllegalArgumentException.class, applyTask::runTask); - - // Then - assertThat(result) - .hasMessage("Connection to Cluster required. Please check if offline mode is set to false"); + // When & Then + assertThatIllegalArgumentException() + .isThrownBy(applyTask::runTask) + .withMessage("Connection to Cluster required. Please check if offline mode is set to false"); } @Test - public void runTask_withNoManifest_shouldThrowException() { + void runTask_withNoManifest_shouldThrowException() { // Given extension.isFailOnNoKubernetesJson = true; final KubernetesApplyTask applyTask = new KubernetesApplyTask(KubernetesExtension.class); - // When - final IllegalStateException result = assertThrows(IllegalStateException.class, applyTask::runTask); - // Then - assertThat(result) - .hasMessageMatching("No such generated manifest file: .+kubernetes\\.yml"); + // When & Then + assertThatIllegalStateException() + .isThrownBy(applyTask::runTask) + .withMessageMatching("No such generated manifest file: .+kubernetes\\.yml"); } @Test - public void configureApplyService_withManifest_shouldSetDefaults() throws Exception { + void configureApplyService_withManifest_shouldSetDefaults() throws Exception { // Given taskEnvironment.withKubernetesManifest(); final KubernetesApplyTask applyTask = new KubernetesApplyTask(KubernetesExtension.class); @@ -123,7 +121,7 @@ public void configureApplyService_withManifest_shouldSetDefaults() throws Except } @Test - public void runTask_withManifest_shouldApplyEntities() throws Exception { + void runTask_withManifest_shouldApplyEntities() throws Exception { // Given taskEnvironment.withKubernetesManifest(); final KubernetesApplyTask applyTask = new KubernetesApplyTask(KubernetesExtension.class); @@ -136,7 +134,7 @@ public void runTask_withManifest_shouldApplyEntities() throws Exception { } @Test - public void runTask_withSkipApply_shouldDoNothing() { + void runTask_withSkipApply_shouldDoNothing() { // Given extension = new TestKubernetesExtension() { @Override diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesBuildTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesBuildTaskTest.java index fcfa0958c8..0c09e22ae7 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesBuildTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesBuildTaskTest.java @@ -16,7 +16,6 @@ import java.io.IOException; import java.util.Collections; -import org.assertj.core.api.Assertions; import org.eclipse.jkube.gradle.plugin.KubernetesExtension; import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; import org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory; @@ -29,14 +28,15 @@ import org.gradle.api.GradleException; import org.gradle.api.internal.provider.DefaultProperty; import org.gradle.api.provider.Property; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; -import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -45,10 +45,10 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesBuildTaskTest { +class KubernetesBuildTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private MockedConstruction dockerAccessFactoryMockedConstruction; private MockedConstruction dockerBuildServiceMockedConstruction; @@ -56,8 +56,8 @@ public class KubernetesBuildTaskTest { private boolean isBuildServiceApplicable; private boolean isBuildError; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { // Mock required for environments with no DOCKER available (don't remove) dockerAccessFactoryMockedConstruction = mockConstruction(DockerAccessFactory.class, (mock, ctx) -> when(mock.createDockerAccess(any())).thenReturn(mock(DockerAccess.class))); @@ -79,14 +79,14 @@ public void setUp() throws IOException { .build()); } - @After - public void tearDown() { + @AfterEach + void tearDown() { dockerBuildServiceMockedConstruction.close(); dockerAccessFactoryMockedConstruction.close(); } @Test - public void runTask_withImageConfiguration_shouldRunBuild() throws JKubeServiceException { + void runTask_withImageConfiguration_shouldRunBuild() throws JKubeServiceException { // Given final KubernetesBuildTask buildTask = new KubernetesBuildTask(KubernetesExtension.class); // When @@ -98,31 +98,29 @@ public void runTask_withImageConfiguration_shouldRunBuild() throws JKubeServiceE } @Test - public void runTask_withImageConfigurationAndNoApplicableService_shouldThrowException() { + void runTask_withImageConfigurationAndNoApplicableService_shouldThrowException() { // Given isBuildServiceApplicable = false; final KubernetesBuildTask buildTask = new KubernetesBuildTask(KubernetesExtension.class); - // When - final IllegalStateException result = assertThrows(IllegalStateException.class, buildTask::runTask); - // Then - assertThat(result) - .hasMessage("No suitable Build Service was found for your current configuration"); + // When & Then + assertThatIllegalStateException() + .isThrownBy(buildTask::runTask) + .withMessage("No suitable Build Service was found for your current configuration"); } @Test - public void runTask_withImageConfigurationAndBuildError_shouldThrowException() { + void runTask_withImageConfigurationAndBuildError_shouldThrowException() { // Given isBuildError = true; final KubernetesBuildTask buildTask = new KubernetesBuildTask(KubernetesExtension.class); - // When - final GradleException result = assertThrows(GradleException.class, buildTask::runTask); - // Then - assertThat(result) - .hasMessage("Exception during Build"); + // When & Then + assertThatExceptionOfType(GradleException.class) + .isThrownBy(buildTask::runTask) + .withMessage("Exception during Build"); } @Test - public void runTask_withSkipBuild_shouldDoNothing() throws JKubeServiceException { + void runTask_withSkipBuild_shouldDoNothing() throws JKubeServiceException { // Given extension = new TestKubernetesExtension() { @Override @@ -137,7 +135,7 @@ public Property getSkipBuild() { buildTask.runTask(); // Then - Assertions.assertThat(dockerBuildServiceMockedConstruction.constructed()).isEmpty(); + assertThat(dockerBuildServiceMockedConstruction.constructed()).isEmpty(); verify(buildTask.jKubeServiceHub.getBuildService(), times(0)).build(any()); } } diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesConfigViewTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesConfigViewTaskTest.java index 802d1d06e3..b7b00e7025 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesConfigViewTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesConfigViewTaskTest.java @@ -18,31 +18,30 @@ import org.eclipse.jkube.gradle.plugin.KubernetesExtension; import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesConfigViewTaskTest { +class KubernetesConfigViewTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private TestKubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { extension = new TestKubernetesExtension(); when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); } @Test - public void runTask_withManualSettings_shouldLogThem() { + void runTask_withManualSettings_shouldLogThem() { // Given extension.buildStrategy = JKubeBuildStrategy.s2i; extension.isOffline = true; diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesDebugTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesDebugTaskTest.java index 3f202bb5de..e2fbd990d1 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesDebugTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesDebugTaskTest.java @@ -21,14 +21,14 @@ import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; import org.eclipse.jkube.kit.config.service.DebugService; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mockConstruction; @@ -36,40 +36,39 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesDebugTaskTest { +class KubernetesDebugTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private MockedConstruction debugServiceMockedConstruction; private TestKubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { debugServiceMockedConstruction = mockConstruction(DebugService.class); extension = new TestKubernetesExtension(); when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); } - @After - public void tearDown() { + @AfterEach + void tearDown() { debugServiceMockedConstruction.close(); } @Test - public void runTask_withNoManifest_shouldThrowException() { + void runTask_withNoManifest_shouldThrowException() { // Given extension.isFailOnNoKubernetesJson = true; final KubernetesDebugTask debugTask = new KubernetesDebugTask(KubernetesExtension.class); - // When - final IllegalStateException result = assertThrows(IllegalStateException.class, debugTask::runTask); - // Then - assertThat(result) - .hasMessageMatching("No such generated manifest file: .+kubernetes\\.yml"); + // When & Then + assertThatIllegalStateException() + .isThrownBy(debugTask::runTask) + .withMessageMatching("No such generated manifest file: .+kubernetes\\.yml"); } @Test - public void runTask_withManifest_shouldStartDebug() throws Exception { + void runTask_withManifest_shouldStartDebug() throws Exception { // Given taskEnvironment.withKubernetesManifest(); final KubernetesDebugTask debugTask = new KubernetesDebugTask(KubernetesExtension.class); diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmPushTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmPushTaskTest.java index 662e712c58..8475988583 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmPushTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmPushTaskTest.java @@ -17,55 +17,55 @@ import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; import org.eclipse.jkube.kit.resource.helm.BadUploadException; import org.eclipse.jkube.kit.resource.helm.HelmService; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; import java.io.IOException; import java.nio.file.NoSuchFileException; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesHelmPushTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); +class KubernetesHelmPushTaskTest { + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); - private TestKubernetesExtension extension; private MockedConstruction helmServiceMockedConstruction; - @Before - public void setUp() throws IOException { - extension = new TestKubernetesExtension(); + @BeforeEach + void setUp() throws IOException { + TestKubernetesExtension extension = new TestKubernetesExtension(); extension.isUseColor = false; helmServiceMockedConstruction = mockConstruction(HelmService.class); when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); } + @AfterEach + void tearDown() { + helmServiceMockedConstruction.close(); + } + @Test - public void runTask_withNoTemplateDir_shouldThrowException() { + void runTask_withNoTemplateDir_shouldThrowException() { // Given KubernetesHelmPushTask kubernetesHelmPushTask = new KubernetesHelmPushTask(KubernetesExtension.class); - // When - IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, kubernetesHelmPushTask::runTask); - - // Then - assertThat(illegalStateException) - .hasMessageContaining("META-INF/jkube/kubernetes") - .getCause() - .isInstanceOf(NoSuchFileException.class); + // When & Then + assertThatIllegalStateException() + .isThrownBy(kubernetesHelmPushTask::runTask) + .withMessageContaining("META-INF/jkube/kubernetes") + .withCauseInstanceOf(NoSuchFileException.class); } @Test - public void runTask_withTemplateDir_shouldCallHelmService() throws IOException, BadUploadException { + void runTask_withTemplateDir_shouldCallHelmService() throws IOException, BadUploadException { // Given taskEnvironment.withKubernetesTemplate(); KubernetesHelmPushTask kubernetesHelmPushTask = new KubernetesHelmPushTask(KubernetesExtension.class); @@ -76,9 +76,4 @@ public void runTask_withTemplateDir_shouldCallHelmService() throws IOException, // Then verify((helmServiceMockedConstruction.constructed().iterator().next()), times(1)).uploadHelmChart(any()); } - - @After - public void tearDown() { - helmServiceMockedConstruction.close(); - } } diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTaskTest.java index bc3660dc4a..e8bbcdc832 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTaskTest.java @@ -20,52 +20,52 @@ import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; import org.eclipse.jkube.kit.resource.helm.HelmService; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesHelmTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); +class KubernetesHelmTaskTest { + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); - private TestKubernetesExtension extension; private MockedConstruction helmServiceMockedConstruction; - @Before - public void setUp() throws IOException { - extension = new TestKubernetesExtension(); + @BeforeEach + void setUp() throws IOException { + TestKubernetesExtension extension = new TestKubernetesExtension(); extension.isUseColor = false; helmServiceMockedConstruction = mockConstruction(HelmService.class); when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); } + @AfterEach + void tearDown() { + helmServiceMockedConstruction.close(); + } + @Test - public void runTask_withNoTemplateDir_shouldThrowException() { + void runTask_withNoTemplateDir_shouldThrowException() { // Given KubernetesHelmTask kubernetesHelmTask = new KubernetesHelmTask(KubernetesExtension.class); - // When - IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, kubernetesHelmTask::runTask); - - // Then - assertThat(illegalStateException) - .hasMessageContaining("META-INF/jkube/kubernetes") - .getCause() - .isInstanceOf(NoSuchFileException.class); + // When & Then + assertThatIllegalStateException() + .isThrownBy(kubernetesHelmTask::runTask) + .withMessageContaining("META-INF/jkube/kubernetes") + .withCauseInstanceOf(NoSuchFileException.class); } @Test - public void runTask_withTemplateDir_shouldCallHelmService() throws IOException { + void runTask_withTemplateDir_shouldCallHelmService() throws IOException { // Given taskEnvironment.withKubernetesTemplate(); KubernetesHelmTask kubernetesHelmTask = new KubernetesHelmTask(KubernetesExtension.class); @@ -77,8 +77,4 @@ public void runTask_withTemplateDir_shouldCallHelmService() throws IOException { verify((helmServiceMockedConstruction.constructed().iterator().next()), times(1)).generateHelmCharts(any()); } - @After - public void tearDown() { - helmServiceMockedConstruction.close(); - } } diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesLogTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesLogTaskTest.java index d1da03a012..8949b57e42 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesLogTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesLogTaskTest.java @@ -20,34 +20,34 @@ import org.eclipse.jkube.kit.common.util.KubernetesHelper; import org.gradle.api.GradleException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedStatic; import org.mockito.Mockito; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesLogTaskTest { +class KubernetesLogTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private TestKubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { extension = new TestKubernetesExtension(); extension.isUseColor = false; when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); } @Test - public void runTask_withNoK8sManifests_shouldLogCantWatchPods() { + void runTask_withNoK8sManifests_shouldLogCantWatchPods() { // Given KubernetesLogTask kubernetesLogTask = new KubernetesLogTask(KubernetesExtension.class); @@ -59,27 +59,26 @@ public void runTask_withNoK8sManifests_shouldLogCantWatchPods() { } @Test - public void runTask_withNoManifestAndFailure_shouldThrowException() { + void runTask_withNoManifestAndFailure_shouldThrowException() { // Given extension.isFailOnNoKubernetesJson = true; final KubernetesLogTask kubernetesLogTask = new KubernetesLogTask(KubernetesExtension.class); - // When - final IllegalStateException result = assertThrows(IllegalStateException.class, kubernetesLogTask::runTask); - // Then - assertThat(result) - .hasMessageMatching("No such generated manifest file: .+kubernetes\\.yml"); + // When & Then + assertThatIllegalStateException() + .isThrownBy(kubernetesLogTask::runTask) + .withMessageMatching("No such generated manifest file: .+kubernetes\\.yml"); } @Test - public void runTask_withIOException_shouldThrowException() { + void runTask_withIOException_shouldThrowException() { try (MockedStatic mockStatic = Mockito.mockStatic(KubernetesHelper.class)) { // Given mockStatic.when(() -> KubernetesHelper.loadResources(any())).thenThrow(new IOException("IO error with logs")); KubernetesLogTask kubernetesLogTask = new KubernetesLogTask(KubernetesExtension.class); - // When - final Exception result = assertThrows(GradleException.class, kubernetesLogTask::runTask); - // Then - assertThat(result).hasMessage("Failure in getting logs"); + // When & Then + assertThatExceptionOfType(GradleException.class) + .isThrownBy(kubernetesLogTask::runTask) + .withMessage("Failure in getting logs"); } } } diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesPushTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesPushTaskTest.java index 46d183c2e8..c2f4c9de98 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesPushTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesPushTaskTest.java @@ -16,7 +16,6 @@ import java.io.IOException; import java.util.Collections; -import org.assertj.core.api.Assertions; import org.eclipse.jkube.gradle.plugin.KubernetesExtension; import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; import org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory; @@ -28,10 +27,10 @@ import org.gradle.api.internal.provider.DefaultProperty; import org.gradle.api.provider.Property; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; @@ -46,17 +45,17 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesPushTaskTest { +class KubernetesPushTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private MockedConstruction dockerAccessFactoryMockedConstruction; private MockedConstruction dockerBuildServiceMockedConstruction; private KubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { // Mock required for environments with no DOCKER available (don't remove) dockerAccessFactoryMockedConstruction = mockConstruction(DockerAccessFactory.class, (mock, ctx) -> when(mock.createDockerAccess(any())).thenReturn(mock(DockerAccess.class))); @@ -72,14 +71,14 @@ public void setUp() throws IOException { .build()); } - @After - public void tearDown() { + @AfterEach + void tearDown() { dockerBuildServiceMockedConstruction.close(); dockerAccessFactoryMockedConstruction.close(); } @Test - public void run_withImageConfiguration_shouldPushImage() throws JKubeServiceException { + void run_withImageConfiguration_shouldPushImage() throws JKubeServiceException { // Given final KubernetesPushTask kubernetesPushTask = new KubernetesPushTask(KubernetesExtension.class); @@ -94,7 +93,7 @@ public void run_withImageConfiguration_shouldPushImage() throws JKubeServiceExce @Test - public void runTask_withSkipPush_shouldDoNothing() throws JKubeServiceException { + void runTask_withSkipPush_shouldDoNothing() throws JKubeServiceException { // Given extension = new TestKubernetesExtension() { @Override @@ -110,7 +109,7 @@ public Property getSkipPush() { pushTask.runTask(); // Then - Assertions.assertThat(dockerBuildServiceMockedConstruction.constructed()).isEmpty(); + assertThat(dockerBuildServiceMockedConstruction.constructed()).isEmpty(); verify(pushTask.jKubeServiceHub.getBuildService(), times(0)).push(any(), anyInt(), any(), anyBoolean()); verify(taskEnvironment.logger, times(1)).lifecycle(contains("k8s: `k8sPush` task is skipped.")); diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesResourceTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesResourceTaskTest.java index 9eebe9fbce..71c68a2cc0 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesResourceTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesResourceTaskTest.java @@ -26,26 +26,26 @@ import org.apache.commons.io.FileUtils; import org.gradle.api.internal.provider.DefaultProperty; import org.gradle.api.provider.Property; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.mockito.Mockito.when; -public class KubernetesResourceTaskTest { +class KubernetesResourceTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)) .thenReturn(new TestKubernetesExtension()); } @Test - public void runTask_withImageConfiguration_shouldGenerateResources() { + void runTask_withImageConfiguration_shouldGenerateResources() { // Given KubernetesResourceTask resourceTask = new KubernetesResourceTask(KubernetesExtension.class); // When @@ -60,7 +60,7 @@ public void runTask_withImageConfiguration_shouldGenerateResources() { } @Test - public void runTask_withMultipleFiles_shouldInterpolateApplicableFragments() throws IOException { + void runTask_withMultipleFiles_shouldInterpolateApplicableFragments() throws IOException { // Given final Map properties = new HashMap<>(); properties.put("some.property", "value"); @@ -82,7 +82,7 @@ public void runTask_withMultipleFiles_shouldInterpolateApplicableFragments() thr } @Test - public void runTask_withSkipResource_shouldDoNothing() { + void runTask_withSkipResource_shouldDoNothing() { // Given KubernetesExtension extension = new TestKubernetesExtension() { @Override diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTaskTest.java index b056fe7cf9..d184f5d19f 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTaskTest.java @@ -27,31 +27,31 @@ import io.fabric8.kubernetes.client.KubernetesClient; import org.gradle.api.internal.provider.DefaultProperty; import org.gradle.api.provider.Property; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class KubernetesUndeployTaskTest { +class KubernetesUndeployTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private MockedConstruction kubernetesUndeployServiceMockedConstruction; private MockedConstruction clusterAccessMockedConstruction; private TestKubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { clusterAccessMockedConstruction = mockConstruction(ClusterAccess.class, (mock, ctx) -> { final KubernetesClient kubernetesClient = mock(KubernetesClient.class); when(mock.createDefaultClient()).thenReturn(kubernetesClient); @@ -62,28 +62,26 @@ public void setUp() throws IOException { when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); } - @After - public void tearDown() { + @AfterEach + void tearDown() { kubernetesUndeployServiceMockedConstruction.close(); clusterAccessMockedConstruction.close(); } @Test - public void runTask_withOffline_shouldThrowException() { + void runTask_withOffline_shouldThrowException() { // Given extension.isOffline = true; final KubernetesUndeployTask undeployTask = new KubernetesUndeployTask(KubernetesExtension.class); - // When - IllegalArgumentException illegalStateException = assertThrows(IllegalArgumentException.class, undeployTask::runTask); - - // Then - assertThat(illegalStateException) - .hasMessage("Connection to Cluster required. Please check if offline mode is set to false"); + // When & Then + assertThatIllegalArgumentException() + .isThrownBy(undeployTask::runTask) + .withMessage("Connection to Cluster required. Please check if offline mode is set to false"); } @Test - public void runTask_withOfflineTrue_shouldUndeployResources() throws IOException { + void runTask_withOfflineTrue_shouldUndeployResources() throws IOException { // Given final KubernetesUndeployTask undeployTask = new KubernetesUndeployTask(KubernetesExtension.class); @@ -102,7 +100,7 @@ public void runTask_withOfflineTrue_shouldUndeployResources() throws IOException } @Test - public void runTask_withSkipUndeploy_shouldDoNothing() { + void runTask_withSkipUndeploy_shouldDoNothing() { // Given extension = new TestKubernetesExtension() { @Override diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesWatchTaskTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesWatchTaskTest.java index f3a27a33d2..7f1f62eaa2 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesWatchTaskTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesWatchTaskTest.java @@ -23,10 +23,10 @@ import org.eclipse.jkube.kit.config.access.ClusterAccess; import org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService; import org.eclipse.jkube.watcher.api.WatcherManager; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.MockedConstruction; import org.mockito.MockedStatic; @@ -34,7 +34,7 @@ import java.net.URL; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; @@ -43,10 +43,10 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; -public class KubernetesWatchTaskTest { +class KubernetesWatchTaskTest { - @Rule - public TaskEnvironment taskEnvironment = new TaskEnvironment(); + @RegisterExtension + private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); private MockedConstruction dockerAccessFactoryMockedConstruction; private MockedConstruction dockerBuildServiceMockedConstruction; @@ -55,8 +55,8 @@ public class KubernetesWatchTaskTest { private MockedStatic kubernetesHelperMockedStatic; private TestKubernetesExtension extension; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { // Mock required for environments with no DOCKER available (don't remove) dockerAccessFactoryMockedConstruction = mockConstruction(DockerAccessFactory.class, (mock, ctx) -> when(mock.createDockerAccess(any())).thenReturn(mock(DockerAccess.class))); @@ -76,8 +76,8 @@ public void setUp() throws IOException { extension.isFailOnNoKubernetesJson = false; } - @After - public void tearDown() { + @AfterEach + void tearDown() { watcherManagerMockedStatic.close(); kubernetesHelperMockedStatic.close(); clusterAccessMockedConstruction.close(); @@ -86,21 +86,20 @@ public void tearDown() { } @Test - public void runTask_withNoManifest_shouldThrowException() { + void runTask_withNoManifest_shouldThrowException() { // Given extension.isFailOnNoKubernetesJson = true; final KubernetesWatchTask watchTask = new KubernetesWatchTask(KubernetesExtension.class); - // When - final IllegalStateException result = assertThrows(IllegalStateException.class, watchTask::runTask); - // Then - AssertionsForClassTypes.assertThat(watchTask.jKubeServiceHub.getBuildService()).isNotNull() + // When & Then + assertThatIllegalStateException() + .isThrownBy(watchTask::runTask) + .withMessageContaining("An error has occurred while while trying to watch the resources"); + assertThat(watchTask.jKubeServiceHub.getBuildService()).isNotNull() .isInstanceOf(DockerBuildService.class); - assertThat(result) - .hasMessageContaining("An error has occurred while while trying to watch the resources"); } @Test - public void runTask_withManifest_shouldWatchEntities() throws Exception { + void runTask_withManifest_shouldWatchEntities() throws Exception { // Given taskEnvironment.withKubernetesManifest(); final KubernetesWatchTask watchTask = new KubernetesWatchTask(KubernetesExtension.class); diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironmentExtension.java similarity index 61% rename from gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java rename to gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironmentExtension.java index 80e7b3c065..cc4fb383af 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironmentExtension.java @@ -13,7 +13,7 @@ */ package org.eclipse.jkube.gradle.plugin.task; -import org.eclipse.jgit.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.gradle.api.DefaultTask; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -21,11 +21,14 @@ import org.gradle.api.internal.plugins.DefaultPluginContainer; import org.gradle.api.logging.Logger; import org.gradle.api.plugins.JavaPluginConvention; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.mockito.MockedConstruction; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -35,24 +38,24 @@ import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.when; -public class TaskEnvironment extends TemporaryFolder { - - private MockedConstruction defaultTaskMockedConstruction; - Logger logger; +public class TaskEnvironmentExtension implements BeforeEachCallback, AfterEachCallback { Project project; + Logger logger; + private File temporaryFolder; + private MockedConstruction defaultTaskMockedConstruction; @Override - protected void before() throws Throwable { - super.before(); + public void beforeEach(ExtensionContext context) throws Exception { + temporaryFolder = Files.createTempDirectory("junit").toFile(); project = mock(Project.class, RETURNS_DEEP_STUBS); logger = mock(Logger.class); - when(project.getProjectDir()).thenReturn(getRoot()); - when(project.getBuildDir()).thenReturn(newFolder("build")); + when(project.getProjectDir()).thenReturn(temporaryFolder); + when(project.getBuildDir()).thenReturn(Files.createDirectory(temporaryFolder.toPath().resolve("build")).toFile()); when(project.getPlugins()).thenReturn(new DefaultPluginContainer(null, null, null)); final ConfigurationContainer cc = mock(ConfigurationContainer.class); when(project.getConfigurations()).thenReturn(cc); - List projectConfigurations = new ArrayList(); + List projectConfigurations = new ArrayList<>(); when(cc.stream()).thenAnswer(i -> projectConfigurations.stream()); when(cc.toArray()).thenAnswer(i -> projectConfigurations.toArray()); @@ -65,17 +68,26 @@ protected void before() throws Throwable { } @Override - protected void after() { - super.after(); + public void afterEach(ExtensionContext context) throws Exception { defaultTaskMockedConstruction.close(); + FileUtils.deleteDirectory(temporaryFolder); + } + + public File getRoot() { + return temporaryFolder; } public void withKubernetesManifest() throws IOException { - final File manifestsDir = newFolder("build", "classes", "java", "main", "META-INF", "jkube"); - FileUtils.touch(new File(manifestsDir, "kubernetes.yml").toPath()); + final File manifestsDir = Files + .createDirectories(temporaryFolder.toPath().resolve("build").resolve("classes").resolve("java") + .resolve("main").resolve("META-INF").resolve("jkube")) + .toFile(); + Files.createFile(manifestsDir.toPath().resolve("kubernetes.yml")); } public void withKubernetesTemplate() throws IOException { - newFolder("build", "classes", "java", "main", "META-INF", "jkube", "kubernetes"); + Files.createDirectories(temporaryFolder.toPath().resolve("build").resolve("classes").resolve("java") + .resolve("main").resolve("META-INF").resolve("jkube").resolve("kubernetes")); } + } diff --git a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskUtilTest.java b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskUtilTest.java index c281375fcf..e41d054616 100644 --- a/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskUtilTest.java +++ b/gradle-plugin/kubernetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskUtilTest.java @@ -19,8 +19,8 @@ import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; import org.eclipse.jkube.kit.config.resource.BuildRecreateMode; import org.eclipse.jkube.kit.config.service.BuildServiceConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.MockedConstruction; import static org.assertj.core.api.Assertions.assertThat; @@ -32,18 +32,18 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class TaskUtilTest { +class TaskUtilTest { private TestKubernetesExtension extension; private KitLogger kitLogger; - @Before - public void setUp() { + @BeforeEach + void setUp() { extension = new TestKubernetesExtension(); kitLogger = mock(KitLogger.class, RETURNS_DEEP_STUBS); } @Test - public void buildServiceConfigBuilder_shouldInitializeBuildServiceConfigWithDefaults() { + void buildServiceConfigBuilder_shouldInitializeBuildServiceConfigWithDefaults() { // When BuildServiceConfig buildServiceConfig = TaskUtil.buildServiceConfigBuilder(extension).build(); @@ -56,7 +56,7 @@ public void buildServiceConfigBuilder_shouldInitializeBuildServiceConfigWithDefa } @Test - public void buildServiceConfigBuilder_shouldInitializeBuildServiceConfigWithConfiguredValues() { + void buildServiceConfigBuilder_shouldInitializeBuildServiceConfigWithConfiguredValues() { // Given extension.buildRecreate = "true"; extension.isForcePull = true; @@ -75,7 +75,7 @@ public void buildServiceConfigBuilder_shouldInitializeBuildServiceConfigWithConf } @Test - public void initDockerAccess_withDockerAccessRequired_shouldReturnDockerAccess() { + void initDockerAccess_withDockerAccessRequired_shouldReturnDockerAccess() { try (MockedConstruction daf = mockConstruction(DockerAccessFactory.class)) { // When TaskUtil.initDockerAccess(extension, kitLogger); @@ -86,7 +86,7 @@ public void initDockerAccess_withDockerAccessRequired_shouldReturnDockerAccess() } @Test - public void initDockerAccess_withNoDockerAccessRequired_shouldReturnNull() { + void initDockerAccess_withNoDockerAccessRequired_shouldReturnNull() { try (MockedConstruction daf = mockConstruction(DockerAccessFactory.class)) { // Given extension.buildStrategy = JKubeBuildStrategy.jib;