diff --git a/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java index 8a3c76c..37af0a4 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java @@ -1,24 +1,6 @@ package org.codehaus.plexus.interpolation; -/* - * Copyright 2007 The Codehaus Foundation. - * - * 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 - * - * 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. - */ - -import java.io.IOException; import java.util.HashMap; -import java.util.Map; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; import org.junit.jupiter.api.BeforeEach; @@ -28,21 +10,19 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -public class EnvarBasedValueSourceTest { +class EnvarBasedValueSourceTest { @BeforeEach - public void setUp() { + void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - void testNoArgConstructorIsCaseSensitive() throws IOException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("aVariable", "variable"); - return map; - } + void noArgConstructorIsCaseSensitive() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("aVariable", "variable"); + return map; }); EnvarBasedValueSource source = new EnvarBasedValueSource(); @@ -54,13 +34,11 @@ public Map getEnvMap() { } @Test - void testCaseInsensitive() throws IOException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("aVariable", "variable"); - return map; - } + void caseInsensitive() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("aVariable", "variable"); + return map; }); EnvarBasedValueSource source = new EnvarBasedValueSource(false); @@ -72,7 +50,7 @@ public Map getEnvMap() { } @Test - void testGetRealEnvironmentVariable() throws IOException { + void getRealEnvironmentVariable() throws Exception { OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource()); EnvarBasedValueSource source = new EnvarBasedValueSource(); diff --git a/src/test/java/org/codehaus/plexus/interpolation/FeedbackingValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/FeedbackingValueSourceTest.java index f6304ad..909e4fa 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/FeedbackingValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/FeedbackingValueSourceTest.java @@ -23,10 +23,10 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -public class FeedbackingValueSourceTest { +class FeedbackingValueSourceTest { @Test - public void testStandalone() { + void standalone() { ValueSource valueSource = new FeedbackingValueSource(); assertNull(valueSource.getValue("test")); assertEquals(1, valueSource.getFeedback().size()); @@ -34,7 +34,7 @@ public void testStandalone() { } @Test - public void testAfterResolvedExpression() throws InterpolationException { + void afterResolvedExpression() throws Exception { StringSearchInterpolator interpolator = new StringSearchInterpolator(); interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val"))); interpolator.addValueSource(new FeedbackingValueSource()); @@ -43,7 +43,7 @@ public void testAfterResolvedExpression() throws InterpolationException { } @Test - public void testBeforeResolvedExpression() throws InterpolationException { + void beforeResolvedExpression() throws Exception { StringSearchInterpolator interpolator = new StringSearchInterpolator(); interpolator.addValueSource(new FeedbackingValueSource("Resolving ${expression}")); interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val"))); @@ -53,7 +53,7 @@ public void testBeforeResolvedExpression() throws InterpolationException { } @Test - public void testAfterNotResolvedExpression() throws InterpolationException { + void afterNotResolvedExpression() throws Exception { StringSearchInterpolator interpolator = new StringSearchInterpolator(); interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val"))); interpolator.addValueSource(new FeedbackingValueSource()); diff --git a/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java b/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java index 0be913d..4f3a4d0 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java @@ -41,14 +41,14 @@ * @author cstamas * */ -public class InterpolatorFilterReaderTest { +class InterpolatorFilterReaderTest { /* * 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 { - Map m = new HashMap(); + void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test"; @@ -60,8 +60,8 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() t * kenneyw@14-04-2005 Added test to check above fix. */ @Test - public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test, really"; @@ -70,8 +70,8 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Excep } @Test - public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedStartToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a $!test} again"; @@ -80,8 +80,8 @@ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { } @Test - public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test!} again"; @@ -90,8 +90,8 @@ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { } @Test - public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -101,8 +101,8 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep } @Test - public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -112,8 +112,8 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio } @Test - public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception { - Map m = new HashMap(); + void interpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -123,8 +123,8 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws } @Test - public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception { - Map m = new HashMap(); + void interpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -134,8 +134,8 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomS } @Test - public void testEscape() throws Exception { - Map m = new HashMap(); + void escape() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -145,8 +145,8 @@ public void testEscape() throws Exception { } @Test - public void testEscapeAtStart() throws Exception { - Map m = new HashMap(); + void escapeAtStart() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -156,8 +156,8 @@ public void testEscapeAtStart() throws Exception { } @Test - public void testEscapeOnlyAtStart() throws Exception { - Map m = new HashMap(); + void escapeOnlyAtStart() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -168,8 +168,8 @@ public void testEscapeOnlyAtStart() throws Exception { } @Test - public void testEscapeOnlyAtStartDefaultToken() throws Exception { - Map m = new HashMap(); + void escapeOnlyAtStartDefaultToken() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -180,15 +180,15 @@ public void testEscapeOnlyAtStartDefaultToken() throws Exception { } @Test - public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception { - List prefixes = new ArrayList(); + void shouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception { + List prefixes = new ArrayList<>(); prefixes.add("prefix1"); prefixes.add("prefix2"); RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("name", "${prefix2.name}"); String input = "${prefix1.name}"; @@ -211,14 +211,14 @@ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throw } @Test - public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception { - List prefixes = new ArrayList(); + void shouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception { + List prefixes = new ArrayList<>(); prefixes.add("prefix1"); RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("name", "${prefix1.name}"); String input = "${name}"; @@ -244,11 +244,11 @@ public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exc // // ---------------------------------------------------------------------- - private String interpolate(String input, Map context) throws Exception { + private String interpolate(String input, Map context) throws Exception { return interpolate(input, context, null); } - private String interpolate(String input, Map context, String escapeStr) throws Exception { + private String interpolate(String input, Map context, String escapeStr) throws Exception { Interpolator interpolator = new StringSearchInterpolator(); interpolator.addValueSource(new MapBasedValueSource(context)); @@ -268,7 +268,8 @@ private String interpolate(String input, Map context, String escapeStr) throws E return buf.toString(); } - private String interpolate(String input, Map context, String beginToken, String endToken) throws Exception { + private String interpolate(String input, Map context, String beginToken, String endToken) + throws Exception { StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken); interpolator.addValueSource(new MapBasedValueSource(context)); diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java index d1f250a..e26d427 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java @@ -25,10 +25,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class PrefixAwareRecursionInterceptorTest { +class PrefixAwareRecursionInterceptorTest { @Test - public void testFindExpression() { + void findExpression() { PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(Collections.singleton("prefix.")); @@ -45,9 +45,9 @@ public void testFindExpression() { } @Test - public void testFindExpressionWithDifferentPrefix() { + void findExpressionWithDifferentPrefix() { PrefixAwareRecursionInterceptor receptor = - new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."})); + new PrefixAwareRecursionInterceptor(Arrays.asList("prefix.", "other.")); String expr = "prefix.first"; @@ -61,9 +61,9 @@ public void testFindExpressionWithDifferentPrefix() { } @Test - public void testFindExpressionWithoutPrefix() { + void findExpressionWithoutPrefix() { PrefixAwareRecursionInterceptor receptor = - new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."})); + new PrefixAwareRecursionInterceptor(Arrays.asList("prefix.", "other.")); String prefixedExpr = "prefix.first"; String expr = "first"; diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java index 996d090..eafcebf 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java @@ -23,13 +23,13 @@ import static org.junit.jupiter.api.Assertions.assertNull; -public class PrefixedObjectValueSourceTest { +class PrefixedObjectValueSourceTest { @Test - public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed() { + void emptyExpressionResultsInNullReturnNoPrefixUsed() { String target = "Target object"; - List prefixes = new ArrayList(); + List prefixes = new ArrayList<>(); prefixes.add("target"); prefixes.add("object"); @@ -40,10 +40,10 @@ public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed() { } @Test - public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot() { + void emptyExpressionResultsInNullReturnPrefixUsedWithDot() { String target = "Target object"; - List prefixes = new ArrayList(); + List prefixes = new ArrayList<>(); prefixes.add("target"); prefixes.add("object"); @@ -54,10 +54,10 @@ public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot() { } @Test - public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithoutDot() { + void emptyExpressionResultsInNullReturnPrefixUsedWithoutDot() { String target = "Target object"; - List prefixes = new ArrayList(); + List prefixes = new ArrayList<>(); prefixes.add("target"); prefixes.add("object"); diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java index 1e65b9b..cc3439f 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java @@ -23,10 +23,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -public class PrefixedValueSourceWrapperTest { +class PrefixedValueSourceWrapperTest { @Test - public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix() { + void shouldReturnValueForPropertyVSWRappedWithSinglePrefix() { String prefix = "prefix."; String key = "key"; String value = "value"; @@ -41,7 +41,7 @@ public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix() { } @Test - public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix() { + void shouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix() { String prefix = "prefix."; String otherPrefix = "other."; String key = "key"; @@ -57,7 +57,7 @@ public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSing } @Test - public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix() { + void shouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix() { String prefix = "prefix."; String key = "key"; diff --git a/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java index 6fe10b8..b571ec5 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java @@ -23,10 +23,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -public class PropertiesBasedValueSourceTest { +class PropertiesBasedValueSourceTest { @Test - public void testPropertyShouldReturnValueFromProperties() { + void propertyShouldReturnValueFromProperties() { Properties props = new Properties(); String key = "key"; @@ -40,7 +40,7 @@ public void testPropertyShouldReturnValueFromProperties() { } @Test - public void testPropertyShouldReturnNullWhenPropertyMissing() { + void propertyShouldReturnNullWhenPropertyMissing() { Properties props = new Properties(); String key = "key"; diff --git a/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java index f2debe4..d701387 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java @@ -1,22 +1,5 @@ package org.codehaus.plexus.interpolation; -/* - * Copyright 2001-2008 Codehaus Foundation. - * - * 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 - * - * 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. - */ - -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -31,7 +14,7 @@ public class RegexBasedInterpolatorTest { @BeforeEach - public void setUp() { + void setUp() { EnvarBasedValueSource.resetStatics(); } @@ -40,7 +23,7 @@ public String getVar() { } @Test - public void testShouldFailOnExpressionCycle() { + void shouldFailOnExpressionCycle() { Properties props = new Properties(); props.setProperty("key1", "${key2}"); props.setProperty("key2", "${key1}"); @@ -58,7 +41,7 @@ public void testShouldFailOnExpressionCycle() { } @Test - public void testShouldResolveByMy_getVar_Method() throws InterpolationException { + void shouldResolveByMyGetVarMethod() throws Exception { RegexBasedInterpolator rbi = new RegexBasedInterpolator(); rbi.addValueSource(new ObjectBasedValueSource(this)); String result = rbi.interpolate("this is a ${this.var}", "this"); @@ -67,10 +50,10 @@ public void testShouldResolveByMy_getVar_Method() throws InterpolationException } @Test - public void testShouldResolveByContextValue() throws InterpolationException { + void shouldResolveByContextValue() throws Exception { RegexBasedInterpolator rbi = new RegexBasedInterpolator(); - Map context = new HashMap(); + Map context = new HashMap(); context.put("var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); @@ -81,7 +64,7 @@ public void testShouldResolveByContextValue() throws InterpolationException { } @Test - public void testDelimitersPassedToValueSource() throws InterpolationException { + void delimitersPassedToValueSource() throws Exception { RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); interpolator.addValueSource(new AbstractValueSource(false) { @@ -103,13 +86,11 @@ public Object getValue(String expression) { } @Test - public void testShouldResolveByEnvar() throws IOException, InterpolationException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("SOME_ENV", "variable"); - return map; - } + void shouldResolveByEnvar() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("SOME_ENV", "variable"); + return map; }); RegexBasedInterpolator rbi = new RegexBasedInterpolator(); @@ -122,10 +103,10 @@ public Map getEnvMap() { } @Test - public void testUseAlternateRegex() throws Exception { + void useAlternateRegex() throws Exception { RegexBasedInterpolator rbi = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@"); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); @@ -136,10 +117,10 @@ public void testUseAlternateRegex() throws Exception { } @Test - public void testNPEFree() throws Exception { + void npeFree() throws Exception { RegexBasedInterpolator rbi = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@"); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); @@ -150,19 +131,15 @@ public void testNPEFree() throws Exception { } @Test - public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException { + void usePostProcessorDoesNotChangeValue() throws Exception { RegexBasedInterpolator rbi = new RegexBasedInterpolator(); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("test.var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); - rbi.addPostProcessor(new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return null; - } - }); + rbi.addPostProcessor((expression, value) -> null); String result = rbi.interpolate("this is a ${test.var}", ""); @@ -170,7 +147,7 @@ public Object execute(String expression, Object value) { } @Test - public void testUsePostProcessor_ChangesValue() throws InterpolationException { + void usePostProcessorChangesValue() throws Exception { int loopNumber = 200000; @@ -178,16 +155,12 @@ public void testUsePostProcessor_ChangesValue() throws InterpolationException { RegexBasedInterpolator rbi = new RegexBasedInterpolator(); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("test.var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); - rbi.addPostProcessor(new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return value + "2"; - } - }); + rbi.addPostProcessor((expression, value) -> value + "2"); for (int i = 0, number = loopNumber; i < number; i++) { @@ -205,11 +178,7 @@ public Object execute(String expression, Object value) { rbi = new RegexBasedInterpolator(true); - rbi.addPostProcessor(new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return value + "2"; - } - }); + rbi.addPostProcessor((expression, value) -> value + "2"); rbi.addValueSource(new MapBasedValueSource(context)); @@ -225,8 +194,8 @@ public Object execute(String expression, Object value) { } @Test - public void testCacheAnswersTrue() throws InterpolationException { - Map ctx = new HashMap(); + void cacheAnswersTrue() throws Exception { + Map ctx = new HashMap<>(); ctx.put("key", "value"); final int[] valueSourceCallCount = {0}; @@ -260,8 +229,8 @@ public Object getValue(String expression) { } @Test - public void testCacheAnswersFalse() throws InterpolationException { - Map ctx = new HashMap(); + void cacheAnswersFalse() throws Exception { + Map ctx = new HashMap<>(); ctx.put("key", "value"); final int[] valueSourceCallCount = {0}; diff --git a/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java index e1fa00a..e96c91c 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java @@ -1,22 +1,5 @@ package org.codehaus.plexus.interpolation; -/* - * Copyright 2001-2008 Codehaus Foundation. - * - * 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 - * - * 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. - */ - -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -34,12 +17,12 @@ public class StringSearchInterpolatorTest { @BeforeEach - public void setUp() { + void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - public void testLongDelimitersInContext() throws InterpolationException { + void longDelimitersInContext() throws Exception { String src = "This is a test.label for long delimiters in context."; String result = "This is a test for long delimiters in context."; @@ -53,7 +36,7 @@ public void testLongDelimitersInContext() throws InterpolationException { } @Test - public void testLongDelimitersWithNoStartContext() throws InterpolationException { + void longDelimitersWithNoStartContext() throws Exception { String src = "test.label for long delimiters in context."; String result = "test for long delimiters in context."; @@ -67,7 +50,7 @@ public void testLongDelimitersWithNoStartContext() throws InterpolationException } @Test - public void testLongDelimitersWithNoEndContext() throws InterpolationException { + void longDelimitersWithNoEndContext() throws Exception { String src = "This is a test.label"; String result = "This is a test"; @@ -81,7 +64,7 @@ public void testLongDelimitersWithNoEndContext() throws InterpolationException { } @Test - public void testLongDelimitersWithNoContext() throws InterpolationException { + void longDelimitersWithNoContext() throws Exception { String src = "test.label"; String result = "test"; @@ -95,7 +78,7 @@ public void testLongDelimitersWithNoContext() throws InterpolationException { } @Test - public void testLongDelimitersPassedToValueSource() throws InterpolationException { + void longDelimitersPassedToValueSource() throws Exception { String src = "test"; StringSearchInterpolator interpolator = new StringSearchInterpolator("", ""); @@ -119,7 +102,7 @@ public Object getValue(String expression) { } @Test - public void testSimpleSubstitution() throws InterpolationException { + void simpleSubstitution() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -130,7 +113,7 @@ public void testSimpleSubstitution() throws InterpolationException { } @Test - public void testSimpleSubstitution_TwoExpressions() throws InterpolationException { + void simpleSubstitutionTwoExpressions() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); @@ -142,7 +125,7 @@ public void testSimpleSubstitution_TwoExpressions() throws InterpolationExceptio } @Test - public void testBrokenExpression_LeaveItAlone() throws InterpolationException { + void brokenExpressionLeaveItAlone() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -153,7 +136,7 @@ public void testBrokenExpression_LeaveItAlone() throws InterpolationException { } @Test - public void testShouldFailOnExpressionCycle() { + void shouldFailOnExpressionCycle() { Properties props = new Properties(); props.setProperty("key1", "${key2}"); props.setProperty("key2", "${key1}"); @@ -171,7 +154,7 @@ public void testShouldFailOnExpressionCycle() { } @Test - public void testShouldResolveByUsingObject_List_Map() throws InterpolationException { + void shouldResolveByUsingObjectListMap() throws Exception { StringSearchInterpolator rbi = new StringSearchInterpolator(); rbi.addValueSource(new ObjectBasedValueSource(this)); String result = @@ -181,10 +164,10 @@ public void testShouldResolveByUsingObject_List_Map() throws InterpolationExcept } @Test - public void testShouldResolveByContextValue() throws InterpolationException { + void shouldResolveByContextValue() throws Exception { StringSearchInterpolator rbi = new StringSearchInterpolator(); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); @@ -195,14 +178,12 @@ public void testShouldResolveByContextValue() throws InterpolationException { } @Test - public void testShouldResolveByEnvar() throws IOException, InterpolationException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("SOME_ENV", "variable"); - map.put("OTHER_ENV", "other variable"); - return map; - } + void shouldResolveByEnvar() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("SOME_ENV", "variable"); + map.put("OTHER_ENV", "other variable"); + return map; }); StringSearchInterpolator rbi = new StringSearchInterpolator(); @@ -215,19 +196,15 @@ public Map getEnvMap() { } @Test - public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException { + void usePostProcessorDoesNotChangeValue() throws Exception { StringSearchInterpolator rbi = new StringSearchInterpolator(); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("test.var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); - rbi.addPostProcessor(new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return null; - } - }); + rbi.addPostProcessor((expression, value) -> null); String result = rbi.interpolate("this is a ${test.var}"); @@ -235,20 +212,16 @@ public Object execute(String expression, Object value) { } @Test - public void testUsePostProcessor_ChangesValue() throws InterpolationException { + void usePostProcessorChangesValue() throws Exception { StringSearchInterpolator rbi = new StringSearchInterpolator(); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("test.var", "testVar"); rbi.addValueSource(new MapBasedValueSource(context)); - rbi.addPostProcessor(new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return value + "2"; - } - }); + rbi.addPostProcessor((expression, value) -> value + "2"); String result = rbi.interpolate("this is a ${test.var}"); @@ -256,7 +229,7 @@ public Object execute(String expression, Object value) { } @Test - public void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException { + void simpleSubstitutionWithDefinedExpr() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -267,7 +240,7 @@ public void testSimpleSubstitutionWithDefinedExpr() throws InterpolationExceptio } @Test - public void testEscape() throws InterpolationException { + void escape() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -281,7 +254,7 @@ public void testEscape() throws InterpolationException { } @Test - public void testEscapeWithLongEscapeStr() throws InterpolationException { + void escapeWithLongEscapeStr() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -295,7 +268,7 @@ public void testEscapeWithLongEscapeStr() throws InterpolationException { } @Test - public void testEscapeWithLongEscapeStrAtStart() throws InterpolationException { + void escapeWithLongEscapeStrAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -309,7 +282,7 @@ public void testEscapeWithLongEscapeStrAtStart() throws InterpolationException { } @Test - public void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException { + void notEscapeWithLongEscapeStrAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -323,7 +296,7 @@ public void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationExceptio } @Test - public void testEscapeNotFailWithNullEscapeStr() throws InterpolationException { + void escapeNotFailWithNullEscapeStr() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -337,7 +310,7 @@ public void testEscapeNotFailWithNullEscapeStr() throws InterpolationException { } @Test - public void testOnlyEscapeExprAtStart() throws InterpolationException { + void onlyEscapeExprAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -351,7 +324,7 @@ public void testOnlyEscapeExprAtStart() throws InterpolationException { } @Test - public void testNotEscapeExprAtStart() throws InterpolationException { + void notEscapeExprAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -365,7 +338,7 @@ public void testNotEscapeExprAtStart() throws InterpolationException { } @Test - public void testEscapeExprAtStart() throws InterpolationException { + void escapeExprAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -379,7 +352,7 @@ public void testEscapeExprAtStart() throws InterpolationException { } @Test - public void testNPEFree() throws InterpolationException { + void npeFree() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -393,7 +366,7 @@ public void testNPEFree() throws InterpolationException { } @Test - public void testInterruptedInterpolate() throws InterpolationException { + void interruptedInterpolate() throws Exception { Interpolator interpolator = new StringSearchInterpolator(); RecursionInterceptor recursionInterceptor = new SimpleRecursionInterceptor(); final boolean[] error = new boolean[] {false}; @@ -431,7 +404,7 @@ public void clearFeedback() {} } @Test - public void testCacheAnswersTrue() throws InterpolationException { + void cacheAnswersTrue() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -470,7 +443,7 @@ public int getExistingCallCount() { } @Test - public void testCacheAnswersFalse() throws InterpolationException { + void cacheAnswersFalse() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -514,7 +487,7 @@ public Person[] getAnArray() { } public List getList() { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new Person("Gabriel")); list.add(new Person("testIndexedWithList")); list.add(new Person("Daniela")); @@ -522,13 +495,13 @@ public List getList() { } public Map getMap() { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("Key with spaces", new Person("testMap")); return map; } public static class Person { - private String name; + private final String name; public Person(String name) { this.name = name; 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 b6ff638..8ae7bd6 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java @@ -16,9 +16,7 @@ * limitations under the License. */ -import java.io.IOException; import java.util.HashMap; -import java.util.Map; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; import org.junit.jupiter.api.BeforeEach; @@ -28,21 +26,19 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -public class EnvarBasedValueSourceTest { +class EnvarBasedValueSourceTest { @BeforeEach - public void setUp() { + void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - void testNoArgConstructorIsCaseSensitive() throws IOException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("aVariable", "variable"); - return map; - } + void noArgConstructorIsCaseSensitive() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("aVariable", "variable"); + return map; }); EnvarBasedValueSource source = new EnvarBasedValueSource(); @@ -54,13 +50,11 @@ public Map getEnvMap() { } @Test - void testCaseInsensitive() throws IOException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("aVariable", "variable"); - return map; - } + void caseInsensitive() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("aVariable", "variable"); + return map; }); EnvarBasedValueSource source = new EnvarBasedValueSource(false); @@ -72,7 +66,7 @@ public Map getEnvMap() { } @Test - void testGetRealEnvironmentVariable() throws IOException { + void getRealEnvironmentVariable() throws Exception { OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource()); EnvarBasedValueSource source = new EnvarBasedValueSource(); 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 afef83e..2061736 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java @@ -15,7 +15,6 @@ * limitations under the License. */ -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -23,7 +22,6 @@ import java.util.Properties; import org.codehaus.plexus.interpolation.FixedInterpolatorValueSource; -import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.InterpolationPostProcessor; import org.codehaus.plexus.interpolation.StringSearchInterpolator; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; @@ -37,12 +35,12 @@ public class FixedStringSearchInterpolatorTest { @BeforeEach - public void setUp() { + void setUp() { EnvarBasedValueSource.resetStatics(); } @Test - void testLongDelimitersInContext() { + void longDelimitersInContext() { String src = "This is a test.label for long delimiters in context."; String result = "This is a test for long delimiters in context."; @@ -56,7 +54,7 @@ void testLongDelimitersInContext() { } @Test - void testLongDelimitersWithNoStartContext() { + void longDelimitersWithNoStartContext() { String src = "test.label for long delimiters in context."; String result = "test for long delimiters in context."; @@ -70,7 +68,7 @@ void testLongDelimitersWithNoStartContext() { } @Test - void testLongDelimitersWithNoEndContext() { + void longDelimitersWithNoEndContext() { String src = "This is a test.label"; String result = "This is a test"; @@ -84,7 +82,7 @@ void testLongDelimitersWithNoEndContext() { } @Test - void testLongDelimitersWithNoContext() { + void longDelimitersWithNoContext() { String src = "test.label"; String result = "test"; @@ -98,7 +96,7 @@ void testLongDelimitersWithNoContext() { } @Test - void testSimpleSubstitution() { + void simpleSubstitution() { Properties p = new Properties(); p.setProperty("key", "value"); @@ -108,7 +106,7 @@ void testSimpleSubstitution() { } @Test - void testSimpleSubstitution_TwoExpressions() { + void simpleSubstitutionTwoExpressions() { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); @@ -119,7 +117,7 @@ void testSimpleSubstitution_TwoExpressions() { } @Test - void testBrokenExpression_LeaveItAlone() { + void brokenExpressionLeaveItAlone() { Properties p = new Properties(); p.setProperty("key", "value"); @@ -129,7 +127,7 @@ void testBrokenExpression_LeaveItAlone() { } @Test - void testShouldFailOnExpressionCycle() { + void shouldFailOnExpressionCycle() { Properties props = new Properties(); props.setProperty("key1", "${key2}"); props.setProperty("key2", "${key1}"); @@ -143,7 +141,7 @@ void testShouldFailOnExpressionCycle() { } @Test - void testShouldResolveByUsingObject_List_Map() throws InterpolationException { + void shouldResolveByUsingObjectListMap() throws Exception { FixedStringSearchInterpolator rbi = create(new ObjectBasedValueSource(this)); String result = rbi.interpolate("this is a ${var} ${list[1].name} ${anArray[2].name} ${map(Key with spaces).name}"); @@ -152,9 +150,9 @@ void testShouldResolveByUsingObject_List_Map() throws InterpolationException { } @Test - void testShouldResolveByContextValue() throws InterpolationException { + void shouldResolveByContextValue() throws Exception { - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("var", "testVar"); FixedStringSearchInterpolator rbi = create(new MapBasedValueSource(context)); @@ -165,14 +163,12 @@ void testShouldResolveByContextValue() throws InterpolationException { } @Test - void testShouldResolveByEnvar() throws IOException, InterpolationException { - OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() { - public Map getEnvMap() { - HashMap map = new HashMap(); - map.put("SOME_ENV", "variable"); - map.put("OTHER_ENV", "other variable"); - return map; - } + void shouldResolveByEnvar() throws Exception { + OperatingSystemUtils.setEnvVarSource(() -> { + HashMap map = new HashMap<>(); + map.put("SOME_ENV", "variable"); + map.put("OTHER_ENV", "other variable"); + return map; }); FixedStringSearchInterpolator rbi = create(new EnvarBasedValueSource(false)); @@ -183,16 +179,12 @@ public Map getEnvMap() { } @Test - void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException { + void usePostProcessorDoesNotChangeValue() throws Exception { - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("test.var", "testVar"); - final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return null; - } - }; + InterpolationPostProcessor postProcessor = (expression, value) -> null; FixedStringSearchInterpolator rbi = create(new MapBasedValueSource(context)).withPostProcessor(postProcessor); @@ -202,16 +194,12 @@ public Object execute(String expression, Object value) { } @Test - void testUsePostProcessor_ChangesValue() throws InterpolationException { + void usePostProcessorChangesValue() throws Exception { - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("test.var", "testVar"); - final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor() { - public Object execute(String expression, Object value) { - return value + "2"; - } - }; + InterpolationPostProcessor postProcessor = (expression, value) -> value + "2"; FixedStringSearchInterpolator rbi = create(new MapBasedValueSource(context)).withPostProcessor(postProcessor); @@ -222,7 +210,7 @@ public Object execute(String expression, Object value) { } @Test - void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException { + void simpleSubstitutionWithDefinedExpr() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -232,7 +220,7 @@ void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException { } @Test - void testEscape() throws InterpolationException { + void escape() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -246,7 +234,7 @@ void testEscape() throws InterpolationException { } @Test - void testEscapeWithLongEscapeStr() throws InterpolationException { + void escapeWithLongEscapeStr() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -260,7 +248,7 @@ void testEscapeWithLongEscapeStr() throws InterpolationException { } @Test - void testEscapeWithLongEscapeStrAtStart() throws InterpolationException { + void escapeWithLongEscapeStrAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -274,7 +262,7 @@ void testEscapeWithLongEscapeStrAtStart() throws InterpolationException { } @Test - void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException { + void notEscapeWithLongEscapeStrAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -288,7 +276,7 @@ void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException { } @Test - void testEscapeNotFailWithNullEscapeStr() throws InterpolationException { + void escapeNotFailWithNullEscapeStr() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -302,7 +290,7 @@ void testEscapeNotFailWithNullEscapeStr() throws InterpolationException { } @Test - void testOnlyEscapeExprAtStart() throws InterpolationException { + void onlyEscapeExprAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -316,7 +304,7 @@ void testOnlyEscapeExprAtStart() throws InterpolationException { } @Test - void testNotEscapeExprAtStart() throws InterpolationException { + void notEscapeExprAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -330,7 +318,7 @@ void testNotEscapeExprAtStart() throws InterpolationException { } @Test - void testEscapeExprAtStart() throws InterpolationException { + void escapeExprAtStart() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -344,7 +332,7 @@ void testEscapeExprAtStart() throws InterpolationException { } @Test - void testNPEFree() throws InterpolationException { + void npeFree() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); @@ -358,18 +346,16 @@ void testNPEFree() throws InterpolationException { } @Test - void testInterruptedInterpolate() throws InterpolationException { + void interruptedInterpolate() throws Exception { final boolean[] error = new boolean[] {false}; - FixedValueSource valueSource = new FixedValueSource() { - public Object getValue(String expression, InterpolationState errorCollector) { - if (expression.equals("key")) { - if (error[0]) { - throw new IllegalStateException("broken"); - } - return "val"; - } else { - return null; + FixedValueSource valueSource = (expression, errorCollector) -> { + if (expression.equals("key")) { + if (error[0]) { + throw new IllegalStateException("broken"); } + return "val"; + } else { + return null; } }; @@ -400,7 +386,7 @@ public Person[] getAnArray() { } public List getList() { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new Person("Gabriel")); list.add(new Person("testIndexedWithList")); list.add(new Person("Daniela")); @@ -408,13 +394,13 @@ public List getList() { } public Map getMap() { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("Key with spaces", new Person("testMap")); return map; } public static class Person { - private String name; + private final String name; public Person(String name) { this.name = name; @@ -426,7 +412,7 @@ public String getName() { } @Test - void testLinkedInterpolators() { + void linkedInterpolators() { final String EXPR = "${test.label}AND${test2}"; final String EXPR2 = "${test.label}${test2.label}AND${test2}"; @@ -439,7 +425,7 @@ void testLinkedInterpolators() { } @Test - void testDominance() { + void dominance() { final String EXPR = "${test.label}AND${test2}"; final String EXPR2 = "${test.label}${test2.label}AND${test2}"; @@ -463,25 +449,21 @@ void unresolable_linked() { } @Test - void testCyclesWithLinked() { - assertThrows(InterpolationCycleException.class, () -> { - FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}")); - FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}")); - second.interpolate("${key2}"); - }); + void cyclesWithLinked() { + FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}")); + FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}")); + assertThrows(InterpolationCycleException.class, () -> second.interpolate("${key2}")); } @Test - void testCyclesWithLinked_betweenRootAndOther() { - assertThrows(InterpolationCycleException.class, () -> { - FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}")); - FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}")); - second.interpolate("${key1}"); - }); + void cyclesWithLinkedBetweenRootAndOther() { + FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}")); + FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}")); + assertThrows(InterpolationCycleException.class, () -> second.interpolate("${key1}")); } @Test - void fixedInjectedIntoRegular() throws InterpolationException { + void fixedInjectedIntoRegular() throws Exception { FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "v1")); Properties p = new Properties(); 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 95ab97d..bb2b026 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java @@ -46,14 +46,14 @@ * @author cstamas * */ -public class MultiDelimiterInterpolatorFilterReaderTest { +class MultiDelimiterInterpolatorFilterReaderTest { /* * 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 { - Map m = new HashMap(); + void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test"; @@ -65,8 +65,8 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() t * kenneyw@14-04-2005 Added test to check above fix. */ @Test - public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test, really"; @@ -75,8 +75,8 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Excep } @Test - public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedStartToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a $!test} again"; @@ -85,8 +85,8 @@ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { } @Test - public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test!} again"; @@ -95,8 +95,8 @@ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { } @Test - public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -106,8 +106,8 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep } @Test - public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -117,8 +117,8 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio } @Test - public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception { - Map m = new HashMap(); + void interpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -128,8 +128,8 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws } @Test - public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception { - Map m = new HashMap(); + void interpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -139,8 +139,8 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomS } @Test - public void testEscape() throws Exception { - Map m = new HashMap(); + void escape() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -150,8 +150,8 @@ public void testEscape() throws Exception { } @Test - public void testEscapeAtStart() throws Exception { - Map m = new HashMap(); + void escapeAtStart() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -161,8 +161,8 @@ public void testEscapeAtStart() throws Exception { } @Test - public void testEscapeOnlyAtStart() throws Exception { - Map m = new HashMap(); + void escapeOnlyAtStart() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -173,8 +173,8 @@ public void testEscapeOnlyAtStart() throws Exception { } @Test - public void testEscapeOnlyAtStartDefaultToken() throws Exception { - Map m = new HashMap(); + void escapeOnlyAtStartDefaultToken() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -185,15 +185,15 @@ public void testEscapeOnlyAtStartDefaultToken() throws Exception { } @Test - public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception { - List prefixes = new ArrayList(); + void shouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception { + List prefixes = new ArrayList<>(); prefixes.add("prefix1"); prefixes.add("prefix2"); RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("name", "${prefix2.name}"); String input = "${prefix1.name}"; @@ -217,14 +217,14 @@ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throw } @Test - public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception { - List prefixes = new ArrayList(); + void shouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception { + List prefixes = new ArrayList<>(); prefixes.add("prefix1"); RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false); - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("name", "${prefix1.name}"); String input = "${name}"; @@ -248,8 +248,8 @@ public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exc } @Test - public void testInterpolationWithMultipleTokenTypes() throws Exception { - Map m = new HashMap(); + void interpolationWithMultipleTokenTypes() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("otherName", "@name@"); @@ -259,8 +259,8 @@ public void testInterpolationWithMultipleTokenTypes() throws Exception { } @Test - public void testInterpolationWithMultipleTokenTypes_ReversedOrdering() throws Exception { - Map m = new HashMap(); + void interpolationWithMultipleTokenTypesReversedOrdering() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("otherName", "${name}"); @@ -273,11 +273,11 @@ public void testInterpolationWithMultipleTokenTypes_ReversedOrdering() throws Ex // // ---------------------------------------------------------------------- - private String interpolate(String input, Map context) throws Exception { + private String interpolate(String input, Map context) throws Exception { return interpolate(input, context, null); } - private String interpolate(String input, Map context, String escapeStr) throws Exception { + private String interpolate(String input, Map context, String escapeStr) throws Exception { Interpolator interpolator = new StringSearchInterpolator(); interpolator.addValueSource(new MapBasedValueSource(context)); @@ -298,7 +298,8 @@ private String interpolate(String input, Map context, String escapeStr) throws E return buf.toString(); } - private String interpolate(String input, Map context, String beginToken, String endToken) throws Exception { + private String interpolate(String input, Map context, String beginToken, String endToken) + throws Exception { StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken); interpolator.addValueSource(new MapBasedValueSource(context)); @@ -319,7 +320,7 @@ private String interpolate(String input, Map context, String beginToken, String return buf.toString(); } - private String interpolateMulti(String input, Map context, String[] specs) throws Exception { + private String interpolateMulti(String input, Map context, String[] specs) throws Exception { MultiDelimiterStringSearchInterpolator interp = new MultiDelimiterStringSearchInterpolator(); interp.addValueSource(new MapBasedValueSource(context)); 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 7b38a16..6f96f98 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java @@ -20,7 +20,6 @@ import java.util.Map; import org.codehaus.plexus.interpolation.AbstractValueSource; -import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.MapBasedValueSource; import org.codehaus.plexus.interpolation.ValueSource; import org.junit.jupiter.api.Test; @@ -28,11 +27,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -public class MultiDelimiterStringSearchInterpolatorTest { +class MultiDelimiterStringSearchInterpolatorTest { @Test - public void testInterpolationWithDifferentDelimiters() throws InterpolationException { - Map ctx = new HashMap(); + void interpolationWithDifferentDelimiters() throws Exception { + Map ctx = new HashMap<>(); ctx.put("name", "User"); ctx.put("otherName", "@name@"); @@ -49,9 +48,8 @@ public void testInterpolationWithDifferentDelimiters() throws InterpolationExcep } @Test - public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiterSequence() - throws InterpolationException { - Map ctx = new HashMap(); + void successiveInterpolationWithDifferentDelimitersReversedDelimiterSequence() throws Exception { + Map ctx = new HashMap<>(); ctx.put("name", "User"); ctx.put("otherName", "${name}"); @@ -68,8 +66,8 @@ public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiter } @Test - public void testInterpolationWithMultipleEscapes() throws InterpolationException { - Map ctx = new HashMap(); + void interpolationWithMultipleEscapes() throws Exception { + Map ctx = new HashMap<>(); ctx.put("name", "User"); ctx.put("otherName", "##${first} and #${last}"); @@ -86,8 +84,8 @@ public void testInterpolationWithMultipleEscapes() throws InterpolationException } @Test - public void testInterpolationWithMultipleEscapes2() throws InterpolationException { - Map ctx = new HashMap(); + void interpolationWithMultipleEscapes2() throws Exception { + Map ctx = new HashMap<>(); ctx.put("name", "User"); ctx.put("otherName", "#${first} and ##${last}"); @@ -104,8 +102,8 @@ public void testInterpolationWithMultipleEscapes2() throws InterpolationExceptio } @Test - public void testInterpolationWithMultipleEscapes3() throws InterpolationException { - Map ctx = new HashMap(); + void interpolationWithMultipleEscapes3() throws Exception { + Map ctx = new HashMap<>(); ctx.put("name", "User"); ctx.put("last", "beer"); ctx.put("otherName", "###${first} and ##${second} and ${last}"); @@ -123,7 +121,7 @@ public void testInterpolationWithMultipleEscapes3() throws InterpolationExceptio } @Test - public void testDelimitersPassedToValueSource() throws InterpolationException { + void delimitersPassedToValueSource() throws Exception { ValueSource vs = new AbstractValueSource(false) { @Override @@ -148,8 +146,8 @@ public Object getValue(String expression) { } @Test - public void testCacheAnswersTrue() throws InterpolationException { - Map ctx = new HashMap(); + void cacheAnswersTrue() throws Exception { + Map ctx = new HashMap<>(); ctx.put("key", "value"); final int[] valueSourceCallCount = {0}; @@ -180,8 +178,8 @@ public Object getValue(String expression) { } @Test - public void testCacheAnswersFalse() throws InterpolationException { - Map ctx = new HashMap(); + void cacheAnswersFalse() throws Exception { + Map ctx = new HashMap<>(); ctx.put("key", "value"); final int[] valueSourceCallCount = {0}; 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 08c8ad8..c207036 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java @@ -29,10 +29,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class FieldBasedObjectInterpolatorTest { +class FieldBasedObjectInterpolatorTest { @Test - public void testInterpolateStringArray() throws Exception { + void interpolateStringArray() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); @@ -49,7 +49,7 @@ public void testInterpolateStringArray() throws Exception { } @Test - public void testInterpolateObjectWithStringArrayField() throws Exception { + void interpolateObjectWithStringArrayField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); @@ -68,12 +68,12 @@ public void testInterpolateObjectWithStringArrayField() throws Exception { } @Test - public void testInterpolateObjectWithStringListField() throws Exception { + void interpolateObjectWithStringListField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); - List values = new ArrayList(); + List values = new ArrayList<>(); values.add("${key}"); values.add("${key2}"); @@ -89,12 +89,12 @@ public void testInterpolateObjectWithStringListField() throws Exception { } @Test - public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() throws Exception { + void interpolateObjectWithStringListFieldAndOneLiteralValue() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); - List values = new ArrayList(); + List values = new ArrayList<>(); values.add("key"); values.add("${key2}"); @@ -110,12 +110,12 @@ public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() throws } @Test - public void testInterpolateObjectWithUnmodifiableStringListField() throws Exception { + void interpolateObjectWithUnmodifiableStringListField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); - List values = Collections.unmodifiableList(Collections.singletonList("${key}")); + List values = Collections.singletonList("${key}"); ObjectWithListField obj = new ObjectWithListField(values); @@ -128,14 +128,14 @@ public void testInterpolateObjectWithUnmodifiableStringListField() throws Except } @Test - public void testInterpolateObjectWithStringArrayListField() throws Exception { + void interpolateObjectWithStringArrayListField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); p.setProperty("key3", "value3"); p.setProperty("key4", "value4"); - List values = new ArrayList(); + List values = new ArrayList<>(); values.add(new String[] {"${key}", "${key2}"}); values.add(new String[] {"${key3}", "${key4}"}); @@ -153,12 +153,12 @@ public void testInterpolateObjectWithStringArrayListField() throws Exception { } @Test - public void testInterpolateObjectWithStringToStringMapField() throws Exception { + void interpolateObjectWithStringToStringMapField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); - Map values = new HashMap(); + Map values = new HashMap<>(); values.put("key", "${key}"); values.put("key2", "${key2}"); @@ -174,12 +174,12 @@ public void testInterpolateObjectWithStringToStringMapField() throws Exception { } @Test - public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() throws Exception { + void interpolateObjectWithStringToStringMapFieldAndOneLiteralValue() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); - Map values = new HashMap(); + Map values = new HashMap<>(); values.put("key", "val"); values.put("key2", "${key2}"); @@ -195,12 +195,12 @@ public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() } @Test - public void testInterpolateObjectWithUnmodifiableStringToStringMapField() throws Exception { + void interpolateObjectWithUnmodifiableStringToStringMapField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); - Map values = Collections.unmodifiableMap(Collections.singletonMap("key", "${key}")); + Map values = Collections.singletonMap("key", "${key}"); ObjectWithMapField obj = new ObjectWithMapField(values); @@ -213,14 +213,14 @@ public void testInterpolateObjectWithUnmodifiableStringToStringMapField() throws } @Test - public void testInterpolateObjectWithStringToStringArrayMapField() throws Exception { + void interpolateObjectWithStringToStringArrayMapField() throws Exception { Properties p = new Properties(); p.setProperty("key", "value"); p.setProperty("key2", "value2"); p.setProperty("key3", "value3"); p.setProperty("key4", "value4"); - Map values = new HashMap(); + Map values = new HashMap<>(); values.put("key", new String[] {"${key}", "${key2}"}); values.put("key2", new String[] {"${key3}", "${key4}"}); 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 d788f63..e47766c 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java @@ -19,9 +19,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class StringUtilsTest { +class StringUtilsTest { @Test - public void testCapitalizeFirstLetter() throws Exception { + void capitalizeFirstLetter() throws Exception { assertEquals("Abc", StringUtils.capitalizeFirstLetter("abc")); assertEquals("\u00cdce", StringUtils.capitalizeFirstLetter("\u00edce")); assertEquals("X", StringUtils.capitalizeFirstLetter("x"));