From dce786df4301dab6d51d1eab6bbb79e510327086 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 23 Dec 2023 01:24:43 +0100 Subject: [PATCH] [MSHARED-1341] Convert tests to Junit 5 --- pom.xml | 14 ++- ...nterpolatorFilterReaderLineEndingTest.java | 16 +-- .../AbstractMavenFilteringRequestTest.java | 20 ++-- .../shared/filtering/BoundedReaderTest.java | 16 +-- .../filtering/DefaultMavenFileFilterTest.java | 49 +++++---- .../DefaultMavenReaderFilterTest.java | 15 ++- .../DefaultMavenResourcesFilteringTest.java | 102 +++++++++++------- .../shared/filtering/EscapeStringTest.java | 23 ++-- .../shared/filtering/FilteringUtilsTest.java | 30 +++--- .../IncrementalResourceFilteringTest.java | 44 +++++--- .../shared/filtering/InvalidMarkTest.java | 31 ++++-- .../MuliLinesMavenResourcesFilteringTest.java | 23 ++-- ...nterpolatorFilterReaderLineEndingTest.java | 15 ++- .../shared/filtering/PropertyUtilsTest.java | 33 ++++-- .../filtering/TestReflectionProperties.java | 21 +++- .../maven/shared/filtering/TestSupport.java | 33 ------ 16 files changed, 288 insertions(+), 197 deletions(-) delete mode 100644 src/test/java/org/apache/maven/shared/filtering/TestSupport.java diff --git a/pom.xml b/pom.xml index ba85deaa..55306662 100644 --- a/pom.xml +++ b/pom.xml @@ -125,13 +125,13 @@ org.mockito mockito-core - 4.7.0 + 4.11.0 test - junit - junit - 4.13.2 + org.codehaus.plexus + plexus-testing + 1.2.0 test @@ -140,6 +140,12 @@ 2.2 test + + org.junit.jupiter + junit-jupiter-api + 5.10.1 + test + org.slf4j slf4j-simple diff --git a/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java b/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java index 35ba64c6..e0cbf565 100644 --- a/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java @@ -25,12 +25,12 @@ import org.apache.commons.io.IOUtils; import org.codehaus.plexus.interpolation.Interpolator; import org.codehaus.plexus.interpolation.RecursionInterceptor; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.when; @@ -40,13 +40,13 @@ public abstract class AbstractInterpolatorFilterReaderLineEndingTest { @Mock private Interpolator interpolator; - @Before + @BeforeEach public void onSetup() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test - public void testDefaults() throws Exception { + void defaults() throws Exception { when(interpolator.interpolate(eq("${a}"), eq(""), isA(RecursionInterceptor.class))) .thenReturn("DONE_A"); @@ -89,7 +89,7 @@ public void testDefaults() throws Exception { // MSHARED-198: custom delimiters doesn't work as expected @Test - public void testCustomDelimiters() throws Exception { + void customDelimiters() throws Exception { when(interpolator.interpolate(eq("aaaFILTER.a.MEaaa"), eq(""), isA(RecursionInterceptor.class))) .thenReturn("DONE"); when(interpolator.interpolate(eq("abcFILTER.a.MEabc"), eq(""), isA(RecursionInterceptor.class))) @@ -107,7 +107,7 @@ public void testCustomDelimiters() throws Exception { // MSHARED-235: reader exceeds readAheadLimit @Test - public void testMarkInvalid() throws IOException { + void markInvalid() throws IOException { try (Reader reader = getAtReader(new StringReader("@\").replace(p,\"]\").replace(q,\""), interpolator, "\\")) { assertEquals("@\").replace(p,\"]\").replace(q,\"", IOUtils.toString(reader)); } diff --git a/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java b/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java index 9aa8d701..5c91afbb 100644 --- a/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java @@ -21,39 +21,39 @@ import java.util.LinkedHashSet; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; /** * @author Karl Heinz Marbaise khmarbaise@apache.org. */ -public class AbstractMavenFilteringRequestTest { +class AbstractMavenFilteringRequestTest { private AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest(); private LinkedHashSet delimiters = new LinkedHashSet<>(); @Test - public void setDelimitersShouldNotChangeAnythingIfUsingNull() { + void setDelimitersShouldNotChangeAnythingIfUsingNull() { request.setDelimiters(null, false); assertThat(request.getDelimiters(), Matchers.contains("${*}", "@")); } @Test - public void setDelimitersShouldNotChangeAnythingIfUsingEmpty() { + void setDelimitersShouldNotChangeAnythingIfUsingEmpty() { request.setDelimiters(delimiters, false); assertThat(request.getDelimiters(), Matchers.contains("${*}", "@")); } @Test - public void setDelimitersShouldAddOnlyTheGivenDelimiter() { + void setDelimitersShouldAddOnlyTheGivenDelimiter() { delimiters.add("test"); request.setDelimiters(delimiters, false); assertThat(request.getDelimiters(), Matchers.contains("test")); } @Test - public void setDelimitersShouldAddDefaultDelimitersForNullElements() { + void setDelimitersShouldAddDefaultDelimitersForNullElements() { delimiters.add("test"); delimiters.add(null); delimiters.add("second"); @@ -62,27 +62,27 @@ public void setDelimitersShouldAddDefaultDelimitersForNullElements() { } @Test - public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNullGiven() { + void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNullGiven() { request.setDelimiters(null, true); assertThat(request.getDelimiters(), Matchers.contains("${*}", "@")); } @Test - public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNotNullGiven() { + void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNotNullGiven() { LinkedHashSet delimiters = new LinkedHashSet<>(); request.setDelimiters(delimiters, true); assertThat(request.getDelimiters(), Matchers.contains("${*}", "@")); } @Test - public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfSingleElementIsGiven() { + void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfSingleElementIsGiven() { delimiters.add("test"); request.setDelimiters(delimiters, true); assertThat(request.getDelimiters(), Matchers.contains("${*}", "@", "test")); } @Test - public void setDelimitersShouldAddDefaultDelimitersForNullElement() { + void setDelimitersShouldAddDefaultDelimitersForNullElement() { delimiters.add("test"); delimiters.add(null); delimiters.add("second"); diff --git a/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java b/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java index 58ac3725..3819a22c 100644 --- a/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java @@ -23,16 +23,16 @@ import java.io.Reader; import java.io.StringReader; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class BoundedReaderTest { +class BoundedReaderTest { private final Reader sr = new BufferedReader(new StringReader("01234567890")); @Test - public void readTillEnd() throws IOException { + void readTillEnd() throws IOException { try (BoundedReader mr = new BoundedReader(sr, 3)) { mr.mark(3); mr.read(); @@ -43,7 +43,7 @@ public void readTillEnd() throws IOException { } @Test - public void readMulti() throws IOException { + void readMulti() throws IOException { char[] cbuf = new char[4]; for (int i = 0; i < cbuf.length; i++) { cbuf[i] = 'X'; @@ -61,7 +61,7 @@ public void readMulti() throws IOException { } @Test - public void readMultiWithOffset() throws IOException { + void readMultiWithOffset() throws IOException { char[] cbuf = new char[4]; for (int i = 0; i < cbuf.length; i++) { @@ -80,7 +80,7 @@ public void readMultiWithOffset() throws IOException { } @Test - public void resetWorks() throws IOException { + void resetWorks() throws IOException { try (BoundedReader mr = new BoundedReader(sr, 3)) { mr.read(); mr.read(); @@ -94,7 +94,7 @@ public void resetWorks() throws IOException { } @Test - public void skipTest() throws IOException { + void skipTest() throws IOException { try (BoundedReader mr = new BoundedReader(sr, 3)) { mr.skip(2); mr.read(); diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java index 82bf131f..b0ca05a5 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java @@ -18,6 +18,8 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; import java.io.Reader; import java.io.StringReader; @@ -31,27 +33,34 @@ import org.apache.commons.io.IOUtils; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.sonatype.plexus.build.incremental.BuildContext; +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; /** * @author Olivier Lamy * */ -public class DefaultMavenFileFilterTest extends TestSupport { +@PlexusTest +class DefaultMavenFileFilterTest { + + @Inject + MavenFileFilter mavenFileFilter; File to = new File(getBasedir(), "target/reflection-test.properties"); - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { Files.deleteIfExists(to.toPath()); } - public void testOverwriteFile() throws Exception { - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); - + @Test + void overwriteFile() throws Exception { File from = new File(getBasedir(), "src/test/units-files/reflection-test.properties"); mavenFileFilter.copyFile(from, to, false, null, null); @@ -69,15 +78,14 @@ public void testOverwriteFile() throws Exception { assertEquals("older file", properties.getProperty("version")); } - public void testNullSafeDefaultFilterWrappers() throws Exception { - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); - + @Test + void nullSafeDefaultFilterWrappers() throws Exception { mavenFileFilter.getDefaultFilterWrappers(null, null, false, null, null); - // shouldn't fail } - public void testMultiFilterFileInheritance() throws Exception { + @Test + void multiFilterFileInheritance() throws Exception { DefaultMavenFileFilter mavenFileFilter = new DefaultMavenFileFilter(mock(BuildContext.class)); File testDir = new File(getBasedir(), "src/test/units-files/MSHARED-177"); @@ -92,14 +100,13 @@ public void testMultiFilterFileInheritance() throws Exception { mavenFileFilter.loadProperties(filterProperties, new File(getBasedir()), filters, new Properties()); - assertTrue(filterProperties.getProperty("third_filter_key").equals("first and second")); + assertEquals("first and second", filterProperties.getProperty("third_filter_key")); } // MSHARED-161: DefaultMavenFileFilter.getDefaultFilterWrappers loads // filters from the current directory instead of using basedir - public void testMavenBasedir() throws Exception { - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); - + @Test + void mavenBasedir() throws Exception { AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest(); req.setFileFilters(Collections.singletonList("src/main/filters/filefilter.properties")); @@ -116,9 +123,8 @@ public void testMavenBasedir() throws Exception { } // MSHARED-198: custom delimiters doesn't work as expected - public void testCustomDelimiters() throws Exception { - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); - + @Test + void customDelimiters() throws Exception { AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest(); Properties additionalProperties = new Properties(); additionalProperties.setProperty("FILTER.a.ME", "DONE"); @@ -135,9 +141,8 @@ public void testCustomDelimiters() throws Exception { } // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open - public void testLineWithSingleAtAndExpression() throws Exception { - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); - + @Test + void lineWithSingleAtAndExpression() throws Exception { AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest(); Properties additionalProperties = new Properties(); additionalProperties.setProperty("foo", "bar"); diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java index 7788288e..6fe3556b 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java @@ -18,19 +18,28 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.Reader; import java.io.StringReader; import java.util.Properties; import org.apache.commons.io.IOUtils; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Kristian Rosenvold */ -public class DefaultMavenReaderFilterTest extends TestSupport { - public void testJustDoSomeFiltering() throws Exception { - MavenReaderFilter readerFilter = lookup(MavenReaderFilter.class); +@PlexusTest +class DefaultMavenReaderFilterTest { + @Inject + MavenReaderFilter readerFilter; + @Test + void justDoSomeFiltering() throws Exception { StringReader src = new StringReader("toto@titi.com ${foo}"); MavenReaderFilterRequest req = new MavenReaderFilterRequest(); Properties additionalProperties = new Properties(); diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java index b6374e14..f2d1a481 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java @@ -18,6 +18,8 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -34,22 +36,35 @@ import org.apache.maven.settings.Settings; import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; import org.codehaus.plexus.interpolation.ValueSource; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Olivier Lamy * * @since 1.0-beta-1 */ -public class DefaultMavenResourcesFilteringTest extends TestSupport { +@PlexusTest +class DefaultMavenResourcesFilteringTest { private File outputDirectory = new File(getBasedir(), "target/DefaultMavenResourcesFilteringTest"); private File baseDir = new File(getBasedir()); private StubMavenProject mavenProject = new StubMavenProject(baseDir); + + @Inject private MavenResourcesFiltering mavenResourcesFiltering; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { if (outputDirectory.exists()) { FileUtils.deleteDirectory(outputDirectory); } @@ -58,11 +73,10 @@ protected void setUp() throws Exception { mavenProject.setVersion("1.0"); mavenProject.setGroupId("org.apache"); mavenProject.setName("test project"); - - mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); } - public void testSimpleFiltering() throws Exception { + @Test + void simpleFiltering() throws Exception { Properties projectProperties = new Properties(); projectProperties.put("foo", "bar"); projectProperties.put("java.version", "zloug"); @@ -97,7 +111,8 @@ public void testSimpleFiltering() throws Exception { assertFiltering(initialImageFile, false, false); } - public void testSessionFiltering() throws Exception { + @Test + void sessionFiltering() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/session-filtering"; @@ -138,7 +153,8 @@ public void testSessionFiltering() throws Exception { assertEquals(settings.getLocalRepository(), result.getProperty("local.repo")); } - public void testWithMavenResourcesExecution() throws Exception { + @Test + void withMavenResourcesExecution() throws Exception { Properties projectProperties = new Properties(); projectProperties.put("foo", "bar"); projectProperties.put("java.version", "zloug"); @@ -171,7 +187,8 @@ public void testWithMavenResourcesExecution() throws Exception { assertFiltering(initialImageFile, true, false); } - public void testWithMavenResourcesExecutionWithAdditionalProperties() throws Exception { + @Test + void withMavenResourcesExecutionWithAdditionalProperties() throws Exception { Properties projectProperties = new Properties(); projectProperties.put("foo", "bar"); projectProperties.put("java.version", "zloug"); @@ -248,7 +265,7 @@ private void assertFiltering(File initialImageFile, boolean escapeTest, boolean String userHome = result.getProperty("userHome"); - assertTrue("'" + userHome + "' does not exist.", new File(userHome).exists()); + assertTrue(new File(userHome).exists(), "'" + userHome + "' does not exist."); assertEquals(new File(System.getProperty("user.home")), new File(userHome)); if (escapeTest) { @@ -264,7 +281,8 @@ private void assertFiltering(File initialImageFile, boolean escapeTest, boolean assertTrue(filesAreIdentical(initialImageFile, imageFile)); } - public void testAddingTokens() throws Exception { + @Test + void addingTokens() throws Exception { Properties projectProperties = new Properties(); projectProperties.put("foo", "bar"); projectProperties.put("java.version", "zloug"); @@ -307,7 +325,8 @@ public void testAddingTokens() throws Exception { assertFiltering(initialImageFile, false, false); } - public void testNoFiltering() throws Exception { + @Test + void noFiltering() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; File initialImageFile = new File(unitFilesDir, "happy_duke.gif"); @@ -365,7 +384,8 @@ private static boolean filesAreIdentical(File expected, File current) throws IOE return true; } - public void testIncludeOneFile() throws Exception { + @Test + void includeOneFile() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; @@ -395,7 +415,8 @@ public void testIncludeOneFile() throws Exception { assertEquals("includefile.txt", files[0].getName()); } - public void testIncludeOneFileAndDirectory() throws Exception { + @Test + void includeOneFileAndDirectory() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; Resource resource = new Resource(); @@ -430,15 +451,14 @@ public void testIncludeOneFileAndDirectory() throws Exception { assertTrue(includeFile.exists()); } - public void testFlattenDirectoryStructure() throws Exception { + @Test + void flattenDirectoryStructure() throws Exception { File baseDir = new File(getBasedir()); StubMavenProject mavenProject = new StubMavenProject(baseDir); mavenProject.setVersion("1.0"); mavenProject.setGroupId("org.apache"); mavenProject.setName("test project"); - MavenResourcesFiltering mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); - String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; Resource resource = new Resource(); @@ -475,15 +495,14 @@ public void testFlattenDirectoryStructure() throws Exception { assertTrue(includeFile.exists()); } - public void testFlattenDirectoryStructureWithoutOverride() throws Exception { + @Test + void flattenDirectoryStructureWithoutOverride() throws Exception { File baseDir = new File(getBasedir()); StubMavenProject mavenProject = new StubMavenProject(baseDir); mavenProject.setVersion("1.0"); mavenProject.setGroupId("org.apache"); mavenProject.setName("test project"); - MavenResourcesFiltering mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); - String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; Resource resource = new Resource(); @@ -516,7 +535,8 @@ public void testFlattenDirectoryStructureWithoutOverride() throws Exception { fail("Copying directory structure with duplicate filename includefile.txt should have failed with overwrite"); } - public void testExcludeOneFile() throws Exception { + @Test + void excludeOneFile() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; @@ -557,7 +577,8 @@ public void testExcludeOneFile() throws Exception { assertFalse(excludeDir.exists()); } - public void testTargetAbsolutePath() throws Exception { + @Test + void targetAbsolutePath() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; @@ -596,7 +617,8 @@ public void testTargetAbsolutePath() throws Exception { assertEquals("includefile.txt", files[0].getName()); } - public void testTargetPath() throws Exception { + @Test + void targetPath() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-resources-filtering"; @@ -629,7 +651,8 @@ public void testTargetPath() throws Exception { } @SuppressWarnings("serial") - public void testEmptyDirectories() throws Exception { + @Test + void emptyDirectories() throws Exception { List resources = new ArrayList<>(); resources.add(new Resource() { @@ -676,7 +699,8 @@ public void testEmptyDirectories() throws Exception { } @SuppressWarnings("serial") - public void testShouldReturnGitIgnoreFiles() throws Exception { + @Test + void shouldReturnGitIgnoreFiles() throws Exception { createTestDataStructure(); File outputDirectory = new File(getBasedir(), "/target/testGitIgnoreFile"); @@ -763,7 +787,8 @@ private static void createTestDataStructure() throws IOException { * unit test for MSHARED-81 : https://issues.apache.org/jira/browse/MSHARED-81 */ @SuppressWarnings("serial") - public void testMSHARED81() throws Exception { + @Test + void mSHARED81() throws Exception { mavenProject.addProperty("escaped", "this is escaped"); mavenProject.addProperty("escaped.at", "this is escaped.at"); mavenProject.addProperty("foo", "this is foo"); @@ -808,7 +833,7 @@ public void testMSHARED81() throws Exception { Properties expectedNonFilteredResult = PropertyUtils.loadPropertyFile( new File(getBasedir() + "/src/test/units-files/MSHARED-81/resources", "unfiltered.properties"), null); - assertTrue(nonFilteredResult.equals(expectedNonFilteredResult)); + assertEquals(nonFilteredResult, expectedNonFilteredResult); } /** @@ -853,7 +878,8 @@ public void testMSHARED81() throws Exception { * unit test for edge cases : https://issues.apache.org/jira/browse/MSHARED-228 */ @SuppressWarnings("serial") - public void testEdgeCases() throws Exception { + @Test + void edgeCases() throws Exception { mavenProject.addProperty("escaped", "this is escaped"); mavenProject.addProperty("escaped.at", "this is escaped.at"); mavenProject.addProperty("foo", "this is foo"); @@ -902,11 +928,12 @@ public void testEdgeCases() throws Exception { Properties expectedNonFilteredResult = PropertyUtils.loadPropertyFile( new File(getBasedir() + "/src/test/units-files/edge-cases/resources", "unfiltered.properties"), null); - assertTrue(nonFilteredResult.equals(expectedNonFilteredResult)); + assertEquals(nonFilteredResult, expectedNonFilteredResult); } // MSHARED-220: Apply filtering to filenames - public void testFilterFileName() throws Exception { + @Test + void filterFileName() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/maven-filename-filtering"; @@ -937,7 +964,8 @@ public void testFilterFileName() throws Exception { /** * MRESOURCES-171: Use correct encoding when filtering properties-files */ - public void testFilterPropertiesFiles() throws Exception { + @Test + void filterPropertiesFiles() throws Exception { String unitFilesDir = getBasedir() + "/src/test/units-files/MRESOURCES-171"; @@ -963,21 +991,23 @@ public void testFilterPropertiesFiles() throws Exception { assertTrue(FileUtils.contentEquals(new File(unitFilesDir, "test.txt"), new File(targetPathFile, "test.txt"))); } - public void testGetEncoding() { + @Test + void getEncoding() { File propertiesFile = new File("file.properties"); File regularFile = new File("file.xml"); // Properties files - assertEquals(null, DefaultMavenResourcesFiltering.getEncoding(propertiesFile, null, null)); + assertNull(DefaultMavenResourcesFiltering.getEncoding(propertiesFile, null, null)); assertEquals("UTF-8", DefaultMavenResourcesFiltering.getEncoding(propertiesFile, "UTF-8", null)); assertEquals("ISO-8859-1", DefaultMavenResourcesFiltering.getEncoding(propertiesFile, "UTF-8", "ISO-8859-1")); // Regular files - assertEquals(null, DefaultMavenResourcesFiltering.getEncoding(regularFile, null, null)); + assertNull(DefaultMavenResourcesFiltering.getEncoding(regularFile, null, null)); assertEquals("UTF-8", DefaultMavenResourcesFiltering.getEncoding(regularFile, "UTF-8", null)); assertEquals("UTF-8", DefaultMavenResourcesFiltering.getEncoding(regularFile, "UTF-8", "ISO-8859-1")); } - public void testIsPropertiesFile() { + @Test + void isPropertiesFile() { // Properties files assertTrue(DefaultMavenResourcesFiltering.isPropertiesFile(new File("file.properties"))); assertTrue(DefaultMavenResourcesFiltering.isPropertiesFile(new File("some/parent/path", "file.properties"))); diff --git a/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java b/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java index e3dd1e6b..768baba9 100644 --- a/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java @@ -18,6 +18,8 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -27,26 +29,36 @@ import org.apache.commons.io.FileUtils; import org.apache.maven.model.Resource; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Olivier Lamy */ -public class EscapeStringTest extends TestSupport { +@PlexusTest +class EscapeStringTest { + + @Inject + MavenResourcesFiltering mavenResourcesFiltering; File outputDirectory = new File(getBasedir(), "target/EscapeStringTest"); File unitDirectory = new File(getBasedir(), "src/test/units-files/escape-remove-char"); - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { if (outputDirectory.exists()) { FileUtils.deleteDirectory(outputDirectory); } outputDirectory.mkdirs(); } - public void testEscape() throws Exception { + @Test + void escape() throws Exception { File baseDir = new File(getBasedir()); StubMavenProject mavenProject = new StubMavenProject(baseDir); mavenProject.setVersion("1.0"); @@ -58,7 +70,6 @@ public void testEscape() throws Exception { projectProperties.put("java.version", "zloug"); projectProperties.put("replaceThis", "I am the replacement"); mavenProject.setProperties(projectProperties); - MavenResourcesFiltering mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); Resource resource = new Resource(); List resources = new ArrayList<>(); diff --git a/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java index 6893d42e..d6a64a72 100644 --- a/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java @@ -25,10 +25,11 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; -import org.junit.Assert; -import org.junit.Test; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author John Casey @@ -36,11 +37,12 @@ * @since 1.0 * */ -public class FilteringUtilsTest extends TestSupport { +@PlexusTest +class FilteringUtilsTest { private static File testDirectory = new File(getBasedir(), "target/test-classes/"); @Test - public void testMSHARED1213CopyWithTargetAlreadyExisting0ByteFile() throws IOException { + void mSHARED1213CopyWithTargetAlreadyExisting0ByteFile() throws IOException { File fromFile = new File(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml"); File toFile = new File(testDirectory, "MSHARED-1213-enunciate.xml"); Files.write(toFile.toPath(), "".getBytes(StandardCharsets.UTF_8)); @@ -57,13 +59,13 @@ public Reader getReader(Reader fileReader) { } }, false); - Assert.assertEquals( + assertEquals( Files.readAllLines(fromFile.toPath(), StandardCharsets.UTF_8), Files.readAllLines(toFile.toPath(), StandardCharsets.UTF_8)); } @Test - public void testMSHARED1213CopyWithTargetAlreadyExistingJunkFile() throws IOException { + void mSHARED1213CopyWithTargetAlreadyExistingJunkFile() throws IOException { File fromFile = new File(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml"); File toFile = new File(testDirectory, "MSHARED-1213-enunciate.xml"); Files.write(toFile.toPath(), "junk".getBytes(StandardCharsets.UTF_8)); @@ -80,13 +82,13 @@ public Reader getReader(Reader fileReader) { } }, false); - Assert.assertEquals( + assertEquals( Files.readAllLines(fromFile.toPath(), StandardCharsets.UTF_8), Files.readAllLines(toFile.toPath(), StandardCharsets.UTF_8)); } @Test - public void testMSHARED1213CopyWithTargetAlreadyExistingSameFile() throws IOException { + void mSHARED1213CopyWithTargetAlreadyExistingSameFile() throws IOException { File fromFile = new File(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml"); File toFile = new File(testDirectory, "MSHARED-1213-enunciate.xml"); Files.copy(fromFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -103,23 +105,23 @@ public Reader getReader(Reader fileReader) { } }, false); - Assert.assertEquals( + assertEquals( Files.readAllLines(fromFile.toPath(), StandardCharsets.UTF_8), Files.readAllLines(toFile.toPath(), StandardCharsets.UTF_8)); } @Test - public void testEscapeWindowsPathStartingWithDrive() { + void escapeWindowsPathStartingWithDrive() { assertEquals("C:\\\\Users\\\\Administrator", FilteringUtils.escapeWindowsPath("C:\\Users\\Administrator")); } @Test - public void testEscapeWindowsPathMissingDriveLetter() { + void escapeWindowsPathMissingDriveLetter() { assertEquals(":\\Users\\Administrator", FilteringUtils.escapeWindowsPath(":\\Users\\Administrator")); } @Test - public void testEscapeWindowsPathInvalidDriveLetter() { + void escapeWindowsPathInvalidDriveLetter() { assertEquals("4:\\Users\\Administrator", FilteringUtils.escapeWindowsPath("4:\\Users\\Administrator")); } @@ -141,7 +143,7 @@ public void testEscapeWindowsPathInvalidDriveLetter() { // MSHARED-179 @Test - public void testEscapeWindowsPathNotAtBeginning() throws Exception { + void escapeWindowsPathNotAtBeginning() throws Exception { assertEquals( "jdbc:derby:C:\\\\Users\\\\Administrator/test;create=true", FilteringUtils.escapeWindowsPath("jdbc:derby:C:\\Users\\Administrator/test;create=true")); diff --git a/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java index 5a665534..ed3b91e5 100644 --- a/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java @@ -18,10 +18,12 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -32,9 +34,21 @@ import org.apache.commons.io.FileUtils; import org.apache.maven.model.Resource; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.sonatype.plexus.build.incremental.ThreadBuildContext; -public class IncrementalResourceFilteringTest extends TestSupport { +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@PlexusTest +class IncrementalResourceFilteringTest { + + @Inject + MavenResourcesFiltering mavenResourcesFiltering; Path baseDirectory = new File(getBasedir()).toPath(); Path outputDirectory = baseDirectory.resolve("target/IncrementalResourceFilteringTest"); @@ -45,16 +59,16 @@ public class IncrementalResourceFilteringTest extends TestSupport { Path outputFile01 = outputDirectory.resolve("file01.txt"); Path outputFile02 = outputDirectory.resolve("file02.txt"); - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { if (outputDirectory.toFile().exists()) { FileUtils.deleteDirectory(outputDirectory.toFile()); } outputDirectory.toFile().mkdirs(); } - public void testSimpleIncrementalFiltering() throws Exception { + @Test + void simpleIncrementalFiltering() throws Exception { // run full build first filter("time"); @@ -88,7 +102,8 @@ public void testSimpleIncrementalFiltering() throws Exception { assertTrue(ctx.getRefreshFiles().contains(outputFile01)); } - public void testOutputChange() throws Exception { + @Test + void outputChange() throws Exception { // run full build first filter("time"); @@ -106,7 +121,8 @@ public void testOutputChange() throws Exception { assertTrue(ctx.getRefreshFiles().contains(outputFile02)); } - public void testFilterChange() throws Exception { + @Test + void filterChange() throws Exception { // run full build first filter("time"); @@ -127,7 +143,8 @@ public void testFilterChange() throws Exception { /** * Check that missing targets are rebuilt even if source is not changed (MSHARED-1285) */ - public void testMissingTarget() throws Exception { + @Test + void missingTarget() throws Exception { // run full build first filter("time"); @@ -151,7 +168,8 @@ public void testMissingTarget() throws Exception { /** * Check that updated targets with unchanged sources are updated (MSHARED-1285) */ - public void testUpdatedTarget() throws Exception { + @Test + void updatedTarget() throws Exception { // run full build first filter("time"); @@ -173,7 +191,8 @@ public void testUpdatedTarget() throws Exception { assertTrue(ctx.getRefreshFiles().contains(outputFile02)); } - public void testFilterDeleted() throws Exception { + @Test + void filterDeleted() throws Exception { // run full build first filter("time"); @@ -195,7 +214,7 @@ private void assertTime(String time, String relpath) throws IOException { Properties properties = new Properties(); try (InputStream is = - new FileInputStream(outputDirectory.resolve(relpath).toFile())) { + Files.newInputStream(outputDirectory.resolve(relpath).toFile().toPath())) { properties.load(is); } @@ -213,7 +232,6 @@ private void filter(String time) throws Exception { projectProperties.put("time", time); projectProperties.put("java.version", "zloug"); mavenProject.setProperties(projectProperties); - MavenResourcesFiltering mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); String unitFilesDir = unitDirectory.resolve("files").toString(); diff --git a/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java b/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java index 4d0cf44b..5e715a5a 100644 --- a/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java @@ -18,30 +18,41 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; import java.util.Collections; import org.apache.commons.io.FileUtils; import org.apache.maven.model.Resource; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; /** * @author Mikolaj Izdebski */ -public class InvalidMarkTest extends TestSupport { +@PlexusTest +class InvalidMarkTest { + + @Inject + MavenResourcesFiltering mavenResourcesFiltering; + File outputDirectory = new File(getBasedir(), "target/LongLineTest"); - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { if (outputDirectory.exists()) { FileUtils.deleteDirectory(outputDirectory); } outputDirectory.mkdirs(); } - public void testEscape() throws Exception { - MavenResourcesFiltering mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); - + @Test + void escape() { Resource resource = new Resource(); resource.setDirectory("src/test/units-files/MSHARED-325"); resource.setFiltering(true); @@ -55,10 +66,8 @@ public void testEscape() throws Exception { Collections.emptyList(), new StubMavenSession()); - try { + assertDoesNotThrow(() -> { mavenResourcesFiltering.filterResources(mavenResourcesExecution); - } catch (MavenFilteringException e) { - fail(); - } + }); } } diff --git a/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java index 12144dc6..fa8c63ac 100644 --- a/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java @@ -18,6 +18,8 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; @@ -27,18 +29,27 @@ import org.apache.commons.io.FileUtils; import org.apache.maven.model.Resource; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Olivier Lamy * */ -public class MuliLinesMavenResourcesFilteringTest extends TestSupport { +@PlexusTest +class MuliLinesMavenResourcesFilteringTest { + + @Inject + MavenResourcesFiltering mavenResourcesFiltering; File outputDirectory = new File(getBasedir(), "target/MuliLinesMavenResourcesFilteringTest"); - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { if (outputDirectory.exists()) { FileUtils.deleteDirectory(outputDirectory); } @@ -48,7 +59,8 @@ protected void setUp() throws Exception { /** * @throws Exception */ - public void testFilteringTokenOnce() throws Exception { + @Test + void filteringTokenOnce() throws Exception { File baseDir = new File(getBasedir()); StubMavenProject mavenProject = new StubMavenProject(baseDir); mavenProject.setVersion("1.0"); @@ -59,7 +71,6 @@ public void testFilteringTokenOnce() throws Exception { projectProperties.put("foo", "bar"); projectProperties.put("java.version", "zloug"); mavenProject.setProperties(projectProperties); - MavenResourcesFiltering mavenResourcesFiltering = lookup(MavenResourcesFiltering.class); String unitFilesDir = getBasedir() + "/src/test/units-files/MRESOURCES-104"; diff --git a/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java b/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java index 4494df76..53deff8a 100644 --- a/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java @@ -27,24 +27,23 @@ import org.apache.commons.io.IOUtils; import org.codehaus.plexus.interpolation.Interpolator; import org.codehaus.plexus.interpolation.RecursionInterceptor; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.when; -public class MultiDelimiterInterpolatorFilterReaderLineEndingTest - extends AbstractInterpolatorFilterReaderLineEndingTest { +class MultiDelimiterInterpolatorFilterReaderLineEndingTest extends AbstractInterpolatorFilterReaderLineEndingTest { @Mock private Interpolator interpolator; @Override - @Before + @BeforeEach public void onSetup() { MockitoAnnotations.initMocks(this); } @@ -85,7 +84,7 @@ protected Reader getAtReader(Reader in, Interpolator interpolator, String escape // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open @Test - public void testLineWithSingleAtAndExpression() throws Exception { + void lineWithSingleAtAndExpression() throws Exception { when(interpolator.interpolate(eq("${foo}"), eq(""), isA(RecursionInterceptor.class))) .thenReturn("bar"); @@ -99,7 +98,7 @@ public void testLineWithSingleAtAndExpression() throws Exception { // http://stackoverflow.com/questions/21786805/maven-war-plugin-customize-filter-delimitters-in-webresources/ @Test - public void testAtDollarExpression() throws Exception { + void atDollarExpression() throws Exception { when(interpolator.interpolate(eq("${db.server}"), eq(""), isA(RecursionInterceptor.class))) .thenReturn("DB_SERVER"); when(interpolator.interpolate(eq("${db.port}"), eq(""), isA(RecursionInterceptor.class))) diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java index 3459f9b6..4e8d53fd 100644 --- a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java @@ -26,14 +26,20 @@ import java.nio.charset.StandardCharsets; import java.util.Properties; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Olivier Lamy * @since 1.0-beta-1 */ -public class PropertyUtilsTest extends TestSupport { +class PropertyUtilsTest { private static File testDirectory = new File(getBasedir(), "target/test-classes/"); - public void testBasic() throws Exception { + @Test + void basic() throws Exception { File basicProperties = File.createTempFile("basic", ".properties"); basicProperties.deleteOnExit(); @@ -49,7 +55,8 @@ public void testBasic() throws Exception { assertEquals("${non_existent}", properties.getProperty("ghost")); } - public void testSystemProperties() throws Exception { + @Test + void systemProperties() throws Exception { File systemProperties = File.createTempFile("system", ".properties"); systemProperties.deleteOnExit(); @@ -62,10 +69,11 @@ public void testSystemProperties() throws Exception { assertEquals(System.getProperty("user.dir"), properties.getProperty("key")); } - public void testException() throws Exception { + @Test + void exception() throws Exception { File nonExistent = new File(testDirectory, "not_existent_file"); - assertFalse("property file exist: " + nonExistent, nonExistent.exists()); + assertFalse(nonExistent.exists(), "property file exist: " + nonExistent); try { PropertyUtils.loadPropertyFile(nonExistent, true, false); @@ -75,7 +83,8 @@ public void testException() throws Exception { } } - public void testLoadPropertiesFile() throws Exception { + @Test + void loadPropertiesFile() throws Exception { File propertyFile = new File(getBasedir() + "/src/test/units-files/propertyutils-test.properties"); Properties baseProperties = new Properties(); baseProperties.put("pom.version", "realVersion"); @@ -92,7 +101,8 @@ public void testLoadPropertiesFile() throws Exception { * * @throws IOException if problem writing file */ - public void testCircularReferences() throws IOException { + @Test + void circularReferences() throws IOException { File circularProperties = File.createTempFile("circular", ".properties"); circularProperties.deleteOnExit(); @@ -112,7 +122,8 @@ public void testCircularReferences() throws IOException { * * @throws IOException if problem writing file */ - public void testCircularReferences3Vars() throws IOException { + @Test + void circularReferences3Vars() throws IOException { File circularProperties = File.createTempFile("circular", ".properties"); circularProperties.deleteOnExit(); @@ -129,7 +140,8 @@ public void testCircularReferences3Vars() throws IOException { assertEquals("${test}", properties.getProperty("test3")); } - public void testNonCircularReferences1Var3Times() throws IOException { + @Test + void nonCircularReferences1Var3Times() throws IOException { File nonCircularProperties = File.createTempFile("non-circular", ".properties"); nonCircularProperties.deleteOnExit(); @@ -145,7 +157,8 @@ public void testNonCircularReferences1Var3Times() throws IOException { assertEquals("1.2.3", properties.getProperty("version")); } - public void testNonCircularReferences2Vars2Times() throws IOException { + @Test + void nonCircularReferences2Vars2Times() throws IOException { File nonCircularProperties = File.createTempFile("non-circular", ".properties"); nonCircularProperties.deleteOnExit(); diff --git a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java index 98f684b0..a2926ff2 100644 --- a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java +++ b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java @@ -18,26 +18,37 @@ */ package org.apache.maven.shared.filtering; +import javax.inject.Inject; + import java.io.File; import java.io.FileInputStream; import java.util.Properties; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Olivier Lamy * @since 1.0-beta-1 * */ -public class TestReflectionProperties extends TestSupport { +@PlexusTest +class TestReflectionProperties { + + @Inject + MavenFileFilter mavenFileFilter; - public void testSimpleFiltering() throws Exception { + @Test + void simpleFiltering() throws Exception { MavenProject mavenProject = new MavenProject(); mavenProject.setVersion("1.0"); mavenProject.setGroupId("org.apache"); Properties userProperties = new Properties(); userProperties.setProperty("foo", "bar"); - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); File from = new File(getBasedir() + "/src/test/units-files/reflection-test.properties"); File to = new File(getBasedir() + "/target/reflection-test.properties"); @@ -60,14 +71,14 @@ public void testSimpleFiltering() throws Exception { assertEquals("none filtered", reading.get("none")); } - public void testSimpleNonFiltering() throws Exception { + @Test + void simpleNonFiltering() throws Exception { MavenProject mavenProject = new MavenProject(); mavenProject.setVersion("1.0"); mavenProject.setGroupId("org.apache"); Properties userProperties = new Properties(); userProperties.setProperty("foo", "bar"); - MavenFileFilter mavenFileFilter = lookup(MavenFileFilter.class); File from = new File(getBasedir() + "/src/test/units-files/reflection-test.properties"); File to = new File(getBasedir() + "/target/reflection-test.properties"); diff --git a/src/test/java/org/apache/maven/shared/filtering/TestSupport.java b/src/test/java/org/apache/maven/shared/filtering/TestSupport.java deleted file mode 100644 index 5eb18a3b..00000000 --- a/src/test/java/org/apache/maven/shared/filtering/TestSupport.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.shared.filtering; - -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; - -/** - * Support class for injected tests. This should be moved off ancient Junit3 PlexusTestCase to more modern JUnit. - */ -public abstract class TestSupport extends PlexusTestCase { - @Override - protected void customizeContainerConfiguration(ContainerConfiguration configuration) { - configuration.setAutoWiring(true).setClassPathScanning(PlexusConstants.SCANNING_INDEX); - } -}