methods, Class>
* Returns true if the supplied method is applicable to actual
* argument types.
*/
- private static boolean isApplicable( Method method, Class>[] classes )
- {
+ private static boolean isApplicable(Method method, Class>[] classes) {
Class>[] methodArgs = method.getParameterTypes();
- if ( methodArgs.length != classes.length )
- {
+ if (methodArgs.length != classes.length) {
return false;
}
- for ( int i = 0; i < classes.length; ++i )
- {
- if ( !isMethodInvocationConvertible( methodArgs[i], classes[i] ) )
- {
+ for (int i = 0; i < classes.length; ++i) {
+ if (!isMethodInvocationConvertible(methodArgs[i], classes[i])) {
return false;
}
}
@@ -332,13 +295,11 @@ private static boolean isApplicable( Method method, Class>[] classes )
* type or an object type of a primitive type that can be converted to
* the formal type.
*/
- private static boolean isMethodInvocationConvertible( Class> formal, Class> actual )
- {
+ private static boolean isMethodInvocationConvertible(Class> formal, Class> actual) {
/*
* if it's a null, it means the arg was null
*/
- if ( actual == null && !formal.isPrimitive() )
- {
+ if (actual == null && !formal.isPrimitive()) {
return true;
}
@@ -346,8 +307,7 @@ private static boolean isMethodInvocationConvertible( Class> formal, Class>
* Check for identity or widening reference conversion
*/
- if ( actual != null && formal.isAssignableFrom( actual ) )
- {
+ if (actual != null && formal.isAssignableFrom(actual)) {
return true;
}
@@ -356,41 +316,39 @@ private static boolean isMethodInvocationConvertible( Class> formal, Class>
* actual parameters are never primitives.
*/
- if ( formal.isPrimitive() )
- {
- if ( formal == Boolean.TYPE )
- {
+ if (formal.isPrimitive()) {
+ if (formal == Boolean.TYPE) {
return actual == Boolean.class;
}
- if ( formal == Character.TYPE )
- {
+ if (formal == Character.TYPE) {
return actual == Character.class;
}
- if ( formal == Byte.TYPE )
- {
+ if (formal == Byte.TYPE) {
return actual == Byte.class;
}
- if ( formal == Short.TYPE )
- {
+ if (formal == Short.TYPE) {
return actual == Short.class || actual == Byte.class;
}
- if ( formal == Integer.TYPE )
- {
+ if (formal == Integer.TYPE) {
return actual == Integer.class || actual == Short.class || actual == Byte.class;
}
- if ( formal == Long.TYPE )
- {
+ if (formal == Long.TYPE) {
return actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class;
}
- if ( formal == Float.TYPE )
- {
- return actual == Float.class || actual == Long.class || actual == Integer.class
- || actual == Short.class || actual == Byte.class;
+ if (formal == Float.TYPE) {
+ return actual == Float.class
+ || actual == Long.class
+ || actual == Integer.class
+ || actual == Short.class
+ || actual == Byte.class;
}
- if ( formal == Double.TYPE )
- {
- return actual == Double.class || actual == Float.class || actual == Long.class
- || actual == Integer.class || actual == Short.class || actual == Byte.class;
+ if (formal == Double.TYPE) {
+ return actual == Double.class
+ || actual == Float.class
+ || actual == Long.class
+ || actual == Integer.class
+ || actual == Short.class
+ || actual == Byte.class;
}
}
@@ -411,13 +369,11 @@ private static boolean isMethodInvocationConvertible( Class> formal, Class>
* or formal and actual are both primitive types and actual can be
* subject to widening conversion to formal.
*/
- private static boolean isStrictMethodInvocationConvertible( Class> formal, Class> actual )
- {
+ private static boolean isStrictMethodInvocationConvertible(Class> formal, Class> actual) {
/*
* we shouldn't get a null into, but if so
*/
- if ( actual == null && !formal.isPrimitive() )
- {
+ if (actual == null && !formal.isPrimitive()) {
return true;
}
@@ -425,8 +381,7 @@ private static boolean isStrictMethodInvocationConvertible( Class> formal, Cla
* Check for identity or widening reference conversion
*/
- if ( formal.isAssignableFrom( actual ) )
- {
+ if (formal.isAssignableFrom(actual)) {
return true;
}
@@ -434,28 +389,25 @@ private static boolean isStrictMethodInvocationConvertible( Class> formal, Cla
* Check for widening primitive conversion.
*/
- if ( formal.isPrimitive() )
- {
- if ( formal == Short.TYPE )
- {
+ if (formal.isPrimitive()) {
+ if (formal == Short.TYPE) {
return actual == Byte.TYPE;
}
- if ( formal == Integer.TYPE )
- {
+ if (formal == Integer.TYPE) {
return actual == Short.TYPE || actual == Byte.TYPE;
}
- if ( formal == Long.TYPE )
- {
+ if (formal == Long.TYPE) {
return actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE;
}
- if ( formal == Float.TYPE )
- {
+ if (formal == Float.TYPE) {
return actual == Long.TYPE || actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE;
}
- if ( formal == Double.TYPE )
- {
- return actual == Float.TYPE || actual == Long.TYPE || actual == Integer.TYPE || actual == Short.TYPE
- || actual == Byte.TYPE;
+ if (formal == Double.TYPE) {
+ return actual == Float.TYPE
+ || actual == Long.TYPE
+ || actual == Integer.TYPE
+ || actual == Short.TYPE
+ || actual == Byte.TYPE;
}
}
return false;
diff --git a/src/main/java/org/codehaus/plexus/interpolation/reflection/ReflectionValueExtractor.java b/src/main/java/org/codehaus/plexus/interpolation/reflection/ReflectionValueExtractor.java
index 4213732..c9db516 100644
--- a/src/main/java/org/codehaus/plexus/interpolation/reflection/ReflectionValueExtractor.java
+++ b/src/main/java/org/codehaus/plexus/interpolation/reflection/ReflectionValueExtractor.java
@@ -15,8 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import org.codehaus.plexus.interpolation.util.StringUtils;
-
import java.lang.ref.WeakReference;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
@@ -25,6 +23,8 @@
import java.util.Map;
import java.util.WeakHashMap;
+import org.codehaus.plexus.interpolation.util.StringUtils;
+
/**
* NOTE: This class was copied from plexus-utils, to allow this library to stand completely self-contained.
* Using simple dotted expressions extract the values from a MavenProject instance, For example we might want to extract
@@ -32,8 +32,7 @@
*
* @author Jason van Zyl
*/
-public class ReflectionValueExtractor
-{
+public class ReflectionValueExtractor {
private static final Class>[] CLASS_ARGS = new Class[0];
private static final Object[] OBJECT_ARGS = new Object[0];
@@ -43,7 +42,7 @@ public class ReflectionValueExtractor
* space overflows due to retention of discarded classloaders.
*/
private static final Map, WeakReference> classMaps =
- new WeakHashMap, WeakReference>();
+ new WeakHashMap, WeakReference>();
static final int EOF = -1;
@@ -57,79 +56,65 @@ public class ReflectionValueExtractor
static final char MAPPED_END = ')';
- static class Tokenizer
- {
+ static class Tokenizer {
final String expression;
int idx;
- public Tokenizer( String expression )
- {
+ public Tokenizer(String expression) {
this.expression = expression;
}
- public int peekChar()
- {
- return idx < expression.length() ? expression.charAt( idx ) : EOF;
+ public int peekChar() {
+ return idx < expression.length() ? expression.charAt(idx) : EOF;
}
- public int skipChar()
- {
- return idx < expression.length() ? expression.charAt( idx++ ) : EOF;
+ public int skipChar() {
+ return idx < expression.length() ? expression.charAt(idx++) : EOF;
}
- public String nextToken( char delimiter )
- {
+ public String nextToken(char delimiter) {
int start = idx;
- while ( idx < expression.length() && delimiter != expression.charAt( idx ) )
- {
+ while (idx < expression.length() && delimiter != expression.charAt(idx)) {
idx++;
}
// delimiter MUST be present
- if ( idx <= start || idx >= expression.length() )
- {
+ if (idx <= start || idx >= expression.length()) {
return null;
}
- return expression.substring( start, idx++ );
+ return expression.substring(start, idx++);
}
- public String nextPropertyName()
- {
+ public String nextPropertyName() {
final int start = idx;
- while ( idx < expression.length() && Character.isJavaIdentifierPart( expression.charAt( idx ) ) )
- {
+ while (idx < expression.length() && Character.isJavaIdentifierPart(expression.charAt(idx))) {
idx++;
}
// property name does not require delimiter
- if ( idx <= start || idx > expression.length() )
- {
+ if (idx <= start || idx > expression.length()) {
return null;
}
- return expression.substring( start, idx );
+ return expression.substring(start, idx);
}
- public int getPosition()
- {
+ public int getPosition() {
return idx < expression.length() ? idx : EOF;
}
// to make tokenizer look pretty in debugger
@Override
- public String toString()
- {
- return idx < expression.length() ? expression.substring( idx ) : "";
+ public String toString() {
+ return idx < expression.length() ? expression.substring(idx) : "";
}
}
- private ReflectionValueExtractor()
- {
- }
+ private ReflectionValueExtractor() {}
/**
*
@@ -142,16 +127,14 @@ private ReflectionValueExtractor()
*
mapped properties should be contains (\\w+)\\((.+)\\)
pattern, i.e.
* "user.addresses(myAddress).street"
*
- *
+ *
* @param expression not null expression
* @param root not null object
* @return the object defined by the expression
* @throws Exception if any
*/
- public static Object evaluate( String expression, Object root )
- throws Exception
- {
- return evaluate( expression, root, true );
+ public static Object evaluate(String expression, Object root) throws Exception {
+ return evaluate(expression, root, true);
}
/**
@@ -165,7 +148,7 @@ public static Object evaluate( String expression, Object root )
* mapped properties should be contains (\\w+)\\((.+)\\)
pattern, i.e.
* "user.addresses(myAddress).street"
*
- *
+ *
* @param expression not null expression
* @param root not null object
* @param trimRootToken trim the token or not.
@@ -173,9 +156,7 @@ public static Object evaluate( String expression, Object root )
* @throws Exception if any
*/
// TODO: don't throw Exception
- public static Object evaluate( String expression, final Object root, final boolean trimRootToken )
- throws Exception
- {
+ public static Object evaluate(String expression, final Object root, final boolean trimRootToken) throws Exception {
Object value = root;
// ----------------------------------------------------------------------
@@ -183,45 +164,47 @@ public static Object evaluate( String expression, final Object root, final boole
// MavenProject instance.
// ----------------------------------------------------------------------
- if ( expression == null || "".equals( expression.trim() )
- || !Character.isJavaIdentifierStart( expression.charAt( 0 ) ) )
- {
+ if (expression == null
+ || "".equals(expression.trim())
+ || !Character.isJavaIdentifierStart(expression.charAt(0))) {
return null;
}
- boolean hasDots = expression.indexOf( PROPERTY_START ) >= 0;
+ boolean hasDots = expression.indexOf(PROPERTY_START) >= 0;
final Tokenizer tokenizer;
- if ( trimRootToken && hasDots )
- {
- tokenizer = new Tokenizer( expression );
+ if (trimRootToken && hasDots) {
+ tokenizer = new Tokenizer(expression);
tokenizer.nextPropertyName();
- if ( tokenizer.getPosition() == EOF )
- {
+ if (tokenizer.getPosition() == EOF) {
return null;
}
- }
- else
- {
- tokenizer = new Tokenizer( "." + expression );
+ } else {
+ tokenizer = new Tokenizer("." + expression);
}
int propertyPosition = tokenizer.getPosition();
- while ( value != null && tokenizer.peekChar() != EOF )
- {
- switch ( tokenizer.skipChar() )
- {
+ while (value != null && tokenizer.peekChar() != EOF) {
+ switch (tokenizer.skipChar()) {
case INDEXED_START:
- value = getIndexedValue( expression, propertyPosition, tokenizer.getPosition(), value,
- tokenizer.nextToken( INDEXED_END ) );
+ value = getIndexedValue(
+ expression,
+ propertyPosition,
+ tokenizer.getPosition(),
+ value,
+ tokenizer.nextToken(INDEXED_END));
break;
case MAPPED_START:
- value = getMappedValue( expression, propertyPosition, tokenizer.getPosition(), value,
- tokenizer.nextToken( MAPPED_END ) );
+ value = getMappedValue(
+ expression,
+ propertyPosition,
+ tokenizer.getPosition(),
+ value,
+ tokenizer.nextToken(MAPPED_END));
break;
case PROPERTY_START:
propertyPosition = tokenizer.getPosition();
- value = getPropertyValue( value, tokenizer.nextPropertyName() );
+ value = getPropertyValue(value, tokenizer.nextPropertyName());
break;
default:
// could not parse expression
@@ -232,124 +215,102 @@ public static Object evaluate( String expression, final Object root, final boole
return value;
}
- private static Object getMappedValue( final String expression, final int from, final int to, final Object value,
- final String key )
- throws Exception
- {
- if ( value == null || key == null )
- {
+ private static Object getMappedValue(
+ final String expression, final int from, final int to, final Object value, final String key)
+ throws Exception {
+ if (value == null || key == null) {
return null;
}
- if ( value instanceof Map )
- {
- Object[] localParams = new Object[] { key };
- ClassMap classMap = getClassMap( value.getClass() );
- Method method = classMap.findMethod( "get", localParams );
- return method.invoke( value, localParams );
+ if (value instanceof Map) {
+ Object[] localParams = new Object[] {key};
+ ClassMap classMap = getClassMap(value.getClass());
+ Method method = classMap.findMethod("get", localParams);
+ return method.invoke(value, localParams);
}
- final String message =
- String.format( "The token '%s' at position '%d' refers to a java.util.Map, but the value seems is an instance of '%s'",
- expression.subSequence( from, to ), from, value.getClass() );
+ final String message = String.format(
+ "The token '%s' at position '%d' refers to a java.util.Map, but the value seems is an instance of '%s'",
+ expression.subSequence(from, to), from, value.getClass());
- throw new Exception( message );
+ throw new Exception(message);
}
- private static Object getIndexedValue( final String expression, final int from, final int to, final Object value,
- final String indexStr )
- throws Exception
- {
- try
- {
- int index = Integer.parseInt( indexStr );
-
- if ( value.getClass().isArray() )
- {
- return Array.get( value, index );
+ private static Object getIndexedValue(
+ final String expression, final int from, final int to, final Object value, final String indexStr)
+ throws Exception {
+ try {
+ int index = Integer.parseInt(indexStr);
+
+ if (value.getClass().isArray()) {
+ return Array.get(value, index);
}
- if ( value instanceof List )
- {
- ClassMap classMap = getClassMap( value.getClass() );
+ if (value instanceof List) {
+ ClassMap classMap = getClassMap(value.getClass());
// use get method on List interface
- Object[] localParams = new Object[] { index };
- Method method = classMap.findMethod( "get", localParams );
- return method.invoke( value, localParams );
+ Object[] localParams = new Object[] {index};
+ Method method = classMap.findMethod("get", localParams);
+ return method.invoke(value, localParams);
}
- }
- catch ( NumberFormatException e )
- {
+ } catch (NumberFormatException e) {
return null;
- }
- catch ( InvocationTargetException e )
- {
+ } catch (InvocationTargetException e) {
// catch array index issues gracefully, otherwise release
- if ( e.getCause() instanceof IndexOutOfBoundsException )
- {
+ if (e.getCause() instanceof IndexOutOfBoundsException) {
return null;
}
throw e;
}
- final String message =
- String.format( "The token '%s' at position '%d' refers to a java.util.List or an array, but the value seems is an instance of '%s'",
- expression.subSequence( from, to ), from, value.getClass() );
+ final String message = String.format(
+ "The token '%s' at position '%d' refers to a java.util.List or an array, but the value seems is an instance of '%s'",
+ expression.subSequence(from, to), from, value.getClass());
- throw new Exception( message );
+ throw new Exception(message);
}
- private static Object getPropertyValue( Object value, String property )
- throws Exception
- {
- if ( value == null || property == null )
- {
+ private static Object getPropertyValue(Object value, String property) throws Exception {
+ if (value == null || property == null) {
return null;
}
- ClassMap classMap = getClassMap( value.getClass() );
- String methodBase = StringUtils.capitalizeFirstLetter( property );
+ ClassMap classMap = getClassMap(value.getClass());
+ String methodBase = StringUtils.capitalizeFirstLetter(property);
String methodName = "get" + methodBase;
- Method method = classMap.findMethod( methodName, CLASS_ARGS );
+ Method method = classMap.findMethod(methodName, CLASS_ARGS);
- if ( method == null )
- {
+ if (method == null) {
// perhaps this is a boolean property??
methodName = "is" + methodBase;
- method = classMap.findMethod( methodName, CLASS_ARGS );
+ method = classMap.findMethod(methodName, CLASS_ARGS);
}
- if ( method == null )
- {
+ if (method == null) {
return null;
}
- try
- {
- return method.invoke( value, OBJECT_ARGS );
- }
- catch ( InvocationTargetException e )
- {
+ try {
+ return method.invoke(value, OBJECT_ARGS);
+ } catch (InvocationTargetException e) {
throw e;
}
}
- private static ClassMap getClassMap( Class> clazz )
- {
+ private static ClassMap getClassMap(Class> clazz) {
- WeakReference softRef = classMaps.get( clazz );
+ WeakReference softRef = classMaps.get(clazz);
ClassMap classMap;
- if ( softRef == null || ( classMap = softRef.get() ) == null )
- {
- classMap = new ClassMap( clazz );
+ if (softRef == null || (classMap = softRef.get()) == null) {
+ classMap = new ClassMap(clazz);
- classMaps.put( clazz, new WeakReference( classMap ) );
+ classMaps.put(clazz, new WeakReference(classMap));
}
return classMap;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/codehaus/plexus/interpolation/util/StringUtils.java b/src/main/java/org/codehaus/plexus/interpolation/util/StringUtils.java
index 507cbf9..1852725 100644
--- a/src/main/java/org/codehaus/plexus/interpolation/util/StringUtils.java
+++ b/src/main/java/org/codehaus/plexus/interpolation/util/StringUtils.java
@@ -59,8 +59,7 @@
*
* @author jdcasey
*/
-public class StringUtils
-{
+public class StringUtils {
/**
* Replace all occurrences of a String within another String.
@@ -73,9 +72,8 @@ public class StringUtils
* @param with String to replace with
* @return the text with any replacements processed
*/
- public static String replace( String text, String repl, String with )
- {
- return replace( text, repl, with, -1 );
+ public static String replace(String text, String repl, String with) {
+ return replace(text, repl, with, -1);
}
/**
@@ -90,41 +88,34 @@ public static String replace( String text, String repl, String with )
* @param max maximum number of values to replace, or -1
if no maximum
* @return the text with any replacements processed
*/
- public static String replace( String text, String repl, String with, int max )
- {
- if ( ( text == null ) || ( repl == null ) || ( with == null ) || ( repl.length() == 0 ) )
- {
+ public static String replace(String text, String repl, String with, int max) {
+ if ((text == null) || (repl == null) || (with == null) || (repl.length() == 0)) {
return text;
}
- StringBuilder buf = new StringBuilder( text.length() );
+ StringBuilder buf = new StringBuilder(text.length());
int start = 0, end;
- while ( ( end = text.indexOf( repl, start ) ) != -1 )
- {
- buf.append( text, start, end ).append( with );
+ while ((end = text.indexOf(repl, start)) != -1) {
+ buf.append(text, start, end).append(with);
start = end + repl.length();
- if ( --max == 0 )
- {
+ if (--max == 0) {
break;
}
}
- buf.append( text, start, text.length());
+ buf.append(text, start, text.length());
return buf.toString();
}
- public static String capitalizeFirstLetter( String data )
- {
- char firstChar = data.charAt( 0 );
- char titleCase = Character.toTitleCase( firstChar );
- if (firstChar == titleCase)
- {
+ public static String capitalizeFirstLetter(String data) {
+ char firstChar = data.charAt(0);
+ char titleCase = Character.toTitleCase(firstChar);
+ if (firstChar == titleCase) {
return data;
}
- StringBuilder result = new StringBuilder( data.length() );
- result.append( titleCase );
- result.append( data, 1, data.length() );
+ StringBuilder result = new StringBuilder(data.length());
+ result.append(titleCase);
+ result.append(data, 1, data.length());
return result.toString();
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/interpolation/util/ValueSourceUtils.java b/src/main/java/org/codehaus/plexus/interpolation/util/ValueSourceUtils.java
index 558f28a..85c1dad 100644
--- a/src/main/java/org/codehaus/plexus/interpolation/util/ValueSourceUtils.java
+++ b/src/main/java/org/codehaus/plexus/interpolation/util/ValueSourceUtils.java
@@ -16,21 +16,18 @@
* limitations under the License.
*/
-import org.codehaus.plexus.interpolation.ValueSource;
-
import java.util.Collection;
+import org.codehaus.plexus.interpolation.ValueSource;
+
/**
* Utility methods shared by multiple {@link ValueSource} implementations.
*
* @author jdcasey
*/
-public final class ValueSourceUtils
-{
+public final class ValueSourceUtils {
- private ValueSourceUtils()
- {
- }
+ private ValueSourceUtils() {}
/**
* If the expression starts with one of the provided prefixes, trim that prefix
@@ -47,63 +44,50 @@ private ValueSourceUtils()
* @return The trimmed expression, or null. See the behavior of
* allowUnprefixedExpressions in this method for more detail.
*/
- public static String trimPrefix( String expression, Collection possiblePrefixes,
- boolean allowUnprefixedExpressions )
- {
- if ( expression == null )
- {
+ public static String trimPrefix(
+ String expression, Collection possiblePrefixes, boolean allowUnprefixedExpressions) {
+ if (expression == null) {
return null;
}
String realExpr = null;
- for ( String prefix : possiblePrefixes )
- {
- if ( expression.startsWith( prefix ) )
- {
- realExpr = expression.substring( prefix.length() );
- if ( realExpr.startsWith( "." ) )
- {
- realExpr = realExpr.substring( 1 );
+ for (String prefix : possiblePrefixes) {
+ if (expression.startsWith(prefix)) {
+ realExpr = expression.substring(prefix.length());
+ if (realExpr.startsWith(".")) {
+ realExpr = realExpr.substring(1);
}
break;
}
}
- if ( realExpr == null && allowUnprefixedExpressions )
- {
+ if (realExpr == null && allowUnprefixedExpressions) {
realExpr = expression;
}
return realExpr;
}
- public static String trimPrefix( String expression, String[] possiblePrefixes, boolean allowUnprefixedExpressions )
- {
- if ( expression == null )
- {
+ public static String trimPrefix(String expression, String[] possiblePrefixes, boolean allowUnprefixedExpressions) {
+ if (expression == null) {
return null;
}
String realExpr = null;
- for ( String prefix : possiblePrefixes )
- {
- if ( expression.startsWith( prefix ) )
- {
- realExpr = expression.substring( prefix.length() );
- if ( realExpr.startsWith( "." ) )
- {
- realExpr = realExpr.substring( 1 );
+ for (String prefix : possiblePrefixes) {
+ if (expression.startsWith(prefix)) {
+ realExpr = expression.substring(prefix.length());
+ if (realExpr.startsWith(".")) {
+ realExpr = realExpr.substring(1);
}
break;
}
}
- if ( realExpr == null && allowUnprefixedExpressions )
- {
+ if (realExpr == null && allowUnprefixedExpressions) {
realExpr = expression;
}
return realExpr;
}
-
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java
index e6b200b..8a3c76c 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java
@@ -16,10 +16,6 @@
* limitations under the License.
*/
-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;
@@ -28,72 +24,64 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class EnvarBasedValueSourceTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class EnvarBasedValueSourceTest {
@BeforeEach
- public void setUp()
- {
+ public void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- void testNoArgConstructorIsCaseSensitive()
- throws IOException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
- {
- public Map getEnvMap()
- {
+ void testNoArgConstructorIsCaseSensitive() throws IOException {
+ OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
+ public Map getEnvMap() {
HashMap map = new HashMap();
- map.put( "aVariable", "variable" );
+ map.put("aVariable", "variable");
return map;
}
- } );
+ });
EnvarBasedValueSource source = new EnvarBasedValueSource();
- assertEquals( "variable", source.getValue( "aVariable" ) );
- assertEquals( "variable", source.getValue( "env.aVariable" ) );
- assertNull( source.getValue( "AVARIABLE" ) );
- assertNull( source.getValue( "env.AVARIABLE" ) );
+ assertEquals("variable", source.getValue("aVariable"));
+ assertEquals("variable", source.getValue("env.aVariable"));
+ assertNull(source.getValue("AVARIABLE"));
+ assertNull(source.getValue("env.AVARIABLE"));
}
@Test
- void testCaseInsensitive()
- throws IOException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
- {
- public Map getEnvMap()
- {
+ void testCaseInsensitive() throws IOException {
+ OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
+ public Map getEnvMap() {
HashMap map = new HashMap();
- map.put( "aVariable", "variable" );
+ map.put("aVariable", "variable");
return map;
}
- } );
+ });
- EnvarBasedValueSource source = new EnvarBasedValueSource( false );
+ EnvarBasedValueSource source = new EnvarBasedValueSource(false);
- assertEquals( "variable", source.getValue( "aVariable" ) );
- assertEquals( "variable", source.getValue( "env.aVariable" ) );
- assertEquals( "variable", source.getValue( "AVARIABLE" ) );
- assertEquals( "variable", source.getValue( "env.AVARIABLE" ) );
+ assertEquals("variable", source.getValue("aVariable"));
+ assertEquals("variable", source.getValue("env.aVariable"));
+ assertEquals("variable", source.getValue("AVARIABLE"));
+ assertEquals("variable", source.getValue("env.AVARIABLE"));
}
@Test
- void testGetRealEnvironmentVariable()
- throws IOException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() );
+ void testGetRealEnvironmentVariable() throws IOException {
+ OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource());
EnvarBasedValueSource source = new EnvarBasedValueSource();
String realEnvVar = "JAVA_HOME";
- String realValue = System.getenv().get( realEnvVar );
- assertNotNull( realValue , "Can't run this test until " + realEnvVar + " env variable is set");
+ String realValue = System.getenv().get(realEnvVar);
+ assertNotNull(realValue, "Can't run this test until " + realEnvVar + " env variable is set");
- assertEquals( realValue, source.getValue( realEnvVar ) );
+ assertEquals(realValue, source.getValue(realEnvVar));
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java b/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java
index 88eacf0..0be913d 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java
@@ -24,8 +24,6 @@
* SOFTWARE.
*/
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
@@ -34,296 +32,258 @@
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* InterpolatorFilterReaderTest, heavily based on InterpolationFilterReaderTest. Heh, even the test strings remained the
* same!
- *
+ *
* @author cstamas
- *
+ *
*/
-public class InterpolatorFilterReaderTest
-{
+public 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
- {
+ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "TestValue" );
+ m.put("test", "TestValue");
String testStr = "This is a ${test";
- assertEquals( "This is a ${test", interpolate( testStr, m ) );
+ assertEquals("This is a ${test", interpolate(testStr, m));
}
/*
* kenneyw@14-04-2005 Added test to check above fix.
*/
@Test
- public void testShouldNotInterpolateExpressionWithMissingEndToken()
- throws Exception
- {
+ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "TestValue" );
+ m.put("test", "TestValue");
String testStr = "This is a ${test, really";
- assertEquals( "This is a ${test, really", interpolate( testStr, m ) );
+ assertEquals("This is a ${test, really", interpolate(testStr, m));
}
@Test
- public void testShouldNotInterpolateWithMalformedStartToken()
- throws Exception
- {
+ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "testValue" );
+ m.put("test", "testValue");
String foo = "This is a $!test} again";
- assertEquals( "This is a $!test} again", interpolate( foo, m ) );
+ assertEquals("This is a $!test} again", interpolate(foo, m));
}
@Test
- public void testShouldNotInterpolateWithMalformedEndToken()
- throws Exception
- {
+ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "testValue" );
+ m.put("test", "testValue");
String foo = "This is a ${test!} again";
- assertEquals( "This is a ${test!} again", interpolate( foo, m ) );
+ assertEquals("This is a ${test!} again", interpolate(foo, m));
}
@Test
- public void testDefaultInterpolationWithNonInterpolatedValueAtEnd()
- throws Exception
- {
+ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "${name} is an ${noun}. ${not.interpolated}";
- assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) );
+ assertEquals("jason is an asshole. ${not.interpolated}", interpolate(foo, m));
}
@Test
- public void testDefaultInterpolationWithInterpolatedValueAtEnd()
- throws Exception
- {
+ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "${name} is an ${noun}";
- assertEquals( "jason is an asshole", interpolate( foo, m ) );
+ assertEquals("jason is an asshole", interpolate(foo, m));
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomToken()
- throws Exception
- {
+ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "@{name} is an @{noun}";
- assertEquals( "jason is an asshole", interpolate( foo, m, "@{", "}" ) );
+ assertEquals("jason is an asshole", interpolate(foo, m, "@{", "}"));
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString()
- throws Exception
- {
+ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "@name@ is an @noun@";
- assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) );
+ assertEquals("jason is an asshole", interpolate(foo, m, "@", "@"));
}
@Test
- public void testEscape()
- throws Exception
- {
+ public void testEscape() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "${name} is an \\${noun}";
- assertEquals( "jason is an ${noun}", interpolate( foo, m, "\\" ) );
+ assertEquals("jason is an ${noun}", interpolate(foo, m, "\\"));
}
@Test
- public void testEscapeAtStart()
- throws Exception
- {
+ public void testEscapeAtStart() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "\\${name} is an \\${noun}";
- assertEquals( "${name} is an ${noun}", interpolate( foo, m, "\\" ) );
+ assertEquals("${name} is an ${noun}", interpolate(foo, m, "\\"));
}
@Test
- public void testEscapeOnlyAtStart()
- throws Exception
- {
+ public void testEscapeOnlyAtStart() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "\\@name@ is an @noun@";
- String result = interpolate( foo, m, "@", "@" );
- assertEquals( "@name@ is an asshole", result );
+ String result = interpolate(foo, m, "@", "@");
+ assertEquals("@name@ is an asshole", result);
}
@Test
- public void testEscapeOnlyAtStartDefaultToken()
- throws Exception
- {
+ public void testEscapeOnlyAtStartDefaultToken() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "\\${name} is an ${noun}";
- String result = interpolate( foo, m, "${", "}" );
- assertEquals( "${name} is an asshole", result );
+ String result = interpolate(foo, m, "${", "}");
+ assertEquals("${name} is an asshole", result);
}
@Test
- public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes()
- throws Exception
- {
+ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
List prefixes = new ArrayList();
- prefixes.add( "prefix1" );
- prefixes.add( "prefix2" );
+ prefixes.add("prefix1");
+ prefixes.add("prefix2");
- RecursionInterceptor ri = new PrefixAwareRecursionInterceptor( prefixes, false );
+ RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
Map context = new HashMap();
- context.put( "name", "${prefix2.name}" );
+ context.put("name", "${prefix2.name}");
String input = "${prefix1.name}";
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new MapBasedValueSource( context ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- InterpolatorFilterReader r = new InterpolatorFilterReader( new StringReader( input ), interpolator, ri );
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ InterpolatorFilterReader r = new InterpolatorFilterReader(new StringReader(input), interpolator, ri);
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
- assertEquals( input, buf.toString() );
+ assertEquals(input, buf.toString());
}
@Test
- public void testShouldDetectRecursiveExpressionWithPrefixAndWithout()
- throws Exception
- {
+ public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
List prefixes = new ArrayList();
- prefixes.add( "prefix1" );
+ prefixes.add("prefix1");
- RecursionInterceptor ri = new PrefixAwareRecursionInterceptor( prefixes, false );
+ RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
Map context = new HashMap();
- context.put( "name", "${prefix1.name}" );
+ context.put("name", "${prefix1.name}");
String input = "${name}";
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new MapBasedValueSource( context ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- InterpolatorFilterReader r = new InterpolatorFilterReader( new StringReader( input ), interpolator, ri );
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ InterpolatorFilterReader r = new InterpolatorFilterReader(new StringReader(input), interpolator, ri);
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
- assertEquals( "${prefix1.name}", buf.toString() );
+ assertEquals("${prefix1.name}", buf.toString());
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- private String interpolate( String input, Map context )
- throws Exception
- {
- return interpolate( input, context, null );
+ 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 ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- InterpolatorFilterReader r = new InterpolatorFilterReader( new StringReader( input ), interpolator );
- r.setInterpolateWithPrefixPattern( false );
- if ( escapeStr != null )
- {
- r.setEscapeString( escapeStr );
+ InterpolatorFilterReader r = new InterpolatorFilterReader(new StringReader(input), interpolator);
+ r.setInterpolateWithPrefixPattern(false);
+ if (escapeStr != null) {
+ r.setEscapeString(escapeStr);
}
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
return buf.toString();
}
- private String interpolate( String input, Map context, String beginToken, String endToken )
- throws Exception
- {
- StringSearchInterpolator interpolator = new StringSearchInterpolator( beginToken, endToken );
+ private String interpolate(String input, Map context, String beginToken, String endToken) throws Exception {
+ StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken);
- interpolator.addValueSource( new MapBasedValueSource( context ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- InterpolatorFilterReader r = new InterpolatorFilterReader( new StringReader( input ), interpolator, beginToken, endToken );
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ InterpolatorFilterReader r =
+ new InterpolatorFilterReader(new StringReader(input), interpolator, beginToken, endToken);
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
return buf.toString();
}
-
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java
index 1cbf533..d1f250a 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java
@@ -16,75 +16,64 @@
* 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 org.junit.jupiter.api.Test;
-public class PrefixAwareRecursionInterceptorTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class PrefixAwareRecursionInterceptorTest {
@Test
- public void testFindExpression()
- {
- PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
- Collections.singleton( "prefix." ) );
+ public void testFindExpression() {
+ PrefixAwareRecursionInterceptor receptor =
+ new PrefixAwareRecursionInterceptor(Collections.singleton("prefix."));
String expr = "prefix.first";
- receptor.expressionResolutionStarted( expr );
+ receptor.expressionResolutionStarted(expr);
- assertTrue( receptor.hasRecursiveExpression( expr ) );
- assertEquals( "[first]", receptor.getExpressionCycle( expr ).toString() );
+ assertTrue(receptor.hasRecursiveExpression(expr));
+ assertEquals("[first]", receptor.getExpressionCycle(expr).toString());
- receptor.expressionResolutionFinished( expr );
+ receptor.expressionResolutionFinished(expr);
- assertFalse( receptor.hasRecursiveExpression( expr ) );
+ assertFalse(receptor.hasRecursiveExpression(expr));
}
@Test
- public void testFindExpressionWithDifferentPrefix()
- {
- PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
- Arrays.asList( new String[] {
- "prefix.",
- "other."
- } ) );
+ public void testFindExpressionWithDifferentPrefix() {
+ PrefixAwareRecursionInterceptor receptor =
+ new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."}));
String expr = "prefix.first";
- receptor.expressionResolutionStarted( expr );
+ receptor.expressionResolutionStarted(expr);
- assertTrue( receptor.hasRecursiveExpression( expr ) );
+ assertTrue(receptor.hasRecursiveExpression(expr));
- receptor.expressionResolutionFinished( expr );
+ receptor.expressionResolutionFinished(expr);
- assertFalse( receptor.hasRecursiveExpression( expr ) );
+ assertFalse(receptor.hasRecursiveExpression(expr));
}
@Test
- public void testFindExpressionWithoutPrefix()
- {
- PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
- Arrays.asList( new String[] {
- "prefix.",
- "other."
- } ) );
+ public void testFindExpressionWithoutPrefix() {
+ PrefixAwareRecursionInterceptor receptor =
+ new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."}));
String prefixedExpr = "prefix.first";
String expr = "first";
- receptor.expressionResolutionStarted( prefixedExpr );
+ receptor.expressionResolutionStarted(prefixedExpr);
- assertTrue( receptor.hasRecursiveExpression( expr ) );
+ assertTrue(receptor.hasRecursiveExpression(expr));
- receptor.expressionResolutionFinished( prefixedExpr );
+ receptor.expressionResolutionFinished(prefixedExpr);
- assertFalse( receptor.hasRecursiveExpression( expr ) );
+ assertFalse(receptor.hasRecursiveExpression(expr));
}
-
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java
index 0a916aa..996d090 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java
@@ -16,59 +16,54 @@
* limitations under the License.
*/
-import static org.junit.jupiter.api.Assertions.assertNull;
-
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
-public class PrefixedObjectValueSourceTest
-{
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class PrefixedObjectValueSourceTest {
@Test
- public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed()
- {
+ public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed() {
String target = "Target object";
-
+
List prefixes = new ArrayList();
- prefixes.add( "target" );
- prefixes.add( "object" );
-
- PrefixedObjectValueSource vs = new PrefixedObjectValueSource( prefixes, target, true );
- Object result = vs.getValue( "" );
-
- assertNull( result );
+ prefixes.add("target");
+ prefixes.add("object");
+
+ PrefixedObjectValueSource vs = new PrefixedObjectValueSource(prefixes, target, true);
+ Object result = vs.getValue("");
+
+ assertNull(result);
}
@Test
- public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot()
- {
+ public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot() {
String target = "Target object";
-
+
List prefixes = new ArrayList();
- prefixes.add( "target" );
- prefixes.add( "object" );
-
- PrefixedObjectValueSource vs = new PrefixedObjectValueSource( prefixes, target, true );
- Object result = vs.getValue( "target." );
-
- assertNull( result );
+ prefixes.add("target");
+ prefixes.add("object");
+
+ PrefixedObjectValueSource vs = new PrefixedObjectValueSource(prefixes, target, true);
+ Object result = vs.getValue("target.");
+
+ assertNull(result);
}
@Test
- public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithoutDot()
- {
+ public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithoutDot() {
String target = "Target object";
-
+
List prefixes = new ArrayList();
- prefixes.add( "target" );
- prefixes.add( "object" );
-
- PrefixedObjectValueSource vs = new PrefixedObjectValueSource( prefixes, target, true );
- Object result = vs.getValue( "target" );
-
- assertNull( result );
- }
+ prefixes.add("target");
+ prefixes.add("object");
+
+ PrefixedObjectValueSource vs = new PrefixedObjectValueSource(prefixes, target, true);
+ Object result = vs.getValue("target");
+ assertNull(result);
+ }
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java b/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java
index e7502a4..1e65b9b 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java
@@ -16,58 +16,56 @@
* 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 org.junit.jupiter.api.Test;
-public class PrefixedValueSourceWrapperTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class PrefixedValueSourceWrapperTest {
@Test
- public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix()
- {
+ public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix() {
String prefix = "prefix.";
String key = "key";
String value = "value";
Properties props = new Properties();
- props.setProperty( key, value );
+ props.setProperty(key, value);
- PrefixedValueSourceWrapper wrapper = new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( props ), prefix );
+ PrefixedValueSourceWrapper wrapper =
+ new PrefixedValueSourceWrapper(new PropertiesBasedValueSource(props), prefix);
- assertEquals( value, wrapper.getValue( prefix + key ) );
+ assertEquals(value, wrapper.getValue(prefix + key));
}
@Test
- public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix()
- {
+ public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix() {
String prefix = "prefix.";
String otherPrefix = "other.";
String key = "key";
String value = "value";
Properties props = new Properties();
- props.setProperty( key, value );
+ props.setProperty(key, value);
- PrefixedValueSourceWrapper wrapper = new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( props ), prefix );
+ PrefixedValueSourceWrapper wrapper =
+ new PrefixedValueSourceWrapper(new PropertiesBasedValueSource(props), prefix);
- assertNull( wrapper.getValue( otherPrefix + key ) );
+ assertNull(wrapper.getValue(otherPrefix + key));
}
@Test
- public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix()
- {
+ public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix() {
String prefix = "prefix.";
String key = "key";
Properties props = new Properties();
- PrefixedValueSourceWrapper wrapper = new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( props ), prefix );
+ PrefixedValueSourceWrapper wrapper =
+ new PrefixedValueSourceWrapper(new PropertiesBasedValueSource(props), prefix);
- assertNull( wrapper.getValue( prefix + key ) );
+ assertNull(wrapper.getValue(prefix + key));
}
-
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java b/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java
index d893030..6fe10b8 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java
@@ -16,41 +16,37 @@
* 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 org.junit.jupiter.api.Test;
-public class PropertiesBasedValueSourceTest
-{
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class PropertiesBasedValueSourceTest {
@Test
- public void testPropertyShouldReturnValueFromProperties()
- {
+ public void testPropertyShouldReturnValueFromProperties() {
Properties props = new Properties();
String key = "key";
String value = "value";
- props.setProperty( key, value );
+ props.setProperty(key, value);
- PropertiesBasedValueSource vs = new PropertiesBasedValueSource( props );
+ PropertiesBasedValueSource vs = new PropertiesBasedValueSource(props);
- assertNotNull( vs.getValue( key ) );
+ assertNotNull(vs.getValue(key));
}
@Test
- public void testPropertyShouldReturnNullWhenPropertyMissing()
- {
+ public void testPropertyShouldReturnNullWhenPropertyMissing() {
Properties props = new Properties();
String key = "key";
- PropertiesBasedValueSource vs = new PropertiesBasedValueSource( props );
+ PropertiesBasedValueSource vs = new PropertiesBasedValueSource(props);
- assertNull( vs.getValue( key ) );
+ assertNull(vs.getValue(key));
}
-
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java
index 245ef51..d3c31f6 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java
@@ -16,9 +16,6 @@
* 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;
@@ -28,211 +25,180 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class RegexBasedInterpolatorTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class RegexBasedInterpolatorTest {
@BeforeEach
- public void setUp()
- {
+ public void setUp() {
EnvarBasedValueSource.resetStatics();
}
- public String getVar()
- {
+ public String getVar() {
return "testVar";
}
@Test
- public void testShouldFailOnExpressionCycle()
- {
+ public void testShouldFailOnExpressionCycle() {
Properties props = new Properties();
- props.setProperty( "key1", "${key2}" );
- props.setProperty( "key2", "${key1}" );
+ props.setProperty("key1", "${key2}");
+ props.setProperty("key2", "${key1}");
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
- rbi.addValueSource( new PropertiesBasedValueSource( props ) );
+ rbi.addValueSource(new PropertiesBasedValueSource(props));
- try
- {
- rbi.interpolate( "${key1}", new SimpleRecursionInterceptor() );
+ try {
+ rbi.interpolate("${key1}", new SimpleRecursionInterceptor());
- fail( "Should detect expression cycle and fail." );
- }
- catch ( InterpolationException e )
- {
+ fail("Should detect expression cycle and fail.");
+ } catch (InterpolationException e) {
// expected
}
}
@Test
- public void testShouldResolveByMy_getVar_Method()
- throws InterpolationException
- {
+ public void testShouldResolveByMy_getVar_Method() throws InterpolationException {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
- rbi.addValueSource( new ObjectBasedValueSource( this ) );
- String result = rbi.interpolate( "this is a ${this.var}", "this" );
+ rbi.addValueSource(new ObjectBasedValueSource(this));
+ String result = rbi.interpolate("this is a ${this.var}", "this");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@Test
- public void testShouldResolveByContextValue()
- throws InterpolationException
- {
+ public void testShouldResolveByContextValue() throws InterpolationException {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
Map context = new HashMap();
- context.put( "var", "testVar" );
+ context.put("var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- String result = rbi.interpolate( "this is a ${this.var}", "this" );
+ String result = rbi.interpolate("this is a ${this.var}", "this");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@Test
- public void testShouldResolveByEnvar()
- throws IOException, InterpolationException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
- {
- public Map getEnvMap()
- {
- HashMap map = new HashMap();
- map.put( "SOME_ENV", "variable" );
+ 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;
}
- } );
+ });
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
- rbi.addValueSource( new EnvarBasedValueSource() );
+ rbi.addValueSource(new EnvarBasedValueSource());
- String result = rbi.interpolate( "this is a ${env.SOME_ENV}", "this" );
+ String result = rbi.interpolate("this is a ${env.SOME_ENV}", "this");
- assertEquals( "this is a variable", result );
+ assertEquals("this is a variable", result);
}
@Test
- public void testUseAlternateRegex()
- throws Exception
- {
- RegexBasedInterpolator rbi = new RegexBasedInterpolator( "\\@\\{(", ")?([^}]+)\\}@" );
+ public void testUseAlternateRegex() throws Exception {
+ RegexBasedInterpolator rbi = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@");
Map context = new HashMap();
- context.put( "var", "testVar" );
+ context.put("var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- String result = rbi.interpolate( "this is a @{this.var}@", "this" );
+ String result = rbi.interpolate("this is a @{this.var}@", "this");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@Test
- public void testNPEFree()
- throws Exception
- {
- RegexBasedInterpolator rbi = new RegexBasedInterpolator( "\\@\\{(", ")?([^}]+)\\}@" );
+ public void testNPEFree() throws Exception {
+ RegexBasedInterpolator rbi = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@");
Map context = new HashMap();
- context.put( "var", "testVar" );
+ context.put("var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- String result = rbi.interpolate( null );
+ String result = rbi.interpolate(null);
- assertEquals( "", result );
+ assertEquals("", result);
}
@Test
- public void testUsePostProcessor_DoesNotChangeValue()
- throws InterpolationException
- {
+ public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
-
+
Map context = new HashMap();
- context.put( "test.var", "testVar" );
+ context.put("test.var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor( new InterpolationPostProcessor()
- {
- public Object execute( String expression, Object value )
- {
+ rbi.addPostProcessor(new InterpolationPostProcessor() {
+ public Object execute(String expression, Object value) {
return null;
}
- } );
+ });
- String result = rbi.interpolate( "this is a ${test.var}", "" );
+ String result = rbi.interpolate("this is a ${test.var}", "");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@Test
- public void testUsePostProcessor_ChangesValue()
- throws InterpolationException
- {
+ public void testUsePostProcessor_ChangesValue() throws InterpolationException {
int loopNumber = 200000;
-
+
long start = System.currentTimeMillis();
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
Map context = new HashMap();
- context.put( "test.var", "testVar" );
+ context.put("test.var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor( new InterpolationPostProcessor()
- {
- public Object execute( String expression, Object value )
- {
+ rbi.addPostProcessor(new InterpolationPostProcessor() {
+ public Object execute(String expression, Object value) {
return value + "2";
}
- } );
-
- for ( int i = 0, number = loopNumber; i < number; i++ )
- {
+ });
+ for (int i = 0, number = loopNumber; i < number; i++) {
- String result = rbi.interpolate( "this is a ${test.var}", "" );
+ String result = rbi.interpolate("this is a ${test.var}", "");
- assertEquals( "this is a testVar2", result );
+ assertEquals("this is a testVar2", result);
}
long end = System.currentTimeMillis();
- System.out.println( "time without pattern reuse and RegexBasedInterpolator instance reuse " + ( end - start ) );
+ System.out.println("time without pattern reuse and RegexBasedInterpolator instance reuse " + (end - start));
System.gc();
-
+
start = System.currentTimeMillis();
-
-
-
- rbi = new RegexBasedInterpolator( true );
-
- rbi.addPostProcessor( new InterpolationPostProcessor()
- {
- 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.addValueSource( new MapBasedValueSource( context ) );
-
- for ( int i = 0, number = loopNumber; i < number; i++ )
- {
+ });
+
+ rbi.addValueSource(new MapBasedValueSource(context));
+
+ for (int i = 0, number = loopNumber; i < number; i++) {
- String result = rbi.interpolate( "this is a ${test.var}", "" );
+ String result = rbi.interpolate("this is a ${test.var}", "");
- assertEquals( "this is a testVar2", result );
+ assertEquals("this is a testVar2", result);
}
end = System.currentTimeMillis();
- System.out.println( "time with pattern reuse and RegexBasedInterpolator instance reuse " + ( end - start ) );
+ System.out.println("time with pattern reuse and RegexBasedInterpolator instance reuse " + (end - start));
}
}
diff --git a/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java
index 1d184eb..5152670 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java
@@ -16,9 +16,6 @@
* 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;
@@ -31,488 +28,419 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class StringSearchInterpolatorTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class StringSearchInterpolatorTest {
@BeforeEach
- public void setUp()
- {
+ public void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- public void testLongDelimitersInContext()
- throws InterpolationException
- {
+ public void testLongDelimitersInContext() throws InterpolationException {
String src = "This is a test.label for long delimiters in context.";
String result = "This is a test for long delimiters in context.";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "", "" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("", "");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- public void testLongDelimitersWithNoStartContext()
- throws InterpolationException
- {
+ public void testLongDelimitersWithNoStartContext() throws InterpolationException {
String src = "test.label for long delimiters in context.";
String result = "test for long delimiters in context.";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "", "" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("", "");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- public void testLongDelimitersWithNoEndContext()
- throws InterpolationException
- {
+ public void testLongDelimitersWithNoEndContext() throws InterpolationException {
String src = "This is a test.label";
String result = "This is a test";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "", "" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("", "");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- public void testLongDelimitersWithNoContext()
- throws InterpolationException
- {
+ public void testLongDelimitersWithNoContext() throws InterpolationException {
String src = "test.label";
String result = "test";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "", "" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("", "");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- public void testSimpleSubstitution()
- throws InterpolationException
- {
+ public void testSimpleSubstitution() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( "This is a test value.", interpolator.interpolate( "This is a test ${key}." ) );
+ assertEquals("This is a test value.", interpolator.interpolate("This is a test ${key}."));
}
@Test
- public void testSimpleSubstitution_TwoExpressions()
- throws InterpolationException
- {
+ public void testSimpleSubstitution_TwoExpressions() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( "value-value2", interpolator.interpolate( "${key}-${key2}" ) );
+ assertEquals("value-value2", interpolator.interpolate("${key}-${key2}"));
}
@Test
- public void testBrokenExpression_LeaveItAlone()
- throws InterpolationException
- {
+ public void testBrokenExpression_LeaveItAlone() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( "This is a test ${key.", interpolator.interpolate( "This is a test ${key." ) );
+ assertEquals("This is a test ${key.", interpolator.interpolate("This is a test ${key."));
}
@Test
- public void testShouldFailOnExpressionCycle()
- {
+ public void testShouldFailOnExpressionCycle() {
Properties props = new Properties();
- props.setProperty( "key1", "${key2}" );
- props.setProperty( "key2", "${key1}" );
+ props.setProperty("key1", "${key2}");
+ props.setProperty("key2", "${key1}");
StringSearchInterpolator rbi = new StringSearchInterpolator();
- rbi.addValueSource( new PropertiesBasedValueSource( props ) );
+ rbi.addValueSource(new PropertiesBasedValueSource(props));
- try
- {
- rbi.interpolate( "${key1}", new SimpleRecursionInterceptor() );
+ try {
+ rbi.interpolate("${key1}", new SimpleRecursionInterceptor());
- fail( "Should detect expression cycle and fail." );
- }
- catch ( InterpolationException e )
- {
+ fail("Should detect expression cycle and fail.");
+ } catch (InterpolationException e) {
// expected
}
}
@Test
- public void testShouldResolveByUsingObject_List_Map()
- throws InterpolationException
- {
+ public void testShouldResolveByUsingObject_List_Map() throws InterpolationException {
StringSearchInterpolator rbi = new StringSearchInterpolator();
- rbi.addValueSource( new ObjectBasedValueSource( this ) );
+ rbi.addValueSource(new ObjectBasedValueSource(this));
String result =
- rbi.interpolate( "this is a ${var} ${list[1].name} ${anArray[2].name} ${map(Key with spaces).name}" );
+ rbi.interpolate("this is a ${var} ${list[1].name} ${anArray[2].name} ${map(Key with spaces).name}");
- assertEquals( "this is a testVar testIndexedWithList testIndexedWithArray testMap", result );
+ assertEquals("this is a testVar testIndexedWithList testIndexedWithArray testMap", result);
}
@Test
- public void testShouldResolveByContextValue()
- throws InterpolationException
- {
+ public void testShouldResolveByContextValue() throws InterpolationException {
StringSearchInterpolator rbi = new StringSearchInterpolator();
Map context = new HashMap();
- context.put( "var", "testVar" );
+ context.put("var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- String result = rbi.interpolate( "this is a ${var}" );
+ String result = rbi.interpolate("this is a ${var}");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@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" );
+ 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;
}
- } );
+ });
StringSearchInterpolator rbi = new StringSearchInterpolator();
- rbi.addValueSource( new EnvarBasedValueSource( false ) );
+ rbi.addValueSource(new EnvarBasedValueSource(false));
- String result = rbi.interpolate( "this is a ${env.SOME_ENV} ${env.OTHER_ENV}" );
+ String result = rbi.interpolate("this is a ${env.SOME_ENV} ${env.OTHER_ENV}");
- assertEquals( "this is a variable other variable", result );
+ assertEquals("this is a variable other variable", result);
}
@Test
- public void testUsePostProcessor_DoesNotChangeValue()
- throws InterpolationException
- {
+ public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException {
StringSearchInterpolator rbi = new StringSearchInterpolator();
Map context = new HashMap();
- context.put( "test.var", "testVar" );
+ context.put("test.var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor( new InterpolationPostProcessor()
- {
- public Object execute( String expression, Object value )
- {
+ rbi.addPostProcessor(new InterpolationPostProcessor() {
+ public Object execute(String expression, Object value) {
return null;
}
- } );
+ });
- String result = rbi.interpolate( "this is a ${test.var}" );
+ String result = rbi.interpolate("this is a ${test.var}");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@Test
- public void testUsePostProcessor_ChangesValue()
- throws InterpolationException
- {
+ public void testUsePostProcessor_ChangesValue() throws InterpolationException {
StringSearchInterpolator rbi = new StringSearchInterpolator();
Map context = new HashMap();
- context.put( "test.var", "testVar" );
+ context.put("test.var", "testVar");
- rbi.addValueSource( new MapBasedValueSource( context ) );
+ rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor( new InterpolationPostProcessor()
- {
- public Object execute( String expression, Object value )
- {
+ rbi.addPostProcessor(new InterpolationPostProcessor() {
+ public Object execute(String expression, Object value) {
return value + "2";
}
- } );
+ });
- String result = rbi.interpolate( "this is a ${test.var}" );
+ String result = rbi.interpolate("this is a ${test.var}");
- assertEquals( "this is a testVar2", result );
+ assertEquals("this is a testVar2", result);
}
@Test
- public void testSimpleSubstitutionWithDefinedExpr()
- throws InterpolationException
- {
+ public void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- assertEquals( "This is a test value.", interpolator.interpolate( "This is a test @{key}." ) );
+ assertEquals("This is a test value.", interpolator.interpolate("This is a test @{key}."));
}
@Test
- public void testEscape()
- throws InterpolationException
- {
+ public void testEscape() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "\\" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("\\");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "This is a test \\@{key}." );
+ String result = interpolator.interpolate("This is a test \\@{key}.");
- assertEquals( "This is a test @{key}.", result );
+ assertEquals("This is a test @{key}.", result);
}
@Test
- public void testEscapeWithLongEscapeStr()
- throws InterpolationException
- {
+ public void testEscapeWithLongEscapeStr() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "$$" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("$$");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "This is a test $$@{key}." );
+ String result = interpolator.interpolate("This is a test $$@{key}.");
- assertEquals( "This is a test @{key}.", result );
+ assertEquals("This is a test @{key}.", result);
}
@Test
- public void testEscapeWithLongEscapeStrAtStart()
- throws InterpolationException
- {
+ public void testEscapeWithLongEscapeStrAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "$$" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("$$");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "$$@{key} This is a test." );
+ String result = interpolator.interpolate("$$@{key} This is a test.");
- assertEquals( "@{key} This is a test.", result );
+ assertEquals("@{key} This is a test.", result);
}
@Test
- public void testNotEscapeWithLongEscapeStrAtStart()
- throws InterpolationException
- {
+ public void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "$$" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("$$");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "@{key} This is a test." );
+ String result = interpolator.interpolate("@{key} This is a test.");
- assertEquals( "value This is a test.", result );
+ assertEquals("value This is a test.", result);
}
@Test
- public void testEscapeNotFailWithNullEscapeStr()
- throws InterpolationException
- {
+ public void testEscapeNotFailWithNullEscapeStr() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( null );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString(null);
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "This is a test @{key}." );
+ String result = interpolator.interpolate("This is a test @{key}.");
- assertEquals( "This is a test value.", result );
+ assertEquals("This is a test value.", result);
}
@Test
- public void testOnlyEscapeExprAtStart()
- throws InterpolationException
- {
+ public void testOnlyEscapeExprAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "\\" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("\\");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "\\@{key} This is a test." );
+ String result = interpolator.interpolate("\\@{key} This is a test.");
- assertEquals( "@{key} This is a test.", result );
+ assertEquals("@{key} This is a test.", result);
}
@Test
- public void testNotEscapeExprAtStart()
- throws InterpolationException
- {
+ public void testNotEscapeExprAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "\\" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("\\");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "@{key} This is a test." );
+ String result = interpolator.interpolate("@{key} This is a test.");
- assertEquals( "value This is a test.", result );
+ assertEquals("value This is a test.", result);
}
@Test
- public void testEscapeExprAtStart()
- throws InterpolationException
- {
+ public void testEscapeExprAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@", "@" );
- interpolator.setEscapeString( "\\" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@", "@");
+ interpolator.setEscapeString("\\");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( "\\@key@ This is a test @key@." );
+ String result = interpolator.interpolate("\\@key@ This is a test @key@.");
- assertEquals( "@key@ This is a test value.", result );
+ assertEquals("@key@ This is a test value.", result);
}
@Test
- public void testNPEFree()
- throws InterpolationException
- {
+ public void testNPEFree() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "@{", "}" );
- interpolator.setEscapeString( "\\" );
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("@{", "}");
+ interpolator.setEscapeString("\\");
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- String result = interpolator.interpolate( null );
+ String result = interpolator.interpolate(null);
- assertEquals( "", result );
+ assertEquals("", result);
}
@Test
- public void testInterruptedInterpolate()
- throws InterpolationException
- {
+ public void testInterruptedInterpolate() throws InterpolationException {
Interpolator interpolator = new StringSearchInterpolator();
RecursionInterceptor recursionInterceptor = new SimpleRecursionInterceptor();
- final boolean[] error = new boolean[] { false };
- interpolator.addValueSource( new ValueSource()
- {
- public Object getValue( String expression ) {
- if ( expression.equals( "key" ) )
- {
- if ( error[ 0 ] )
- {
- throw new IllegalStateException( "broken" );
+ final boolean[] error = new boolean[] {false};
+ interpolator.addValueSource(new ValueSource() {
+ public Object getValue(String expression) {
+ if (expression.equals("key")) {
+ if (error[0]) {
+ throw new IllegalStateException("broken");
}
return "val";
- }
- else
- {
+ } else {
return null;
}
}
- public List getFeedback()
- {
+
+ public List getFeedback() {
return Collections.EMPTY_LIST;
}
- public void clearFeedback()
- {
- }
- } );
- assertEquals( "-val-" , interpolator.interpolate( "-${key}-", recursionInterceptor ) , "control case");
- error[ 0 ] = true;
- try
- {
- interpolator.interpolate( "-${key}-", recursionInterceptor );
- fail( "should have thrown exception" );
- }
- catch ( IllegalStateException x )
- {
+
+ public void clearFeedback() {}
+ });
+ assertEquals("-val-", interpolator.interpolate("-${key}-", recursionInterceptor), "control case");
+ error[0] = true;
+ try {
+ interpolator.interpolate("-${key}-", recursionInterceptor);
+ fail("should have thrown exception");
+ } catch (IllegalStateException x) {
// right
}
- error[ 0 ] = false;
- assertEquals( "-val-", interpolator.interpolate( "-${key}-", recursionInterceptor ) , "should not believe there is a cycle here");
+ error[0] = false;
+ assertEquals(
+ "-val-",
+ interpolator.interpolate("-${key}-", recursionInterceptor),
+ "should not believe there is a cycle here");
}
- public String getVar()
- {
+ public String getVar() {
return "testVar";
}
- public Person[] getAnArray()
- {
+ public Person[] getAnArray() {
Person[] array = new Person[3];
- array[0] = new Person( "Gabriel" );
- array[1] = new Person( "Daniela" );
- array[2] = new Person( "testIndexedWithArray" );
+ array[0] = new Person("Gabriel");
+ array[1] = new Person("Daniela");
+ array[2] = new Person("testIndexedWithArray");
return array;
}
- public List getList()
- {
+ public List getList() {
List list = new ArrayList();
- list.add( new Person( "Gabriel" ) );
- list.add( new Person( "testIndexedWithList" ) );
- list.add( new Person( "Daniela" ) );
+ list.add(new Person("Gabriel"));
+ list.add(new Person("testIndexedWithList"));
+ list.add(new Person("Daniela"));
return list;
}
- public Map getMap()
- {
+ public Map getMap() {
Map map = new HashMap();
- map.put( "Key with spaces", new Person( "testMap" ) );
+ map.put("Key with spaces", new Person("testMap"));
return map;
}
- public static class Person
- {
+ public static class Person {
private String name;
- public Person( String name )
- {
+ public Person(String name) {
this.name = name;
}
- public String getName()
- {
+ public String getName() {
return 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 e0f283b..b6ff638 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java
@@ -16,10 +16,6 @@
* limitations under the License.
*/
-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;
@@ -28,73 +24,64 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class EnvarBasedValueSourceTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class EnvarBasedValueSourceTest {
@BeforeEach
- public void setUp()
- {
+ public void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- void testNoArgConstructorIsCaseSensitive()
- throws IOException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
- {
- public Map getEnvMap()
- {
+ void testNoArgConstructorIsCaseSensitive() throws IOException {
+ OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
+ public Map getEnvMap() {
HashMap map = new HashMap();
- map.put( "aVariable", "variable" );
+ map.put("aVariable", "variable");
return map;
}
- } );
+ });
EnvarBasedValueSource source = new EnvarBasedValueSource();
- assertEquals( "variable", source.getValue( "aVariable", null ) );
- assertEquals( "variable", source.getValue( "env.aVariable", null ) );
- assertNull( source.getValue( "AVARIABLE", null ) );
- assertNull( source.getValue( "env.AVARIABLE", null ) );
+ assertEquals("variable", source.getValue("aVariable", null));
+ assertEquals("variable", source.getValue("env.aVariable", null));
+ assertNull(source.getValue("AVARIABLE", null));
+ assertNull(source.getValue("env.AVARIABLE", null));
}
@Test
- void testCaseInsensitive()
- throws IOException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
- {
- public Map getEnvMap()
- {
+ void testCaseInsensitive() throws IOException {
+ OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
+ public Map getEnvMap() {
HashMap map = new HashMap();
- map.put( "aVariable", "variable" );
+ map.put("aVariable", "variable");
return map;
}
- } );
+ });
- EnvarBasedValueSource source = new EnvarBasedValueSource( false );
+ EnvarBasedValueSource source = new EnvarBasedValueSource(false);
- assertEquals( "variable", source.getValue( "aVariable", null ) );
- assertEquals( "variable", source.getValue( "env.aVariable", null ) );
- assertEquals( "variable", source.getValue( "AVARIABLE", null ) );
- assertEquals( "variable", source.getValue( "env.AVARIABLE", null ) );
+ assertEquals("variable", source.getValue("aVariable", null));
+ assertEquals("variable", source.getValue("env.aVariable", null));
+ assertEquals("variable", source.getValue("AVARIABLE", null));
+ assertEquals("variable", source.getValue("env.AVARIABLE", null));
}
@Test
- void testGetRealEnvironmentVariable()
- throws IOException
- {
- OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() );
+ void testGetRealEnvironmentVariable() throws IOException {
+ OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource());
EnvarBasedValueSource source = new EnvarBasedValueSource();
String realEnvVar = "JAVA_HOME";
- String realValue = System.getenv().get( realEnvVar );
- assertNotNull( realValue , "Can't run this test until " + realEnvVar + " env variable is set");
+ String realValue = System.getenv().get(realEnvVar);
+ assertNotNull(realValue, "Can't run this test until " + realEnvVar + " env variable is set");
- assertEquals( realValue, source.getValue( realEnvVar, null ) );
+ 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 a7990f1..afef83e 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java
@@ -15,10 +15,6 @@
* limitations under the License.
*/
-import static org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator.create;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -34,532 +30,474 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class FixedStringSearchInterpolatorTest
-{
+import static org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator.create;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class FixedStringSearchInterpolatorTest {
@BeforeEach
- public void setUp()
- {
+ public void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- 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.";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "", "" );
+ create(new PropertiesBasedValueSource(p)).withExpressionMarkers("", "");
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- void testLongDelimitersWithNoStartContext()
- {
+ void testLongDelimitersWithNoStartContext() {
String src = "test.label for long delimiters in context.";
String result = "test for long delimiters in context.";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "", "" );
+ create(new PropertiesBasedValueSource(p)).withExpressionMarkers("", "");
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- void testLongDelimitersWithNoEndContext()
- {
+ void testLongDelimitersWithNoEndContext() {
String src = "This is a test.label";
String result = "This is a test";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "", "" );
+ create(new PropertiesBasedValueSource(p)).withExpressionMarkers("", "");
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- void testLongDelimitersWithNoContext()
- {
+ void testLongDelimitersWithNoContext() {
String src = "test.label";
String result = "test";
Properties p = new Properties();
- p.setProperty( "test.label", "test" );
+ p.setProperty("test.label", "test");
FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "", "" );
+ create(new PropertiesBasedValueSource(p)).withExpressionMarkers("", "");
- assertEquals( result, interpolator.interpolate( src ) );
+ assertEquals(result, interpolator.interpolate(src));
}
@Test
- void testSimpleSubstitution()
- {
+ void testSimpleSubstitution() {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator = create( new PropertiesBasedValueSource( p ) );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p));
- assertEquals( "This is a test value.", interpolator.interpolate( "This is a test ${key}." ) );
+ assertEquals("This is a test value.", interpolator.interpolate("This is a test ${key}."));
}
@Test
- void testSimpleSubstitution_TwoExpressions()
- {
+ void testSimpleSubstitution_TwoExpressions() {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- FixedStringSearchInterpolator interpolator = create( new PropertiesBasedValueSource( p ) );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p));
- assertEquals( "value-value2", interpolator.interpolate( "${key}-${key2}" ) );
+ assertEquals("value-value2", interpolator.interpolate("${key}-${key2}"));
}
@Test
- void testBrokenExpression_LeaveItAlone()
- {
+ void testBrokenExpression_LeaveItAlone() {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator = create( new PropertiesBasedValueSource( p ) );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p));
- assertEquals( "This is a test ${key.", interpolator.interpolate( "This is a test ${key." ) );
+ assertEquals("This is a test ${key.", interpolator.interpolate("This is a test ${key."));
}
@Test
- void testShouldFailOnExpressionCycle()
- {
+ void testShouldFailOnExpressionCycle() {
Properties props = new Properties();
- props.setProperty( "key1", "${key2}" );
- props.setProperty( "key2", "${key1}" );
+ props.setProperty("key1", "${key2}");
+ props.setProperty("key2", "${key1}");
- FixedStringSearchInterpolator rbi = create( new PropertiesBasedValueSource( props ) );
+ FixedStringSearchInterpolator rbi = create(new PropertiesBasedValueSource(props));
- assertThrows(InterpolationCycleException.class, () -> rbi.interpolate( "${key1}" ),
- "Should detect expression cycle and fail." );
+ assertThrows(
+ InterpolationCycleException.class,
+ () -> rbi.interpolate("${key1}"),
+ "Should detect expression cycle and fail.");
}
@Test
- void testShouldResolveByUsingObject_List_Map()
- throws InterpolationException
- {
- FixedStringSearchInterpolator rbi = create( new ObjectBasedValueSource( this ) );
+ void testShouldResolveByUsingObject_List_Map() throws InterpolationException {
+ 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}" );
+ rbi.interpolate("this is a ${var} ${list[1].name} ${anArray[2].name} ${map(Key with spaces).name}");
- assertEquals( "this is a testVar testIndexedWithList testIndexedWithArray testMap", result );
+ assertEquals("this is a testVar testIndexedWithList testIndexedWithArray testMap", result);
}
@Test
- void testShouldResolveByContextValue()
- throws InterpolationException
- {
+ void testShouldResolveByContextValue() throws InterpolationException {
Map context = new HashMap();
- context.put( "var", "testVar" );
+ context.put("var", "testVar");
- FixedStringSearchInterpolator rbi = create( new MapBasedValueSource( context ) );
+ FixedStringSearchInterpolator rbi = create(new MapBasedValueSource(context));
- String result = rbi.interpolate( "this is a ${var}" );
+ String result = rbi.interpolate("this is a ${var}");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@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" );
+ 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;
}
- } );
+ });
- FixedStringSearchInterpolator rbi = create( new EnvarBasedValueSource( false ) );
+ FixedStringSearchInterpolator rbi = create(new EnvarBasedValueSource(false));
- String result = rbi.interpolate( "this is a ${env.SOME_ENV} ${env.OTHER_ENV}" );
+ String result = rbi.interpolate("this is a ${env.SOME_ENV} ${env.OTHER_ENV}");
- assertEquals( "this is a variable other variable", result );
+ assertEquals("this is a variable other variable", result);
}
@Test
- void testUsePostProcessor_DoesNotChangeValue()
- throws InterpolationException
- {
+ void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException {
Map context = new HashMap();
- context.put( "test.var", "testVar" );
+ context.put("test.var", "testVar");
- final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor()
- {
- public Object execute( String expression, Object value )
- {
+ final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor() {
+ public Object execute(String expression, Object value) {
return null;
}
};
FixedStringSearchInterpolator rbi =
- create( new MapBasedValueSource( context ) ).withPostProcessor( postProcessor );
+ create(new MapBasedValueSource(context)).withPostProcessor(postProcessor);
- String result = rbi.interpolate( "this is a ${test.var}" );
+ String result = rbi.interpolate("this is a ${test.var}");
- assertEquals( "this is a testVar", result );
+ assertEquals("this is a testVar", result);
}
@Test
- void testUsePostProcessor_ChangesValue()
- throws InterpolationException
- {
+ void testUsePostProcessor_ChangesValue() throws InterpolationException {
Map context = new HashMap();
- context.put( "test.var", "testVar" );
+ context.put("test.var", "testVar");
- final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor()
- {
- public Object execute( String expression, Object value )
- {
+ final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor() {
+ public Object execute(String expression, Object value) {
return value + "2";
}
};
FixedStringSearchInterpolator rbi =
- create( new MapBasedValueSource( context ) ).withPostProcessor( postProcessor );
+ create(new MapBasedValueSource(context)).withPostProcessor(postProcessor);
- String result = rbi.interpolate( "this is a ${test.var}" );
+ String result = rbi.interpolate("this is a ${test.var}");
- assertEquals( "this is a testVar2", result );
+ assertEquals("this is a testVar2", result);
}
@Test
- void testSimpleSubstitutionWithDefinedExpr()
- throws InterpolationException
- {
+ void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator = create( "@{", "}", new PropertiesBasedValueSource( p ) );
+ FixedStringSearchInterpolator interpolator = create("@{", "}", new PropertiesBasedValueSource(p));
- assertEquals( "This is a test value.", interpolator.interpolate( "This is a test @{key}." ) );
+ assertEquals("This is a test value.", interpolator.interpolate("This is a test @{key}."));
}
@Test
- void testEscape()
- throws InterpolationException
- {
+ void testEscape() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "\\" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("\\");
- String result = interpolator.interpolate( "This is a test \\@{key}." );
+ String result = interpolator.interpolate("This is a test \\@{key}.");
- assertEquals( "This is a test @{key}.", result );
+ assertEquals("This is a test @{key}.", result);
}
@Test
- void testEscapeWithLongEscapeStr()
- throws InterpolationException
- {
+ void testEscapeWithLongEscapeStr() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "$$" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("$$");
- String result = interpolator.interpolate( "This is a test $$@{key}." );
+ String result = interpolator.interpolate("This is a test $$@{key}.");
- assertEquals( "This is a test @{key}.", result );
+ assertEquals("This is a test @{key}.", result);
}
@Test
- void testEscapeWithLongEscapeStrAtStart()
- throws InterpolationException
- {
+ void testEscapeWithLongEscapeStrAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "$$" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("$$");
- String result = interpolator.interpolate( "$$@{key} This is a test." );
+ String result = interpolator.interpolate("$$@{key} This is a test.");
- assertEquals( "@{key} This is a test.", result );
+ assertEquals("@{key} This is a test.", result);
}
@Test
- void testNotEscapeWithLongEscapeStrAtStart()
- throws InterpolationException
- {
+ void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "$$" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("$$");
- String result = interpolator.interpolate( "@{key} This is a test." );
+ String result = interpolator.interpolate("@{key} This is a test.");
- assertEquals( "value This is a test.", result );
+ assertEquals("value This is a test.", result);
}
@Test
- void testEscapeNotFailWithNullEscapeStr()
- throws InterpolationException
- {
+ void testEscapeNotFailWithNullEscapeStr() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( null );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString(null);
- String result = interpolator.interpolate( "This is a test @{key}." );
+ String result = interpolator.interpolate("This is a test @{key}.");
- assertEquals( "This is a test value.", result );
+ assertEquals("This is a test value.", result);
}
@Test
- void testOnlyEscapeExprAtStart()
- throws InterpolationException
- {
+ void testOnlyEscapeExprAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "\\" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("\\");
- String result = interpolator.interpolate( "\\@{key} This is a test." );
+ String result = interpolator.interpolate("\\@{key} This is a test.");
- assertEquals( "@{key} This is a test.", result );
+ assertEquals("@{key} This is a test.", result);
}
@Test
- void testNotEscapeExprAtStart()
- throws InterpolationException
- {
+ void testNotEscapeExprAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "\\" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("\\");
- String result = interpolator.interpolate( "@{key} This is a test." );
+ String result = interpolator.interpolate("@{key} This is a test.");
- assertEquals( "value This is a test.", result );
+ assertEquals("value This is a test.", result);
}
@Test
- void testEscapeExprAtStart()
- throws InterpolationException
- {
+ void testEscapeExprAtStart() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@", "@" ).withEscapeString( "\\" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@", "@")
+ .withEscapeString("\\");
- String result = interpolator.interpolate( "\\@key@ This is a test @key@." );
+ String result = interpolator.interpolate("\\@key@ This is a test @key@.");
- assertEquals( "@key@ This is a test value.", result );
+ assertEquals("@key@ This is a test value.", result);
}
@Test
- void testNPEFree()
- throws InterpolationException
- {
+ void testNPEFree() throws InterpolationException {
Properties p = new Properties();
- p.setProperty( "key", "value" );
+ p.setProperty("key", "value");
- FixedStringSearchInterpolator interpolator =
- create( new PropertiesBasedValueSource( p ) ).withExpressionMarkers( "@{", "}" ).withEscapeString( "\\" );
+ FixedStringSearchInterpolator interpolator = create(new PropertiesBasedValueSource(p))
+ .withExpressionMarkers("@{", "}")
+ .withEscapeString("\\");
- String result = interpolator.interpolate( null );
+ String result = interpolator.interpolate(null);
- assertEquals( "", result );
+ assertEquals("", result);
}
@Test
- void testInterruptedInterpolate()
- throws InterpolationException
- {
- 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" );
+ void testInterruptedInterpolate() throws InterpolationException {
+ 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
- {
+ } else {
return null;
}
}
};
- FixedStringSearchInterpolator interpolator = create( valueSource );
+ FixedStringSearchInterpolator interpolator = create(valueSource);
- assertEquals( "-val-", interpolator.interpolate( "-${key}-" ) , "control case");
+ assertEquals("-val-", interpolator.interpolate("-${key}-"), "control case");
error[0] = true;
- assertThrows( IllegalStateException.class, () -> interpolator.interpolate( "-${key}-" ) ,
+ assertThrows(
+ IllegalStateException.class,
+ () -> interpolator.interpolate("-${key}-"),
"should have thrown exception");
error[0] = false;
- assertEquals( "-val-", interpolator.interpolate( "-${key}-" ) , "should not believe there is a cycle here");
+ assertEquals("-val-", interpolator.interpolate("-${key}-"), "should not believe there is a cycle here");
}
- public String getVar()
- {
+ public String getVar() {
return "testVar";
}
- public Person[] getAnArray()
- {
+ public Person[] getAnArray() {
Person[] array = new Person[3];
- array[0] = new Person( "Gabriel" );
- array[1] = new Person( "Daniela" );
- array[2] = new Person( "testIndexedWithArray" );
+ array[0] = new Person("Gabriel");
+ array[1] = new Person("Daniela");
+ array[2] = new Person("testIndexedWithArray");
return array;
}
- public List getList()
- {
+ public List getList() {
List list = new ArrayList();
- list.add( new Person( "Gabriel" ) );
- list.add( new Person( "testIndexedWithList" ) );
- list.add( new Person( "Daniela" ) );
+ list.add(new Person("Gabriel"));
+ list.add(new Person("testIndexedWithList"));
+ list.add(new Person("Daniela"));
return list;
}
- public Map getMap()
- {
+ public Map getMap() {
Map map = new HashMap();
- map.put( "Key with spaces", new Person( "testMap" ) );
+ map.put("Key with spaces", new Person("testMap"));
return map;
}
- public static class Person
- {
+ public static class Person {
private String name;
- public Person( String name )
- {
+ public Person(String name) {
this.name = name;
}
- public String getName()
- {
+ public String getName() {
return name;
}
}
@Test
- void testLinkedInterpolators()
- {
+ void testLinkedInterpolators() {
final String EXPR = "${test.label}AND${test2}";
final String EXPR2 = "${test.label}${test2.label}AND${test2}";
FixedStringSearchInterpolator interWith2Fields =
- create( properttyBasedValueSource( "test.label", "p", "test2", "x" ) );
- assertEquals( "pANDx", interWith2Fields.interpolate( EXPR ) );
+ create(properttyBasedValueSource("test.label", "p", "test2", "x"));
+ assertEquals("pANDx", interWith2Fields.interpolate(EXPR));
- FixedStringSearchInterpolator joined =
- create( interWith2Fields, properttyBasedValueSource( "test2.label", "zz" ) );
- assertEquals( "pzzANDx", joined.interpolate( EXPR2 ) );
+ FixedStringSearchInterpolator joined = create(interWith2Fields, properttyBasedValueSource("test2.label", "zz"));
+ assertEquals("pzzANDx", joined.interpolate(EXPR2));
}
@Test
- void testDominance()
- {
+ void testDominance() {
final String EXPR = "${test.label}AND${test2}";
final String EXPR2 = "${test.label}${test2.label}AND${test2}";
FixedStringSearchInterpolator interWith2Fields =
- create( properttyBasedValueSource( "test.label", "p", "test2", "x", "test2.label", "dominant" ) );
- assertEquals( "pANDx", interWith2Fields.interpolate( EXPR ) );
+ create(properttyBasedValueSource("test.label", "p", "test2", "x", "test2.label", "dominant"));
+ assertEquals("pANDx", interWith2Fields.interpolate(EXPR));
- FixedStringSearchInterpolator joined =
- create( interWith2Fields, properttyBasedValueSource( "test2.label", "zz" ) );
- assertEquals( "pdominantANDx", joined.interpolate( EXPR2 ) );
+ FixedStringSearchInterpolator joined = create(interWith2Fields, properttyBasedValueSource("test2.label", "zz"));
+ assertEquals("pdominantANDx", joined.interpolate(EXPR2));
}
@Test
- void unresolable_linked()
- {
+ void unresolable_linked() {
final String EXPR2 = "${test.label}${test2.label}AND${test2}";
FixedStringSearchInterpolator interWith2Fields =
- create( properttyBasedValueSource( "test.label", "p", "test2", "x", "test2.label", "dominant" ) );
+ create(properttyBasedValueSource("test.label", "p", "test2", "x", "test2.label", "dominant"));
- FixedStringSearchInterpolator joined =
- create( interWith2Fields, properttyBasedValueSource( "test2.label", "zz" ) );
- assertEquals( "pdominantANDx", joined.interpolate( EXPR2 ) );
+ FixedStringSearchInterpolator joined = create(interWith2Fields, properttyBasedValueSource("test2.label", "zz"));
+ assertEquals("pdominantANDx", joined.interpolate(EXPR2));
}
@Test
- void testCyclesWithLinked()
- {
- assertThrows( InterpolationCycleException.class, () -> {
- FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "${key2}" ) );
- FixedStringSearchInterpolator second = create( first, properttyBasedValueSource( "key2", "${key1}" ) );
- second.interpolate( "${key2}" );
- } );
+ void testCyclesWithLinked() {
+ assertThrows(InterpolationCycleException.class, () -> {
+ FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}"));
+ FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}"));
+ 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 testCyclesWithLinked_betweenRootAndOther() {
+ assertThrows(InterpolationCycleException.class, () -> {
+ FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}"));
+ FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}"));
+ second.interpolate("${key1}");
+ });
}
@Test
- void fixedInjectedIntoRegular()
- throws InterpolationException
- {
- FixedStringSearchInterpolator first = create( properttyBasedValueSource( "key1", "v1" ) );
+ void fixedInjectedIntoRegular() throws InterpolationException {
+ FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "v1"));
Properties p = new Properties();
- p.setProperty( "key", "X" );
- StringSearchInterpolator interpolator = new StringSearchInterpolator( "${", "}" );
- interpolator.setEscapeString( "\\" );
- interpolator.addValueSource( new org.codehaus.plexus.interpolation.PropertiesBasedValueSource( p ) );
- interpolator.addValueSource( new FixedInterpolatorValueSource( first ) );
- assertEquals("v1X", interpolator.interpolate( "${key1}${key}" ));
-
+ p.setProperty("key", "X");
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("${", "}");
+ interpolator.setEscapeString("\\");
+ interpolator.addValueSource(new org.codehaus.plexus.interpolation.PropertiesBasedValueSource(p));
+ interpolator.addValueSource(new FixedInterpolatorValueSource(first));
+ assertEquals("v1X", interpolator.interpolate("${key1}${key}"));
}
- private PropertiesBasedValueSource properttyBasedValueSource( String... values )
- {
+ private PropertiesBasedValueSource properttyBasedValueSource(String... values) {
Properties p = new Properties();
- for ( int i = 0; i < values.length; i += 2 )
- {
- p.setProperty( values[i], values[i + 1] );
+ for (int i = 0; i < values.length; i += 2) {
+ p.setProperty(values[i], values[i + 1]);
}
- return new PropertiesBasedValueSource( p );
+ return new PropertiesBasedValueSource(p);
}
}
-
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 98190b2..95ab97d 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java
@@ -24,6 +24,12 @@
* SOFTWARE.
*/
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
@@ -31,361 +37,309 @@
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;
/**
* InterpolatorFilterReaderTest, heavily based on InterpolationFilterReaderTest. Heh, even the test strings remained the
* same!
- *
+ *
* @author cstamas
- *
+ *
*/
-public class MultiDelimiterInterpolatorFilterReaderTest
-{
+public 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
- {
+ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "TestValue" );
+ m.put("test", "TestValue");
String testStr = "This is a ${test";
- assertEquals( "This is a ${test", interpolate( testStr, m ) );
+ assertEquals("This is a ${test", interpolate(testStr, m));
}
/*
* kenneyw@14-04-2005 Added test to check above fix.
*/
@Test
- public void testShouldNotInterpolateExpressionWithMissingEndToken()
- throws Exception
- {
+ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "TestValue" );
+ m.put("test", "TestValue");
String testStr = "This is a ${test, really";
- assertEquals( "This is a ${test, really", interpolate( testStr, m ) );
+ assertEquals("This is a ${test, really", interpolate(testStr, m));
}
@Test
- public void testShouldNotInterpolateWithMalformedStartToken()
- throws Exception
- {
+ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "testValue" );
+ m.put("test", "testValue");
String foo = "This is a $!test} again";
- assertEquals( "This is a $!test} again", interpolate( foo, m ) );
+ assertEquals("This is a $!test} again", interpolate(foo, m));
}
@Test
- public void testShouldNotInterpolateWithMalformedEndToken()
- throws Exception
- {
+ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception {
Map m = new HashMap();
- m.put( "test", "testValue" );
+ m.put("test", "testValue");
String foo = "This is a ${test!} again";
- assertEquals( "This is a ${test!} again", interpolate( foo, m ) );
+ assertEquals("This is a ${test!} again", interpolate(foo, m));
}
@Test
- public void testDefaultInterpolationWithNonInterpolatedValueAtEnd()
- throws Exception
- {
+ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "${name} is an ${noun}. ${not.interpolated}";
- assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) );
+ assertEquals("jason is an asshole. ${not.interpolated}", interpolate(foo, m));
}
@Test
- public void testDefaultInterpolationWithInterpolatedValueAtEnd()
- throws Exception
- {
+ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "${name} is an ${noun}";
- assertEquals( "jason is an asshole", interpolate( foo, m ) );
+ assertEquals("jason is an asshole", interpolate(foo, m));
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomToken()
- throws Exception
- {
+ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "@{name} is an @{noun}";
- assertEquals( "jason is an asshole", interpolate( foo, m, "@{", "}" ) );
+ assertEquals("jason is an asshole", interpolate(foo, m, "@{", "}"));
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString()
- throws Exception
- {
+ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "@name@ is an @noun@";
- assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) );
+ assertEquals("jason is an asshole", interpolate(foo, m, "@", "@"));
}
@Test
- public void testEscape()
- throws Exception
- {
+ public void testEscape() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "${name} is an \\${noun}";
- assertEquals( "jason is an ${noun}", interpolate( foo, m, "\\" ) );
+ assertEquals("jason is an ${noun}", interpolate(foo, m, "\\"));
}
@Test
- public void testEscapeAtStart()
- throws Exception
- {
+ public void testEscapeAtStart() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "\\${name} is an \\${noun}";
- assertEquals( "${name} is an ${noun}", interpolate( foo, m, "\\" ) );
+ assertEquals("${name} is an ${noun}", interpolate(foo, m, "\\"));
}
@Test
- public void testEscapeOnlyAtStart()
- throws Exception
- {
+ public void testEscapeOnlyAtStart() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "\\@name@ is an @noun@";
- String result = interpolate( foo, m, "@", "@" );
- assertEquals( "@name@ is an asshole", result );
+ String result = interpolate(foo, m, "@", "@");
+ assertEquals("@name@ is an asshole", result);
}
@Test
- public void testEscapeOnlyAtStartDefaultToken()
- throws Exception
- {
+ public void testEscapeOnlyAtStartDefaultToken() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ m.put("name", "jason");
+ m.put("noun", "asshole");
String foo = "\\${name} is an ${noun}";
- String result = interpolate( foo, m, "${", "}" );
- assertEquals( "${name} is an asshole", result );
+ String result = interpolate(foo, m, "${", "}");
+ assertEquals("${name} is an asshole", result);
}
@Test
- public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes()
- throws Exception
- {
+ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
List prefixes = new ArrayList();
- prefixes.add( "prefix1" );
- prefixes.add( "prefix2" );
+ prefixes.add("prefix1");
+ prefixes.add("prefix2");
- RecursionInterceptor ri = new PrefixAwareRecursionInterceptor( prefixes, false );
+ RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
Map context = new HashMap();
- context.put( "name", "${prefix2.name}" );
+ context.put("name", "${prefix2.name}");
String input = "${prefix1.name}";
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new MapBasedValueSource( context ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- MultiDelimiterInterpolatorFilterReader r = new MultiDelimiterInterpolatorFilterReader( new StringReader( input ),
- interpolator, ri );
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ MultiDelimiterInterpolatorFilterReader r =
+ new MultiDelimiterInterpolatorFilterReader(new StringReader(input), interpolator, ri);
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
- assertEquals( input, buf.toString() );
+ assertEquals(input, buf.toString());
}
@Test
- public void testShouldDetectRecursiveExpressionWithPrefixAndWithout()
- throws Exception
- {
+ public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
List prefixes = new ArrayList();
- prefixes.add( "prefix1" );
+ prefixes.add("prefix1");
- RecursionInterceptor ri = new PrefixAwareRecursionInterceptor( prefixes, false );
+ RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
Map context = new HashMap();
- context.put( "name", "${prefix1.name}" );
+ context.put("name", "${prefix1.name}");
String input = "${name}";
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new MapBasedValueSource( context ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- MultiDelimiterInterpolatorFilterReader r = new MultiDelimiterInterpolatorFilterReader( new StringReader( input ),
- interpolator, ri );
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ MultiDelimiterInterpolatorFilterReader r =
+ new MultiDelimiterInterpolatorFilterReader(new StringReader(input), interpolator, ri);
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
- assertEquals( "${prefix1.name}", buf.toString() );
+ assertEquals("${prefix1.name}", buf.toString());
}
@Test
- public void testInterpolationWithMultipleTokenTypes()
- throws Exception
- {
+ public void testInterpolationWithMultipleTokenTypes() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "otherName", "@name@" );
+ m.put("name", "jason");
+ m.put("otherName", "@name@");
String foo = "${otherName}";
- assertEquals( "jason", interpolateMulti( foo, m, new String[] { "${*}", "@*@" } ) );
+ assertEquals("jason", interpolateMulti(foo, m, new String[] {"${*}", "@*@"}));
}
@Test
- public void testInterpolationWithMultipleTokenTypes_ReversedOrdering()
- throws Exception
- {
+ public void testInterpolationWithMultipleTokenTypes_ReversedOrdering() throws Exception {
Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "otherName", "${name}" );
+ m.put("name", "jason");
+ m.put("otherName", "${name}");
String foo = "@otherName@";
- assertEquals( "jason", interpolateMulti( foo, m, new String[] { "${*}", "@*@" } ) );
+ assertEquals("jason", interpolateMulti(foo, m, new String[] {"${*}", "@*@"}));
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- private String interpolate( String input, Map context )
- throws Exception
- {
- return interpolate( input, context, null );
+ 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 ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- MultiDelimiterInterpolatorFilterReader r = new MultiDelimiterInterpolatorFilterReader( new StringReader( input ), interpolator );
- r.setInterpolateWithPrefixPattern( false );
- if ( escapeStr != null )
- {
- r.setEscapeString( escapeStr );
+ MultiDelimiterInterpolatorFilterReader r =
+ new MultiDelimiterInterpolatorFilterReader(new StringReader(input), interpolator);
+ r.setInterpolateWithPrefixPattern(false);
+ if (escapeStr != null) {
+ r.setEscapeString(escapeStr);
}
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
return buf.toString();
}
- private String interpolate( String input, Map context, String beginToken, String endToken )
- throws Exception
- {
- StringSearchInterpolator interpolator = new StringSearchInterpolator( beginToken, endToken );
+ private String interpolate(String input, Map context, String beginToken, String endToken) throws Exception {
+ StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken);
- interpolator.addValueSource( new MapBasedValueSource( context ) );
+ interpolator.addValueSource(new MapBasedValueSource(context));
- MultiDelimiterInterpolatorFilterReader r = new MultiDelimiterInterpolatorFilterReader( new StringReader( input ), interpolator );
- r.addDelimiterSpec( beginToken + "*" + endToken );
+ MultiDelimiterInterpolatorFilterReader r =
+ new MultiDelimiterInterpolatorFilterReader(new StringReader(input), interpolator);
+ r.addDelimiterSpec(beginToken + "*" + endToken);
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
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 ) );
+ interp.addValueSource(new MapBasedValueSource(context));
- MultiDelimiterInterpolatorFilterReader r = new MultiDelimiterInterpolatorFilterReader( new StringReader( input ), interp );
+ MultiDelimiterInterpolatorFilterReader r =
+ new MultiDelimiterInterpolatorFilterReader(new StringReader(input), interp);
- for ( String spec : specs )
- {
- interp.addDelimiterSpec( spec );
- r.addDelimiterSpec( spec );
+ for (String spec : specs) {
+ interp.addDelimiterSpec(spec);
+ r.addDelimiterSpec(spec);
}
- r.setInterpolateWithPrefixPattern( false );
- r.setEscapeString( "\\" );
+ r.setInterpolateWithPrefixPattern(false);
+ r.setEscapeString("\\");
StringBuilder buf = new StringBuilder();
int read = -1;
char[] cbuf = new char[1024];
- while ( ( read = r.read( cbuf ) ) > -1 )
- {
- buf.append( cbuf, 0, read );
+ while ((read = r.read(cbuf)) > -1) {
+ buf.append(cbuf, 0, read);
}
return buf.toString();
}
-
}
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 4d4cdc8..2c5fe2f 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java
@@ -16,115 +16,107 @@
* limitations under the License.
*/
+import java.util.HashMap;
+import java.util.Map;
+
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.ValueSource;
import org.junit.jupiter.api.Test;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class MultiDelimiterStringSearchInterpolatorTest
-{
+public class MultiDelimiterStringSearchInterpolatorTest {
@Test
- public void testInterpolationWithDifferentDelimiters()
- throws InterpolationException
- {
+ public void testInterpolationWithDifferentDelimiters() throws InterpolationException {
Map ctx = new HashMap();
- ctx.put( "name", "User" );
- ctx.put( "otherName", "@name@" );
+ ctx.put("name", "User");
+ ctx.put("otherName", "@name@");
String input = "${otherName}";
- ValueSource vs = new MapBasedValueSource( ctx );
- MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator().addDelimiterSpec( "@" )
- .withValueSource( vs );
+ ValueSource vs = new MapBasedValueSource(ctx);
+ MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator()
+ .addDelimiterSpec("@")
+ .withValueSource(vs);
- String result = interpolator.interpolate( input );
+ String result = interpolator.interpolate(input);
- assertEquals( ctx.get( "name" ), result );
+ assertEquals(ctx.get("name"), result);
}
@Test
public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiterSequence()
- throws InterpolationException
- {
+ throws InterpolationException {
Map ctx = new HashMap();
- ctx.put( "name", "User" );
- ctx.put( "otherName", "${name}" );
+ ctx.put("name", "User");
+ ctx.put("otherName", "${name}");
String input = "@otherName@";
- ValueSource vs = new MapBasedValueSource( ctx );
- MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator().addDelimiterSpec( "@" )
- .withValueSource( vs );
+ ValueSource vs = new MapBasedValueSource(ctx);
+ MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator()
+ .addDelimiterSpec("@")
+ .withValueSource(vs);
- String result = interpolator.interpolate( input );
+ String result = interpolator.interpolate(input);
- assertEquals( ctx.get( "name" ), result );
+ assertEquals(ctx.get("name"), result);
}
@Test
- public void testInterpolationWithMultipleEscapes()
- throws InterpolationException
- {
- Map ctx = new HashMap();
- ctx.put( "name", "User" );
- ctx.put( "otherName", "##${first} and #${last}" );
+ public void testInterpolationWithMultipleEscapes() throws InterpolationException {
+ Map ctx = new HashMap();
+ ctx.put("name", "User");
+ ctx.put("otherName", "##${first} and #${last}");
- String input = "${otherName}";
+ String input = "${otherName}";
- ValueSource vs = new MapBasedValueSource( ctx );
- MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator()
- .withValueSource( vs );
- interpolator.setEscapeString("#");
+ ValueSource vs = new MapBasedValueSource(ctx);
+ MultiDelimiterStringSearchInterpolator interpolator =
+ new MultiDelimiterStringSearchInterpolator().withValueSource(vs);
+ interpolator.setEscapeString("#");
- String result = interpolator.interpolate( input );
+ String result = interpolator.interpolate(input);
- assertEquals( "#${first} and ${last}", result );
- }
+ assertEquals("#${first} and ${last}", result);
+ }
@Test
- public void testInterpolationWithMultipleEscapes2()
- throws InterpolationException
- {
+ public void testInterpolationWithMultipleEscapes2() throws InterpolationException {
Map ctx = new HashMap();
- ctx.put( "name", "User" );
- ctx.put( "otherName", "#${first} and ##${last}" );
+ ctx.put("name", "User");
+ ctx.put("otherName", "#${first} and ##${last}");
String input = "${otherName}";
- ValueSource vs = new MapBasedValueSource( ctx );
+ ValueSource vs = new MapBasedValueSource(ctx);
MultiDelimiterStringSearchInterpolator interpolator =
- new MultiDelimiterStringSearchInterpolator().withValueSource( vs );
- interpolator.setEscapeString( "#" );
+ new MultiDelimiterStringSearchInterpolator().withValueSource(vs);
+ interpolator.setEscapeString("#");
- String result = interpolator.interpolate( input );
+ String result = interpolator.interpolate(input);
- assertEquals( "${first} and #${last}", result );
+ assertEquals("${first} and #${last}", result);
}
@Test
- public void testInterpolationWithMultipleEscapes3()
- throws InterpolationException
- {
+ public void testInterpolationWithMultipleEscapes3() throws InterpolationException {
Map ctx = new HashMap();
- ctx.put( "name", "User" );
- ctx.put( "last", "beer" );
- ctx.put( "otherName", "###${first} and ##${second} and ${last}" );
+ ctx.put("name", "User");
+ ctx.put("last", "beer");
+ ctx.put("otherName", "###${first} and ##${second} and ${last}");
String input = "${otherName}";
- ValueSource vs = new MapBasedValueSource( ctx );
+ ValueSource vs = new MapBasedValueSource(ctx);
MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator() //
- .withValueSource( vs ) //
- .escapeString( "#" );
+ .withValueSource(vs) //
+ .escapeString("#");
- String result = interpolator.interpolate( input );
+ String result = interpolator.interpolate(input);
- assertEquals( "##${first} and #${second} and beer", result );
+ assertEquals("##${first} and #${second} and beer", result);
}
}
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 57d6e96..08c8ad8 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java
@@ -16,8 +16,6 @@
* limitations under the License.
*/
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -29,261 +27,236 @@
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.junit.jupiter.api.Test;
-public class FieldBasedObjectInterpolatorTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class FieldBasedObjectInterpolatorTest {
@Test
- public void testInterpolateStringArray()
- throws Exception
- {
+ public void testInterpolateStringArray() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- String[] values = { "${key}", "${key2}" };
+ String[] values = {"${key}", "${key2}"};
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( values, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(values, interpolator);
- assertEquals( "value", values[0] );
- assertEquals( "value2", values[1] );
+ assertEquals("value", values[0]);
+ assertEquals("value2", values[1]);
}
@Test
- public void testInterpolateObjectWithStringArrayField()
- throws Exception
- {
+ public void testInterpolateObjectWithStringArrayField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- String[] values = { "${key}", "${key2}" };
+ String[] values = {"${key}", "${key2}"};
- ObjectWithStringArrayField obj = new ObjectWithStringArrayField( values );
+ ObjectWithStringArrayField obj = new ObjectWithStringArrayField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "value", obj.values[0] );
- assertEquals( "value2", obj.values[1] );
+ assertEquals("value", obj.values[0]);
+ assertEquals("value2", obj.values[1]);
}
@Test
- public void testInterpolateObjectWithStringListField()
- throws Exception
- {
+ public void testInterpolateObjectWithStringListField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
List values = new ArrayList();
- values.add( "${key}" );
- values.add( "${key2}" );
+ values.add("${key}");
+ values.add("${key2}");
- ObjectWithListField obj = new ObjectWithListField( values );
+ ObjectWithListField obj = new ObjectWithListField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "value", obj.values.get( 0 ) );
- assertEquals( "value2", obj.values.get( 1 ) );
+ assertEquals("value", obj.values.get(0));
+ assertEquals("value2", obj.values.get(1));
}
@Test
- public void testInterpolateObjectWithStringListFieldAndOneLiteralValue()
- throws Exception
- {
+ public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
List values = new ArrayList();
- values.add( "key" );
- values.add( "${key2}" );
+ values.add("key");
+ values.add("${key2}");
- ObjectWithListField obj = new ObjectWithListField( values );
+ ObjectWithListField obj = new ObjectWithListField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "key", obj.values.get( 0 ) );
- assertEquals( "value2", obj.values.get( 1 ) );
+ assertEquals("key", obj.values.get(0));
+ assertEquals("value2", obj.values.get(1));
}
@Test
- public void testInterpolateObjectWithUnmodifiableStringListField()
- throws Exception
- {
+ public void testInterpolateObjectWithUnmodifiableStringListField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- List values = Collections.unmodifiableList( Collections.singletonList( "${key}" ) );
+ List values = Collections.unmodifiableList(Collections.singletonList("${key}"));
- ObjectWithListField obj = new ObjectWithListField( values );
+ ObjectWithListField obj = new ObjectWithListField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "${key}", obj.values.get( 0 ) );
+ assertEquals("${key}", obj.values.get(0));
}
@Test
- public void testInterpolateObjectWithStringArrayListField()
- throws Exception
- {
+ public void testInterpolateObjectWithStringArrayListField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
- p.setProperty( "key3", "value3" );
- p.setProperty( "key4", "value4" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
+ p.setProperty("key3", "value3");
+ p.setProperty("key4", "value4");
List values = new ArrayList();
- values.add( new String[] { "${key}", "${key2}" } );
- values.add( new String[] { "${key3}", "${key4}" } );
+ values.add(new String[] {"${key}", "${key2}"});
+ values.add(new String[] {"${key3}", "${key4}"});
- ObjectWithListField obj = new ObjectWithListField( values );
+ ObjectWithListField obj = new ObjectWithListField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "value", ( (String[]) obj.values.get( 0 ) )[0] );
- assertEquals( "value2", ( (String[]) obj.values.get( 0 ) )[1] );
- assertEquals( "value3", ( (String[]) obj.values.get( 1 ) )[0] );
- assertEquals( "value4", ( (String[]) obj.values.get( 1 ) )[1] );
+ assertEquals("value", ((String[]) obj.values.get(0))[0]);
+ assertEquals("value2", ((String[]) obj.values.get(0))[1]);
+ assertEquals("value3", ((String[]) obj.values.get(1))[0]);
+ assertEquals("value4", ((String[]) obj.values.get(1))[1]);
}
@Test
- public void testInterpolateObjectWithStringToStringMapField()
- throws Exception
- {
+ public void testInterpolateObjectWithStringToStringMapField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- Map values = new HashMap();
- values.put( "key", "${key}" );
- values.put( "key2", "${key2}" );
+ Map values = new HashMap();
+ values.put("key", "${key}");
+ values.put("key2", "${key2}");
- ObjectWithMapField obj = new ObjectWithMapField( values );
+ ObjectWithMapField obj = new ObjectWithMapField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "value", obj.values.get( "key" ) );
- assertEquals( "value2", obj.values.get( "key2" ) );
+ assertEquals("value", obj.values.get("key"));
+ assertEquals("value2", obj.values.get("key2"));
}
@Test
- public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue()
- throws Exception
- {
+ public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- Map values = new HashMap();
- values.put( "key", "val" );
- values.put( "key2", "${key2}" );
+ Map values = new HashMap();
+ values.put("key", "val");
+ values.put("key2", "${key2}");
- ObjectWithMapField obj = new ObjectWithMapField( values );
+ ObjectWithMapField obj = new ObjectWithMapField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "val", obj.values.get( "key" ) );
- assertEquals( "value2", obj.values.get( "key2" ) );
+ assertEquals("val", obj.values.get("key"));
+ assertEquals("value2", obj.values.get("key2"));
}
@Test
- public void testInterpolateObjectWithUnmodifiableStringToStringMapField()
- throws Exception
- {
+ public void testInterpolateObjectWithUnmodifiableStringToStringMapField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
- Map values = Collections.unmodifiableMap( Collections.singletonMap( "key", "${key}" ) );
+ Map values = Collections.unmodifiableMap(Collections.singletonMap("key", "${key}"));
- ObjectWithMapField obj = new ObjectWithMapField( values );
+ ObjectWithMapField obj = new ObjectWithMapField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "${key}", obj.values.get( "key" ) );
+ assertEquals("${key}", obj.values.get("key"));
}
@Test
- public void testInterpolateObjectWithStringToStringArrayMapField()
- throws Exception
- {
+ public void testInterpolateObjectWithStringToStringArrayMapField() throws Exception {
Properties p = new Properties();
- p.setProperty( "key", "value" );
- p.setProperty( "key2", "value2" );
- p.setProperty( "key3", "value3" );
- p.setProperty( "key4", "value4" );
+ p.setProperty("key", "value");
+ p.setProperty("key2", "value2");
+ p.setProperty("key3", "value3");
+ p.setProperty("key4", "value4");
- Map values = new HashMap();
- values.put( "key", new String[] { "${key}", "${key2}" } );
- values.put( "key2", new String[] { "${key3}", "${key4}" } );
+ Map values = new HashMap();
+ values.put("key", new String[] {"${key}", "${key2}"});
+ values.put("key2", new String[] {"${key3}", "${key4}"});
- ObjectWithMapField obj = new ObjectWithMapField( values );
+ ObjectWithMapField obj = new ObjectWithMapField(values);
StringSearchInterpolator interpolator = new StringSearchInterpolator();
- interpolator.addValueSource( new PropertiesBasedValueSource( p ) );
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
- new FieldBasedObjectInterpolator().interpolate( obj, interpolator );
+ new FieldBasedObjectInterpolator().interpolate(obj, interpolator);
- assertEquals( "value", ( (String[]) obj.values.get( "key" ) )[0] );
- assertEquals( "value2", ( (String[]) obj.values.get( "key" ) )[1] );
- assertEquals( "value3", ( (String[]) obj.values.get( "key2" ) )[0] );
- assertEquals( "value4", ( (String[]) obj.values.get( "key2" ) )[1] );
+ assertEquals("value", ((String[]) obj.values.get("key"))[0]);
+ assertEquals("value2", ((String[]) obj.values.get("key"))[1]);
+ assertEquals("value3", ((String[]) obj.values.get("key2"))[0]);
+ assertEquals("value4", ((String[]) obj.values.get("key2"))[1]);
}
- private static final class ObjectWithStringArrayField
- {
+ private static final class ObjectWithStringArrayField {
private final String[] values;
- public ObjectWithStringArrayField( String[] values )
- {
+ public ObjectWithStringArrayField(String[] values) {
this.values = values;
}
}
- private static final class ObjectWithListField
- {
+ private static final class ObjectWithListField {
private final List values;
- public ObjectWithListField( List values )
- {
+ public ObjectWithListField(List values) {
this.values = values;
}
}
- private static final class ObjectWithMapField
- {
+ private static final class ObjectWithMapField {
private final Map values;
- public ObjectWithMapField( Map values )
- {
+ public ObjectWithMapField(Map values) {
this.values = values;
}
}
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 cfc17ce..d788f63 100644
--- a/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java
@@ -15,18 +15,15 @@
* limitations under the License.
*/
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
import org.junit.jupiter.api.Test;
-public class StringUtilsTest
-{
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class StringUtilsTest {
@Test
- public void testCapitalizeFirstLetter()
- throws Exception
- {
- assertEquals( "Abc", StringUtils.capitalizeFirstLetter( "abc" ) );
- assertEquals( "\u00cdce", StringUtils.capitalizeFirstLetter( "\u00edce" ) );
- assertEquals( "X", StringUtils.capitalizeFirstLetter( "x" ) );
+ public void testCapitalizeFirstLetter() throws Exception {
+ assertEquals("Abc", StringUtils.capitalizeFirstLetter("abc"));
+ assertEquals("\u00cdce", StringUtils.capitalizeFirstLetter("\u00edce"));
+ assertEquals("X", StringUtils.capitalizeFirstLetter("x"));
}
}