You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2024/06/21 19:03:38 UTC
(sling-slingfeature-maven-plugin) branch issue/SLING-12355 created (now a145692)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch issue/SLING-12355
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
at a145692 SLING-12355 - Use the TemporaryFolder JUnit rule instead of manually managing temp directories
This branch includes the following new commits:
new a145692 SLING-12355 - Use the TemporaryFolder JUnit rule instead of manually managing temp directories
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(sling-slingfeature-maven-plugin) 01/01: SLING-12355 - Use the TemporaryFolder JUnit rule instead of manually managing temp directories
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch issue/SLING-12355
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
commit a1456921358cd5fd45b17dc55180d4c76a83816a
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Jun 21 14:49:48 2024 +0200
SLING-12355 - Use the TemporaryFolder JUnit rule instead of manually managing temp directories
---
.../maven/mojos/AggregateFeaturesMojoTest.java | 20 +++++-------
.../maven/mojos/ExtractExtensionsMojoTest.java | 37 ++++++++++------------
.../maven/mojos/FeatureLauncherMojoTest.java | 15 +++------
3 files changed, 29 insertions(+), 43 deletions(-)
diff --git a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
index 095e74a..3f916f1 100644
--- a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
@@ -26,12 +26,10 @@ import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
@@ -60,31 +58,29 @@ import org.apache.sling.feature.io.json.FeatureJSONReader;
import org.apache.sling.feature.maven.FeatureConstants;
import org.apache.sling.feature.maven.Preprocessor;
import org.eclipse.aether.RepositorySystem;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
public class AggregateFeaturesMojoTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
private Path tempDir;
+
private static Map<String, ArtifactId> pluginCallbacks;
public static final String FEATURE_PROCESSED_LOCATION = "/features/processed";
@Before
public void setup() throws Exception {
- tempDir = Files.createTempDirectory(getClass().getSimpleName());
pluginCallbacks = new HashMap<>();
+ tempDir = folder.newFolder().toPath();
}
- @After
- public void tearDown() throws Exception {
- // Delete the temp dir again
- Files.walk(tempDir)
- .sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
- }
public static void addPluginCallback(String plugin, ArtifactId artifactId) {
pluginCallbacks.put(plugin, artifactId);
diff --git a/src/test/java/org/apache/sling/feature/maven/mojos/ExtractExtensionsMojoTest.java b/src/test/java/org/apache/sling/feature/maven/mojos/ExtractExtensionsMojoTest.java
index 03fc57f..aca4f67 100644
--- a/src/test/java/org/apache/sling/feature/maven/mojos/ExtractExtensionsMojoTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/ExtractExtensionsMojoTest.java
@@ -16,6 +16,14 @@
*/
package org.apache.sling.feature.maven.mojos;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.maven.project.MavenProject;
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
@@ -24,34 +32,21 @@ import org.apache.sling.feature.ExtensionState;
import org.apache.sling.feature.ExtensionType;
import org.apache.sling.feature.Feature;
import org.apache.sling.feature.maven.Preprocessor;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
-
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
+import org.junit.rules.TemporaryFolder;
public class ExtractExtensionsMojoTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
private Path tempDir;
@Before
- public void setup() throws Exception {
- tempDir = Files.createTempDirectory(getClass().getSimpleName());
- }
-
- @After
- public void tearDown() throws Exception {
- // Delete the temp dir again
- Files.walk(tempDir)
- .sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
+ public void prepare() {
+ tempDir = folder.getRoot().toPath();
}
@Test
diff --git a/src/test/java/org/apache/sling/feature/maven/mojos/FeatureLauncherMojoTest.java b/src/test/java/org/apache/sling/feature/maven/mojos/FeatureLauncherMojoTest.java
index 899a6bd..9543649 100644
--- a/src/test/java/org/apache/sling/feature/maven/mojos/FeatureLauncherMojoTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/FeatureLauncherMojoTest.java
@@ -31,11 +31,9 @@ import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -50,9 +48,10 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.sling.feature.Feature;
import org.apache.sling.feature.io.json.FeatureJSONReader;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -61,18 +60,14 @@ public class FeatureLauncherMojoTest {
private static final String ASSEMBLED_FEATURE_JSON = Feature.class.getName() + "/assembledmain.json";
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
private FeatureLauncherMojo mojo = spy(new FeatureLauncherMojo());
private Path tempDir;
@Before
public void setup() throws IOException {
- tempDir = Files.createTempDirectory(getClass().getSimpleName());
- }
-
- @After
- public void tearDown() throws Exception {
- // Delete the temp dir again
- Files.walk(tempDir).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ tempDir = folder.newFolder().toPath();
}
@Test