diff --git a/jkube-kit/resource/service/pom.xml b/jkube-kit/resource/service/pom.xml index b9cad38ae4..c008de56e6 100644 --- a/jkube-kit/resource/service/pom.xml +++ b/jkube-kit/resource/service/pom.xml @@ -40,8 +40,9 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine + test org.jmockit diff --git a/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/DefaultResourceServiceTest.java b/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/DefaultResourceServiceTest.java index 839a7d6a9b..d3878f1f7a 100644 --- a/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/DefaultResourceServiceTest.java +++ b/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/DefaultResourceServiceTest.java @@ -33,24 +33,19 @@ import mockit.Mocked; import mockit.Verifications; import org.eclipse.jkube.kit.config.resource.ResourceServiceConfig; -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 static org.assertj.core.api.Assertions.assertThat; -public class DefaultResourceServiceTest { +@SuppressWarnings("unused") +class DefaultResourceServiceTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - @SuppressWarnings("unused") @Mocked private EnricherManager enricherManager; - @SuppressWarnings("unused") @Mocked private KitLogger kitLogger; - @SuppressWarnings("unused") @Mocked private ResourceConfig resourceConfig; @Mocked @@ -60,22 +55,22 @@ public class DefaultResourceServiceTest { private ResourceServiceConfig resourceServiceConfig; private DefaultResourceService defaultResourceService; - @Before - public void init() throws IOException { - targetDir = temporaryFolder.newFolder("target"); + @BeforeEach + void init(@TempDir File temporaryFolder) { + targetDir = new File(temporaryFolder, "target"); resourceServiceConfig = ResourceServiceConfig.builder() .interpolateTemplateParameters(true) .targetDir(targetDir) .project(project) .resourceFileType(ResourceFileType.yaml) - .resourceDirs(Collections.singletonList(temporaryFolder.newFolder("resources"))) + .resourceDirs(Collections.singletonList(new File(temporaryFolder, "resources"))) .resourceConfig(resourceConfig) .build(); defaultResourceService = new DefaultResourceService(resourceServiceConfig); } @Test - public void generateResourcesWithNoResourcesShouldReturnEmpty() throws IOException { + void generateResourcesWithNoResourcesShouldReturnEmpty() throws IOException { // When final KubernetesList result = defaultResourceService .generateResources(PlatformMode.kubernetes, enricherManager, kitLogger); @@ -84,7 +79,7 @@ public void generateResourcesWithNoResourcesShouldReturnEmpty() throws IOExcepti } @Test - public void generateResources_withResources_shouldReturnKubernetesResourceList() throws IOException { + void generateResources_withResources_shouldReturnKubernetesResourceList() throws IOException { // Given File resourceDir1 = new File(Objects.requireNonNull(getClass().getResource("/jkube/common")).getFile()); File resourceDir2 = new File(Objects.requireNonNull(getClass().getResource("/jkube/dev")).getFile()); @@ -113,7 +108,7 @@ public void generateResources_withResources_shouldReturnKubernetesResourceList() @SuppressWarnings("AccessStaticViaInstance") @Test - public void writeResources(@Mocked WriteUtil writeUtil, @Mocked TemplateUtil templateUtil) throws IOException { + void writeResources(@Mocked WriteUtil writeUtil, @Mocked TemplateUtil templateUtil) throws IOException { // When defaultResourceService.writeResources(null, ResourceClassifier.KUBERNETES, kitLogger); // Then diff --git a/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/TemplateUtilTest.java b/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/TemplateUtilTest.java index 33fc432024..8ab824cc71 100644 --- a/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/TemplateUtilTest.java +++ b/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/TemplateUtilTest.java @@ -24,36 +24,35 @@ import mockit.Mocked; import mockit.Verifications; import org.apache.commons.io.FileUtils; -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.eclipse.jkube.kit.resource.service.TemplateUtil.getSingletonTemplate; import static org.eclipse.jkube.kit.resource.service.TemplateUtil.interpolateTemplateVariables; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; -@SuppressWarnings({"AccessStaticViaInstance", "ConstantConditions"}) -public class TemplateUtilTest { +@SuppressWarnings({"AccessStaticViaInstance", "ConstantConditions", "unused"}) +class TemplateUtilTest { - @SuppressWarnings("unused") @Mocked private FileUtils fileUtils; private KubernetesListBuilder klb; - @Before - public void initGlobalVariables() { + @BeforeEach + void initGlobalVariables() { klb = new KubernetesListBuilder(); } @Test - public void getSingletonTemplateWithNullShouldReturnNull() { + void getSingletonTemplateWithNullShouldReturnNull() { assertThat(getSingletonTemplate(null)).isNull(); } @Test - public void getSingletonTemplateWithMultipleItemsShouldReturnNull() { + void getSingletonTemplateWithMultipleItemsShouldReturnNull() { // Given klb.addToItems(new Template(), new Template()); // When - Then @@ -61,7 +60,7 @@ public void getSingletonTemplateWithMultipleItemsShouldReturnNull() { } @Test - public void getSingletonTemplateWithSingleItemsShouldReturnTemplate() { + void getSingletonTemplateWithSingleItemsShouldReturnTemplate() { // Given klb.addToItems(new TemplateBuilder().withNewMetadata().withName("template").endMetadata().build()); // When - Then @@ -70,7 +69,7 @@ public void getSingletonTemplateWithSingleItemsShouldReturnTemplate() { } @Test - public void interpolateTemplateVariablesWithNoParametersShouldDoNothing() throws IOException { + void interpolateTemplateVariablesWithNoParametersShouldDoNothing() throws IOException { // When interpolateTemplateVariables(klb.build(), null); // Then @@ -78,7 +77,7 @@ public void interpolateTemplateVariablesWithNoParametersShouldDoNothing() throws } @Test - public void interpolateTemplateVariablesWithParametersAndNoPlaceholdersShouldDoNothing() throws IOException { + void interpolateTemplateVariablesWithParametersAndNoPlaceholdersShouldDoNothing() throws IOException { // Given klb.addToItems(new TemplateBuilder() .addToParameters(new ParameterBuilder().withName("param1").withValue("value1").build()) @@ -91,7 +90,7 @@ public void interpolateTemplateVariablesWithParametersAndNoPlaceholdersShouldDoN } @Test - public void interpolateTemplateVariablesWithParametersAndPlaceholdersShouldReplace() throws IOException { + void interpolateTemplateVariablesWithParametersAndPlaceholdersShouldReplace() throws IOException { // Given klb.addToItems(new TemplateBuilder() .addToParameters(new ParameterBuilder().withName("param1").withValue("value1").build()) @@ -104,7 +103,7 @@ public void interpolateTemplateVariablesWithParametersAndPlaceholdersShouldRepla } @Test - public void interpolateTemplateVariablesWithReadFileException() throws IOException { + void interpolateTemplateVariablesWithReadFileException() throws IOException { // Given klb.addToItems(new TemplateBuilder() .addToParameters(new ParameterBuilder().withName("param1").withValue("value1").build()) @@ -122,7 +121,7 @@ public void interpolateTemplateVariablesWithReadFileException() throws IOExcepti } @Test - public void interpolateTemplateVariablesWithWriteFileException() throws IOException { + void interpolateTemplateVariablesWithWriteFileException() throws IOException { // Given klb.addToItems(new TemplateBuilder() .addToParameters(new ParameterBuilder().withName("param1").withValue("value1").build()) diff --git a/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/WriteUtilTest.java b/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/WriteUtilTest.java index 2d912b526c..52fb390ffc 100644 --- a/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/WriteUtilTest.java +++ b/jkube-kit/resource/service/src/test/java/org/eclipse/jkube/kit/resource/service/WriteUtilTest.java @@ -27,40 +27,36 @@ import mockit.Expectations; import mockit.Mocked; import mockit.Verifications; -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 static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; -@SuppressWarnings({"ConstantConditions", "AccessStaticViaInstance"}) -public class WriteUtilTest { +@SuppressWarnings({"ConstantConditions", "AccessStaticViaInstance", "unused"}) +class WriteUtilTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @SuppressWarnings("unused") + @TempDir + File temporaryFolder; @Mocked private KitLogger log; - @SuppressWarnings("unused") @Mocked private ResourceUtil resourceUtil; private KubernetesListBuilder klb; private File resourceFileBase; - @Before - public void initGlobalVariables() throws IOException { + @BeforeEach + void initGlobalVariables() { klb = new KubernetesListBuilder(); - resourceFileBase = temporaryFolder.newFolder(); + resourceFileBase = temporaryFolder; } @Test - public void writeResource() throws IOException { + void writeResource() throws IOException { // Given - final File baton = temporaryFolder.newFile(); + final File baton = File.createTempFile("junit", "ext", temporaryFolder); mockResourceUtilSave(baton); // When final File result = WriteUtil.writeResource(null, null, null); @@ -69,9 +65,9 @@ public void writeResource() throws IOException { } @Test - public void writeResourceThrowsException() throws IOException { + void writeResourceThrowsException() throws IOException { // Given - final File resource = temporaryFolder.newFolder("resource-base"); + final File resource = new File(temporaryFolder, "resource-base"); mockResourceUtilSave(new IOException("Message")); // When final IOException result = assertThrows(IOException.class, @@ -85,7 +81,7 @@ public void writeResourceThrowsException() throws IOException { } @Test - public void writeResourcesIndividualAndCompositeWithNoResourcesShouldOnlyWriteComposite() throws IOException { + void writeResourcesIndividualAndCompositeWithNoResourcesShouldOnlyWriteComposite() throws IOException { // When WriteUtil.writeResourcesIndividualAndComposite(klb.build(), resourceFileBase, null, log); // Then @@ -93,7 +89,7 @@ public void writeResourcesIndividualAndCompositeWithNoResourcesShouldOnlyWriteCo } @Test - public void writeResourcesIndividualAndCompositeWithResourcesShouldWriteAll() throws IOException { + void writeResourcesIndividualAndCompositeWithResourcesShouldWriteAll() throws IOException { // Given klb.addToItems( new ConfigMapBuilder().withNewMetadata().withName("cm-1").endMetadata().build(), @@ -110,7 +106,7 @@ public void writeResourcesIndividualAndCompositeWithResourcesShouldWriteAll() th } @Test - public void writeResourcesIndividualAndComposite_withResourcesWithSameName_shouldWriteAll() throws IOException { + void writeResourcesIndividualAndComposite_withResourcesWithSameName_shouldWriteAll() throws IOException { // Given klb.addToItems( new ConfigMapBuilder().withNewMetadata().withNamespace("default").withName("cm-1").endMetadata().build(),