Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, String> getEnvMap() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("aVariable", "variable");
return map;
}
void noArgConstructorIsCaseSensitive() throws Exception {
OperatingSystemUtils.setEnvVarSource(() -> {
HashMap<String, String> map = new HashMap<>();
map.put("aVariable", "variable");
return map;
});

EnvarBasedValueSource source = new EnvarBasedValueSource();
Expand All @@ -54,13 +34,11 @@ public Map<String, String> getEnvMap() {
}

@Test
void testCaseInsensitive() throws IOException {
OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
public Map<String, String> getEnvMap() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("aVariable", "variable");
return map;
}
void caseInsensitive() throws Exception {
OperatingSystemUtils.setEnvVarSource(() -> {
HashMap<String, String> map = new HashMap<>();
map.put("aVariable", "variable");
return map;
});

EnvarBasedValueSource source = new EnvarBasedValueSource(false);
Expand All @@ -72,7 +50,7 @@ public Map<String, String> getEnvMap() {
}

@Test
void testGetRealEnvironmentVariable() throws IOException {
void getRealEnvironmentVariable() throws Exception {
OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource());

EnvarBasedValueSource source = new EnvarBasedValueSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
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());
assertEquals("'test' not resolved", valueSource.getFeedback().iterator().next());
}

@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());
Expand All @@ -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")));
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> m = new HashMap<>();
m.put("test", "TestValue");

String testStr = "This is a ${test";
Expand All @@ -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<String, String> m = new HashMap<>();
m.put("test", "TestValue");

String testStr = "This is a ${test, really";
Expand All @@ -70,8 +70,8 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Excep
}

@Test
public void testShouldNotInterpolateWithMalformedStartToken() throws Exception {
Map m = new HashMap();
void shouldNotInterpolateWithMalformedStartToken() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("test", "testValue");

String foo = "This is a $!test} again";
Expand All @@ -80,8 +80,8 @@ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception {
}

@Test
public void testShouldNotInterpolateWithMalformedEndToken() throws Exception {
Map m = new HashMap();
void shouldNotInterpolateWithMalformedEndToken() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("test", "testValue");

String foo = "This is a ${test!} again";
Expand All @@ -90,8 +90,8 @@ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception {
}

@Test
public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
Map m = new HashMap();
void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -101,8 +101,8 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep
}

@Test
public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
Map m = new HashMap();
void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -112,8 +112,8 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio
}

@Test
public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
Map m = new HashMap();
void interpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -123,8 +123,8 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws
}

@Test
public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
Map m = new HashMap();
void interpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -134,8 +134,8 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomS
}

@Test
public void testEscape() throws Exception {
Map m = new HashMap();
void escape() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -145,8 +145,8 @@ public void testEscape() throws Exception {
}

@Test
public void testEscapeAtStart() throws Exception {
Map m = new HashMap();
void escapeAtStart() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -156,8 +156,8 @@ public void testEscapeAtStart() throws Exception {
}

@Test
public void testEscapeOnlyAtStart() throws Exception {
Map m = new HashMap();
void escapeOnlyAtStart() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -168,8 +168,8 @@ public void testEscapeOnlyAtStart() throws Exception {
}

@Test
public void testEscapeOnlyAtStartDefaultToken() throws Exception {
Map m = new HashMap();
void escapeOnlyAtStartDefaultToken() throws Exception {
Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");

Expand All @@ -180,15 +180,15 @@ public void testEscapeOnlyAtStartDefaultToken() throws Exception {
}

@Test
public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
List prefixes = new ArrayList();
void shouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
List<String> prefixes = new ArrayList<>();

prefixes.add("prefix1");
prefixes.add("prefix2");

RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);

Map context = new HashMap();
Map<String, String> context = new HashMap<>();
context.put("name", "${prefix2.name}");

String input = "${prefix1.name}";
Expand All @@ -211,14 +211,14 @@ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throw
}

@Test
public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
List prefixes = new ArrayList();
void shouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
List<String> prefixes = new ArrayList<>();

prefixes.add("prefix1");

RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);

Map context = new HashMap();
Map<String, String> context = new HashMap<>();
context.put("name", "${prefix1.name}");

String input = "${name}";
Expand All @@ -244,11 +244,11 @@ public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exc
//
// ----------------------------------------------------------------------

private String interpolate(String input, Map context) throws Exception {
private String interpolate(String input, Map<String, String> 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<String, String> context, String escapeStr) throws Exception {
Interpolator interpolator = new StringSearchInterpolator();

interpolator.addValueSource(new MapBasedValueSource(context));
Expand All @@ -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<String, String> context, String beginToken, String endToken)
throws Exception {
StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken);

interpolator.addValueSource(new MapBasedValueSource(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."));

Expand All @@ -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";

Expand All @@ -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";
Expand Down
Loading