From dad9f189b5c8782be76afaaa12b9c5a263cdcb95 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Mon, 8 May 2023 11:09:31 +0200 Subject: [PATCH] Move to Junit5 --- pom.xml | 5 +- .../EnvarBasedValueSourceTest.java | 18 +-- .../InterpolatorFilterReaderTest.java | 19 ++- .../PrefixAwareRecursionInterceptorTest.java | 10 +- .../PrefixedObjectValueSourceTest.java | 10 +- .../PrefixedValueSourceWrapperTest.java | 9 +- .../PropertiesBasedValueSourceTest.java | 8 +- .../RegexBasedInterpolatorTest.java | 23 +++- .../StringSearchInterpolatorTest.java | 39 +++++- .../fixed/EnvarBasedValueSourceTest.java | 18 +-- .../FixedStringSearchInterpolatorTest.java | 121 ++++++++---------- ...DelimiterInterpolatorFilterReaderTest.java | 22 +++- ...DelimiterStringSearchInterpolatorTest.java | 12 +- .../FieldBasedObjectInterpolatorTest.java | 16 ++- .../interpolation/util/StringUtilsTest.java | 13 +- 15 files changed, 218 insertions(+), 125 deletions(-) diff --git a/pom.xml b/pom.xml index c6b0150..cb4cb98 100644 --- a/pom.xml +++ b/pom.xml @@ -37,9 +37,8 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter test diff --git a/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java index bc88e8b..e6b200b 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java @@ -16,27 +16,29 @@ * limitations under the License. */ -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class EnvarBasedValueSourceTest { - @Before + @BeforeEach public void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - public void testNoArgConstructorIsCaseSensitive() + void testNoArgConstructorIsCaseSensitive() throws IOException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() @@ -58,7 +60,7 @@ public Map getEnvMap() } @Test - public void testCaseInsensitive() + void testCaseInsensitive() throws IOException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() @@ -80,7 +82,7 @@ public Map getEnvMap() } @Test - public void testGetRealEnvironmentVariable() + void testGetRealEnvironmentVariable() throws IOException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() ); @@ -90,7 +92,7 @@ public void testGetRealEnvironmentVariable() String realEnvVar = "JAVA_HOME"; String realValue = System.getenv().get( realEnvVar ); - assertNotNull( "Can't run this test until " + realEnvVar + " env variable is set", realValue ); + assertNotNull( realValue , "Can't run this test until " + realEnvVar + " env variable is set"); assertEquals( realValue, source.getValue( realEnvVar ) ); } diff --git a/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java b/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java index 8787413..88eacf0 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java @@ -24,13 +24,15 @@ * SOFTWARE. */ +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * InterpolatorFilterReaderTest, heavily based on InterpolationFilterReaderTest. Heh, even the test strings remained the @@ -40,12 +42,12 @@ * */ public class InterpolatorFilterReaderTest - extends TestCase { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. * kenneyw@15-04-2005 fixed the bug. */ + @Test public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { @@ -60,6 +62,7 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() /* * kenneyw@14-04-2005 Added test to check above fix. */ + @Test public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { @@ -71,6 +74,7 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() assertEquals( "This is a ${test, really", interpolate( testStr, m ) ); } + @Test public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { @@ -82,6 +86,7 @@ public void testShouldNotInterpolateWithMalformedStartToken() assertEquals( "This is a $!test} again", interpolate( foo, m ) ); } + @Test public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { @@ -93,6 +98,7 @@ public void testShouldNotInterpolateWithMalformedEndToken() assertEquals( "This is a ${test!} again", interpolate( foo, m ) ); } + @Test public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { @@ -105,6 +111,7 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) ); } + @Test public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { @@ -117,6 +124,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() assertEquals( "jason is an asshole", interpolate( foo, m ) ); } + @Test public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception { @@ -129,6 +137,7 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() assertEquals( "jason is an asshole", interpolate( foo, m, "@{", "}" ) ); } + @Test public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception { @@ -141,6 +150,7 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomS assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) ); } + @Test public void testEscape() throws Exception { @@ -153,6 +163,7 @@ public void testEscape() assertEquals( "jason is an ${noun}", interpolate( foo, m, "\\" ) ); } + @Test public void testEscapeAtStart() throws Exception { @@ -165,6 +176,7 @@ public void testEscapeAtStart() assertEquals( "${name} is an ${noun}", interpolate( foo, m, "\\" ) ); } + @Test public void testEscapeOnlyAtStart() throws Exception { @@ -178,6 +190,7 @@ public void testEscapeOnlyAtStart() assertEquals( "@name@ is an asshole", result ); } + @Test public void testEscapeOnlyAtStartDefaultToken() throws Exception { @@ -191,6 +204,7 @@ public void testEscapeOnlyAtStartDefaultToken() assertEquals( "${name} is an asshole", result ); } + @Test public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception { @@ -224,6 +238,7 @@ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() assertEquals( input, buf.toString() ); } + @Test public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java index c673137..1cbf533 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java @@ -16,15 +16,19 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Collections; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; public class PrefixAwareRecursionInterceptorTest - extends TestCase { + @Test public void testFindExpression() { PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor( @@ -42,6 +46,7 @@ public void testFindExpression() assertFalse( receptor.hasRecursiveExpression( expr ) ); } + @Test public void testFindExpressionWithDifferentPrefix() { PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor( @@ -61,6 +66,7 @@ public void testFindExpressionWithDifferentPrefix() assertFalse( receptor.hasRecursiveExpression( expr ) ); } + @Test public void testFindExpressionWithoutPrefix() { PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor( diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java index b4ca7ae..0a916aa 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java @@ -16,15 +16,17 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; public class PrefixedObjectValueSourceTest - extends TestCase { - + + @Test public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed() { String target = "Target object"; @@ -39,6 +41,7 @@ public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed() assertNull( result ); } + @Test public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot() { String target = "Target object"; @@ -53,6 +56,7 @@ public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot() assertNull( result ); } + @Test public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithoutDot() { String target = "Target object"; diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java index 624671f..e7502a4 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java @@ -16,14 +16,17 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.Properties; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; public class PrefixedValueSourceWrapperTest - extends TestCase { + @Test public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix() { String prefix = "prefix."; @@ -38,6 +41,7 @@ public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix() assertEquals( value, wrapper.getValue( prefix + key ) ); } + @Test public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix() { String prefix = "prefix."; @@ -53,6 +57,7 @@ public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSing assertNull( wrapper.getValue( otherPrefix + key ) ); } + @Test public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix() { String prefix = "prefix."; diff --git a/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java index 647cfed..d893030 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java @@ -16,14 +16,17 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.Properties; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; public class PropertiesBasedValueSourceTest - extends TestCase { + @Test public void testPropertyShouldReturnValueFromProperties() { Properties props = new Properties(); @@ -38,6 +41,7 @@ public void testPropertyShouldReturnValueFromProperties() assertNotNull( vs.getValue( key ) ); } + @Test public void testPropertyShouldReturnNullWhenPropertyMissing() { Properties props = new Properties(); diff --git a/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java index dcd97d0..245ef51 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java @@ -16,21 +16,22 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; -import org.junit.Before; - -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class RegexBasedInterpolatorTest - extends TestCase { - @Before + @BeforeEach public void setUp() { EnvarBasedValueSource.resetStatics(); @@ -41,6 +42,7 @@ public String getVar() return "testVar"; } + @Test public void testShouldFailOnExpressionCycle() { Properties props = new Properties(); @@ -62,6 +64,7 @@ public void testShouldFailOnExpressionCycle() } } + @Test public void testShouldResolveByMy_getVar_Method() throws InterpolationException { @@ -72,6 +75,7 @@ public void testShouldResolveByMy_getVar_Method() assertEquals( "this is a testVar", result ); } + @Test public void testShouldResolveByContextValue() throws InterpolationException { @@ -87,6 +91,7 @@ public void testShouldResolveByContextValue() assertEquals( "this is a testVar", result ); } + @Test public void testShouldResolveByEnvar() throws IOException, InterpolationException { @@ -109,6 +114,7 @@ public Map getEnvMap() assertEquals( "this is a variable", result ); } + @Test public void testUseAlternateRegex() throws Exception { @@ -124,6 +130,7 @@ public void testUseAlternateRegex() assertEquals( "this is a testVar", result ); } + @Test public void testNPEFree() throws Exception { @@ -137,8 +144,9 @@ public void testNPEFree() String result = rbi.interpolate( null ); assertEquals( "", result ); - } - + } + + @Test public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException { @@ -162,6 +170,7 @@ public Object execute( String expression, Object value ) assertEquals( "this is a testVar", result ); } + @Test public void testUsePostProcessor_ChangesValue() throws InterpolationException { diff --git a/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java index 9065b38..1d184eb 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java @@ -16,6 +16,9 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -25,20 +28,19 @@ import java.util.Properties; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; -import org.junit.Before; - -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class StringSearchInterpolatorTest - extends TestCase { - @Before + @BeforeEach public void setUp() { EnvarBasedValueSource.resetStatics(); } + @Test public void testLongDelimitersInContext() throws InterpolationException { @@ -54,6 +56,7 @@ public void testLongDelimitersInContext() assertEquals( result, interpolator.interpolate( src ) ); } + @Test public void testLongDelimitersWithNoStartContext() throws InterpolationException { @@ -69,6 +72,7 @@ public void testLongDelimitersWithNoStartContext() assertEquals( result, interpolator.interpolate( src ) ); } + @Test public void testLongDelimitersWithNoEndContext() throws InterpolationException { @@ -84,6 +88,7 @@ public void testLongDelimitersWithNoEndContext() assertEquals( result, interpolator.interpolate( src ) ); } + @Test public void testLongDelimitersWithNoContext() throws InterpolationException { @@ -99,6 +104,7 @@ public void testLongDelimitersWithNoContext() assertEquals( result, interpolator.interpolate( src ) ); } + @Test public void testSimpleSubstitution() throws InterpolationException { @@ -111,6 +117,7 @@ public void testSimpleSubstitution() assertEquals( "This is a test value.", interpolator.interpolate( "This is a test ${key}." ) ); } + @Test public void testSimpleSubstitution_TwoExpressions() throws InterpolationException { @@ -124,6 +131,7 @@ public void testSimpleSubstitution_TwoExpressions() assertEquals( "value-value2", interpolator.interpolate( "${key}-${key2}" ) ); } + @Test public void testBrokenExpression_LeaveItAlone() throws InterpolationException { @@ -136,6 +144,7 @@ public void testBrokenExpression_LeaveItAlone() assertEquals( "This is a test ${key.", interpolator.interpolate( "This is a test ${key." ) ); } + @Test public void testShouldFailOnExpressionCycle() { Properties props = new Properties(); @@ -157,6 +166,7 @@ public void testShouldFailOnExpressionCycle() } } + @Test public void testShouldResolveByUsingObject_List_Map() throws InterpolationException { @@ -168,6 +178,7 @@ public void testShouldResolveByUsingObject_List_Map() assertEquals( "this is a testVar testIndexedWithList testIndexedWithArray testMap", result ); } + @Test public void testShouldResolveByContextValue() throws InterpolationException { @@ -183,6 +194,7 @@ public void testShouldResolveByContextValue() assertEquals( "this is a testVar", result ); } + @Test public void testShouldResolveByEnvar() throws IOException, InterpolationException { @@ -206,6 +218,7 @@ public Map getEnvMap() assertEquals( "this is a variable other variable", result ); } + @Test public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException { @@ -229,6 +242,7 @@ public Object execute( String expression, Object value ) assertEquals( "this is a testVar", result ); } + @Test public void testUsePostProcessor_ChangesValue() throws InterpolationException { @@ -253,6 +267,7 @@ public Object execute( String expression, Object value ) assertEquals( "this is a testVar2", result ); } + @Test public void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException { @@ -265,6 +280,7 @@ public void testSimpleSubstitutionWithDefinedExpr() assertEquals( "This is a test value.", interpolator.interpolate( "This is a test @{key}." ) ); } + @Test public void testEscape() throws InterpolationException { @@ -280,6 +296,7 @@ public void testEscape() assertEquals( "This is a test @{key}.", result ); } + @Test public void testEscapeWithLongEscapeStr() throws InterpolationException { @@ -295,6 +312,7 @@ public void testEscapeWithLongEscapeStr() assertEquals( "This is a test @{key}.", result ); } + @Test public void testEscapeWithLongEscapeStrAtStart() throws InterpolationException { @@ -310,6 +328,7 @@ public void testEscapeWithLongEscapeStrAtStart() assertEquals( "@{key} This is a test.", result ); } + @Test public void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException { @@ -325,6 +344,7 @@ public void testNotEscapeWithLongEscapeStrAtStart() assertEquals( "value This is a test.", result ); } + @Test public void testEscapeNotFailWithNullEscapeStr() throws InterpolationException { @@ -340,6 +360,7 @@ public void testEscapeNotFailWithNullEscapeStr() assertEquals( "This is a test value.", result ); } + @Test public void testOnlyEscapeExprAtStart() throws InterpolationException { @@ -355,6 +376,7 @@ public void testOnlyEscapeExprAtStart() assertEquals( "@{key} This is a test.", result ); } + @Test public void testNotEscapeExprAtStart() throws InterpolationException { @@ -370,6 +392,7 @@ public void testNotEscapeExprAtStart() assertEquals( "value This is a test.", result ); } + @Test public void testEscapeExprAtStart() throws InterpolationException { @@ -385,6 +408,7 @@ public void testEscapeExprAtStart() assertEquals( "@key@ This is a test value.", result ); } + @Test public void testNPEFree() throws InterpolationException { @@ -400,6 +424,7 @@ public void testNPEFree() assertEquals( "", result ); } + @Test public void testInterruptedInterpolate() throws InterpolationException { @@ -430,7 +455,7 @@ public void clearFeedback() { } } ); - assertEquals( "control case", "-val-" , interpolator.interpolate( "-${key}-", recursionInterceptor ) ); + assertEquals( "-val-" , interpolator.interpolate( "-${key}-", recursionInterceptor ) , "control case"); error[ 0 ] = true; try { @@ -442,7 +467,7 @@ public void clearFeedback() // right } error[ 0 ] = false; - assertEquals( "should not believe there is a cycle here", "-val-", interpolator.interpolate( "-${key}-", recursionInterceptor ) ); + assertEquals( "-val-", interpolator.interpolate( "-${key}-", recursionInterceptor ) , "should not believe there is a cycle here"); } public String getVar() diff --git a/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java index beaf014..e0f283b 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java @@ -16,27 +16,29 @@ * limitations under the License. */ -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class EnvarBasedValueSourceTest { - @Before + @BeforeEach public void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - public void testNoArgConstructorIsCaseSensitive() + void testNoArgConstructorIsCaseSensitive() throws IOException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() @@ -58,7 +60,7 @@ public Map getEnvMap() } @Test - public void testCaseInsensitive() + void testCaseInsensitive() throws IOException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() @@ -80,7 +82,7 @@ public Map getEnvMap() } @Test - public void testGetRealEnvironmentVariable() + void testGetRealEnvironmentVariable() throws IOException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() ); @@ -90,7 +92,7 @@ public void testGetRealEnvironmentVariable() String realEnvVar = "JAVA_HOME"; String realValue = System.getenv().get( realEnvVar ); - assertNotNull( "Can't run this test until " + realEnvVar + " env variable is set", realValue ); + assertNotNull( realValue , "Can't run this test until " + realEnvVar + " env variable is set"); assertEquals( realValue, source.getValue( realEnvVar, null ) ); } diff --git a/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java index d2c519c..a7990f1 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java @@ -2,7 +2,7 @@ /* * Copyright 2001-2008 Codehaus Foundation. * - * Licensed under the Apache License, VerDefaultInterpolationStatesion 2.0 (the "License"); + * Licensed 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 * @@ -16,8 +16,8 @@ */ import static org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator.create; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.ArrayList; @@ -31,20 +31,20 @@ import org.codehaus.plexus.interpolation.InterpolationPostProcessor; import org.codehaus.plexus.interpolation.StringSearchInterpolator; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class FixedStringSearchInterpolatorTest { - @Before + @BeforeEach public void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - public void testLongDelimitersInContext() + void testLongDelimitersInContext() { String src = "This is a test.label for long delimiters in context."; String result = "This is a test for long delimiters in context."; @@ -59,7 +59,7 @@ public void testLongDelimitersInContext() } @Test - public void testLongDelimitersWithNoStartContext() + void testLongDelimitersWithNoStartContext() { String src = "test.label for long delimiters in context."; String result = "test for long delimiters in context."; @@ -74,7 +74,7 @@ public void testLongDelimitersWithNoStartContext() } @Test - public void testLongDelimitersWithNoEndContext() + void testLongDelimitersWithNoEndContext() { String src = "This is a test.label"; String result = "This is a test"; @@ -89,7 +89,7 @@ public void testLongDelimitersWithNoEndContext() } @Test - public void testLongDelimitersWithNoContext() + void testLongDelimitersWithNoContext() { String src = "test.label"; String result = "test"; @@ -104,7 +104,7 @@ public void testLongDelimitersWithNoContext() } @Test - public void testSimpleSubstitution() + void testSimpleSubstitution() { Properties p = new Properties(); p.setProperty( "key", "value" ); @@ -115,7 +115,7 @@ public void testSimpleSubstitution() } @Test - public void testSimpleSubstitution_TwoExpressions() + void testSimpleSubstitution_TwoExpressions() { Properties p = new Properties(); p.setProperty( "key", "value" ); @@ -127,7 +127,7 @@ public void testSimpleSubstitution_TwoExpressions() } @Test - public void testBrokenExpression_LeaveItAlone() + void testBrokenExpression_LeaveItAlone() { Properties p = new Properties(); p.setProperty( "key", "value" ); @@ -138,7 +138,7 @@ public void testBrokenExpression_LeaveItAlone() } @Test - public void testShouldFailOnExpressionCycle() + void testShouldFailOnExpressionCycle() { Properties props = new Properties(); props.setProperty( "key1", "${key2}" ); @@ -146,20 +146,12 @@ public void testShouldFailOnExpressionCycle() FixedStringSearchInterpolator rbi = create( new PropertiesBasedValueSource( props ) ); - try - { - rbi.interpolate( "${key1}" ); - - fail( "Should detect expression cycle and fail." ); - } - catch ( org.codehaus.plexus.interpolation.fixed.InterpolationCycleException e ) - { - // expected - } + assertThrows(InterpolationCycleException.class, () -> rbi.interpolate( "${key1}" ), + "Should detect expression cycle and fail." ); } @Test - public void testShouldResolveByUsingObject_List_Map() + void testShouldResolveByUsingObject_List_Map() throws InterpolationException { FixedStringSearchInterpolator rbi = create( new ObjectBasedValueSource( this ) ); @@ -170,7 +162,7 @@ public void testShouldResolveByUsingObject_List_Map() } @Test - public void testShouldResolveByContextValue() + void testShouldResolveByContextValue() throws InterpolationException { @@ -185,7 +177,7 @@ public void testShouldResolveByContextValue() } @Test - public void testShouldResolveByEnvar() + void testShouldResolveByEnvar() throws IOException, InterpolationException { OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() @@ -207,7 +199,7 @@ public Map getEnvMap() } @Test - public void testUsePostProcessor_DoesNotChangeValue() + void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException { @@ -230,7 +222,7 @@ public Object execute( String expression, Object value ) } @Test - public void testUsePostProcessor_ChangesValue() + void testUsePostProcessor_ChangesValue() throws InterpolationException { @@ -254,7 +246,7 @@ public Object execute( String expression, Object value ) } @Test - public void testSimpleSubstitutionWithDefinedExpr() + void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException { Properties p = new Properties(); @@ -266,7 +258,7 @@ public void testSimpleSubstitutionWithDefinedExpr() } @Test - public void testEscape() + void testEscape() throws InterpolationException { Properties p = new Properties(); @@ -281,7 +273,7 @@ public void testEscape() } @Test - public void testEscapeWithLongEscapeStr() + void testEscapeWithLongEscapeStr() throws InterpolationException { Properties p = new Properties(); @@ -296,7 +288,7 @@ public void testEscapeWithLongEscapeStr() } @Test - public void testEscapeWithLongEscapeStrAtStart() + void testEscapeWithLongEscapeStrAtStart() throws InterpolationException { Properties p = new Properties(); @@ -311,7 +303,7 @@ public void testEscapeWithLongEscapeStrAtStart() } @Test - public void testNotEscapeWithLongEscapeStrAtStart() + void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException { Properties p = new Properties(); @@ -326,7 +318,7 @@ public void testNotEscapeWithLongEscapeStrAtStart() } @Test - public void testEscapeNotFailWithNullEscapeStr() + void testEscapeNotFailWithNullEscapeStr() throws InterpolationException { Properties p = new Properties(); @@ -341,7 +333,7 @@ public void testEscapeNotFailWithNullEscapeStr() } @Test - public void testOnlyEscapeExprAtStart() + void testOnlyEscapeExprAtStart() throws InterpolationException { Properties p = new Properties(); @@ -356,7 +348,7 @@ public void testOnlyEscapeExprAtStart() } @Test - public void testNotEscapeExprAtStart() + void testNotEscapeExprAtStart() throws InterpolationException { Properties p = new Properties(); @@ -371,7 +363,7 @@ public void testNotEscapeExprAtStart() } @Test - public void testEscapeExprAtStart() + void testEscapeExprAtStart() throws InterpolationException { Properties p = new Properties(); @@ -386,7 +378,7 @@ public void testEscapeExprAtStart() } @Test - public void testNPEFree() + void testNPEFree() throws InterpolationException { Properties p = new Properties(); @@ -401,7 +393,7 @@ public void testNPEFree() } @Test - public void testInterruptedInterpolate() + void testInterruptedInterpolate() throws InterpolationException { final boolean[] error = new boolean[]{ false }; @@ -426,19 +418,14 @@ public Object getValue( String expression, InterpolationState errorCollector ) FixedStringSearchInterpolator interpolator = create( valueSource ); - assertEquals( "control case", "-val-", interpolator.interpolate( "-${key}-" ) ); + assertEquals( "-val-", interpolator.interpolate( "-${key}-" ) , "control case"); error[0] = true; - try - { - interpolator.interpolate( "-${key}-" ); - fail( "should have thrown exception" ); - } - catch ( IllegalStateException x ) - { - // right - } + + assertThrows( IllegalStateException.class, () -> interpolator.interpolate( "-${key}-" ) , + "should have thrown exception"); + error[0] = false; - assertEquals( "should not believe there is a cycle here", "-val-", interpolator.interpolate( "-${key}-" ) ); + assertEquals( "-val-", interpolator.interpolate( "-${key}-" ) , "should not believe there is a cycle here"); } public String getVar() @@ -487,7 +474,7 @@ public String getName() } @Test - public void testLinkedInterpolators() + void testLinkedInterpolators() { final String EXPR = "${test.label}AND${test2}"; final String EXPR2 = "${test.label}${test2.label}AND${test2}"; @@ -502,7 +489,7 @@ public void testLinkedInterpolators() } @Test - public void testDominance() + void testDominance() { final String EXPR = "${test.label}AND${test2}"; final String EXPR2 = "${test.label}${test2.label}AND${test2}"; @@ -517,7 +504,7 @@ public void testDominance() } @Test - public void unresolable_linked() + void unresolable_linked() { final String EXPR2 = "${test.label}${test2.label}AND${test2}"; @@ -529,24 +516,28 @@ public void unresolable_linked() assertEquals( "pdominantANDx", joined.interpolate( EXPR2 ) ); } - @Test( expected = InterpolationCycleException.class ) - public void testCyclesWithLinked() + @Test + void testCyclesWithLinked() { - FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "${key2}" ) ); - FixedStringSearchInterpolator second = create( first, properttyBasedValueSource( "key2", "${key1}" ) ); - second.interpolate( "${key2}" ); + assertThrows( InterpolationCycleException.class, () -> { + FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "${key2}" ) ); + FixedStringSearchInterpolator second = create( first, properttyBasedValueSource( "key2", "${key1}" ) ); + second.interpolate( "${key2}" ); + } ); } - @Test( expected = InterpolationCycleException.class ) - public void testCyclesWithLinked_betweenRootAndOther() + @Test + void testCyclesWithLinked_betweenRootAndOther() { - FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "${key2}" ) ); - FixedStringSearchInterpolator second = create( first, properttyBasedValueSource( "key2", "${key1}" ) ); - second.interpolate( "${key1}" ); + assertThrows( InterpolationCycleException.class, () -> { + FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "${key2}" ) ); + FixedStringSearchInterpolator second = create( first, properttyBasedValueSource( "key2", "${key1}" ) ); + second.interpolate( "${key1}" ); + } ); } @Test - public void fixedInjectedIntoRegular() + void fixedInjectedIntoRegular() throws InterpolationException { FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "v1" ) ); diff --git a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java index a2b5048..98190b2 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java @@ -29,15 +29,16 @@ import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor; import org.codehaus.plexus.interpolation.RecursionInterceptor; import org.codehaus.plexus.interpolation.StringSearchInterpolator; +import org.junit.jupiter.api.Test; import java.io.StringReader; + +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - /** * InterpolatorFilterReaderTest, heavily based on InterpolationFilterReaderTest. Heh, even the test strings remained the * same! @@ -46,12 +47,12 @@ * */ public class MultiDelimiterInterpolatorFilterReaderTest - extends TestCase { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. * kenneyw@15-04-2005 fixed the bug. */ + @Test public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { @@ -66,6 +67,7 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() /* * kenneyw@14-04-2005 Added test to check above fix. */ + @Test public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { @@ -77,6 +79,7 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() assertEquals( "This is a ${test, really", interpolate( testStr, m ) ); } + @Test public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { @@ -88,6 +91,7 @@ public void testShouldNotInterpolateWithMalformedStartToken() assertEquals( "This is a $!test} again", interpolate( foo, m ) ); } + @Test public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { @@ -99,6 +103,7 @@ public void testShouldNotInterpolateWithMalformedEndToken() assertEquals( "This is a ${test!} again", interpolate( foo, m ) ); } + @Test public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { @@ -111,6 +116,7 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) ); } + @Test public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { @@ -123,6 +129,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() assertEquals( "jason is an asshole", interpolate( foo, m ) ); } + @Test public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception { @@ -135,6 +142,7 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() assertEquals( "jason is an asshole", interpolate( foo, m, "@{", "}" ) ); } + @Test public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception { @@ -147,6 +155,7 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomS assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) ); } + @Test public void testEscape() throws Exception { @@ -159,6 +168,7 @@ public void testEscape() assertEquals( "jason is an ${noun}", interpolate( foo, m, "\\" ) ); } + @Test public void testEscapeAtStart() throws Exception { @@ -171,6 +181,7 @@ public void testEscapeAtStart() assertEquals( "${name} is an ${noun}", interpolate( foo, m, "\\" ) ); } + @Test public void testEscapeOnlyAtStart() throws Exception { @@ -184,6 +195,7 @@ public void testEscapeOnlyAtStart() assertEquals( "@name@ is an asshole", result ); } + @Test public void testEscapeOnlyAtStartDefaultToken() throws Exception { @@ -197,6 +209,7 @@ public void testEscapeOnlyAtStartDefaultToken() assertEquals( "${name} is an asshole", result ); } + @Test public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception { @@ -231,6 +244,7 @@ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() assertEquals( input, buf.toString() ); } + @Test public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception { @@ -264,6 +278,7 @@ public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() assertEquals( "${prefix1.name}", buf.toString() ); } + @Test public void testInterpolationWithMultipleTokenTypes() throws Exception { @@ -276,6 +291,7 @@ public void testInterpolationWithMultipleTokenTypes() assertEquals( "jason", interpolateMulti( foo, m, new String[] { "${*}", "@*@" } ) ); } + @Test public void testInterpolationWithMultipleTokenTypes_ReversedOrdering() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java index 91b6434..4d4cdc8 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java @@ -19,17 +19,17 @@ import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.MapBasedValueSource; import org.codehaus.plexus.interpolation.ValueSource; -import org.codehaus.plexus.interpolation.multi.MultiDelimiterStringSearchInterpolator; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MultiDelimiterStringSearchInterpolatorTest - extends TestCase { + @Test public void testInterpolationWithDifferentDelimiters() throws InterpolationException { @@ -48,6 +48,7 @@ public void testInterpolationWithDifferentDelimiters() assertEquals( ctx.get( "name" ), result ); } + @Test public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiterSequence() throws InterpolationException { @@ -66,8 +67,9 @@ public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiter assertEquals( ctx.get( "name" ), result ); } + @Test public void testInterpolationWithMultipleEscapes() - throws InterpolationException + throws InterpolationException { Map ctx = new HashMap(); ctx.put( "name", "User" ); @@ -85,6 +87,7 @@ public void testInterpolationWithMultipleEscapes() assertEquals( "#${first} and ${last}", result ); } + @Test public void testInterpolationWithMultipleEscapes2() throws InterpolationException { @@ -104,6 +107,7 @@ public void testInterpolationWithMultipleEscapes2() assertEquals( "${first} and #${last}", result ); } + @Test public void testInterpolationWithMultipleEscapes3() throws InterpolationException { diff --git a/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java index 4209750..57d6e96 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -23,15 +25,14 @@ import java.util.Map; import java.util.Properties; -import junit.framework.TestCase; - import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; import org.codehaus.plexus.interpolation.StringSearchInterpolator; +import org.junit.jupiter.api.Test; public class FieldBasedObjectInterpolatorTest - extends TestCase { + @Test public void testInterpolateStringArray() throws Exception { @@ -50,6 +51,7 @@ public void testInterpolateStringArray() assertEquals( "value2", values[1] ); } + @Test public void testInterpolateObjectWithStringArrayField() throws Exception { @@ -70,6 +72,7 @@ public void testInterpolateObjectWithStringArrayField() assertEquals( "value2", obj.values[1] ); } + @Test public void testInterpolateObjectWithStringListField() throws Exception { @@ -92,6 +95,7 @@ public void testInterpolateObjectWithStringListField() assertEquals( "value2", obj.values.get( 1 ) ); } + @Test public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() throws Exception { @@ -114,6 +118,7 @@ public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() assertEquals( "value2", obj.values.get( 1 ) ); } + @Test public void testInterpolateObjectWithUnmodifiableStringListField() throws Exception { @@ -133,6 +138,7 @@ public void testInterpolateObjectWithUnmodifiableStringListField() assertEquals( "${key}", obj.values.get( 0 ) ); } + @Test public void testInterpolateObjectWithStringArrayListField() throws Exception { @@ -159,6 +165,7 @@ public void testInterpolateObjectWithStringArrayListField() assertEquals( "value4", ( (String[]) obj.values.get( 1 ) )[1] ); } + @Test public void testInterpolateObjectWithStringToStringMapField() throws Exception { @@ -181,6 +188,7 @@ public void testInterpolateObjectWithStringToStringMapField() assertEquals( "value2", obj.values.get( "key2" ) ); } + @Test public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() throws Exception { @@ -203,6 +211,7 @@ public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() assertEquals( "value2", obj.values.get( "key2" ) ); } + @Test public void testInterpolateObjectWithUnmodifiableStringToStringMapField() throws Exception { @@ -222,6 +231,7 @@ public void testInterpolateObjectWithUnmodifiableStringToStringMapField() assertEquals( "${key}", obj.values.get( "key" ) ); } + @Test public void testInterpolateObjectWithStringToStringArrayMapField() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java index 8044bd0..cfc17ce 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java @@ -15,17 +15,18 @@ * limitations under the License. */ -import junit.framework.Assert; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; public class StringUtilsTest - extends TestCase { + @Test public void testCapitalizeFirstLetter() throws Exception { - Assert.assertEquals( "Abc", StringUtils.capitalizeFirstLetter( "abc" ) ); - Assert.assertEquals( "\u00cdce", StringUtils.capitalizeFirstLetter( "\u00edce" ) ); - Assert.assertEquals( "X", StringUtils.capitalizeFirstLetter( "x" ) ); + assertEquals( "Abc", StringUtils.capitalizeFirstLetter( "abc" ) ); + assertEquals( "\u00cdce", StringUtils.capitalizeFirstLetter( "\u00edce" ) ); + assertEquals( "X", StringUtils.capitalizeFirstLetter( "x" ) ); } }