You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2014/02/13 00:16:51 UTC

svn commit: r1567794 - in /maven/shared/trunk/maven-filtering: ./ src/main/java/org/apache/maven/shared/filtering/ src/test/java/org/apache/maven/shared/filtering/

Author: rfscholte
Date: Wed Feb 12 23:16:50 2014
New Revision: 1567794

URL: http://svn.apache.org/r1567794
Log:
[MSHARED-198] custom delimiters doesn't work as expected
Fixed for InterpolatorFilterReaderLineEnding as well
MSHARED-198 + MSHARED-199 with real unit-test
Introduced mockito

Added:
    maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java
    maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java
    maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java
Modified:
    maven/shared/trunk/maven-filtering/pom.xml
    maven/shared/trunk/maven-filtering/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java

Modified: maven/shared/trunk/maven-filtering/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/pom.xml?rev=1567794&r1=1567793&r2=1567794&view=diff
==============================================================================
--- maven/shared/trunk/maven-filtering/pom.xml (original)
+++ maven/shared/trunk/maven-filtering/pom.xml Wed Feb 12 23:16:50 2014
@@ -133,6 +133,12 @@
     </dependency>
 
     <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>1.9.5</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.9</version>

Modified: maven/shared/trunk/maven-filtering/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java?rev=1567794&r1=1567793&r2=1567794&view=diff
==============================================================================
--- maven/shared/trunk/maven-filtering/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java (original)
+++ maven/shared/trunk/maven-filtering/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java Wed Feb 12 23:16:50 2014
@@ -311,7 +311,8 @@ public class InterpolatorFilterReaderLin
         in.skip( beginToken.length() );
         ch = in.read();
 
-        int end = endToken.length();
+        int endTokenSize = endToken.length();
+        int end = endTokenSize;
         do
         {
             if ( ch == -1 )
@@ -327,7 +328,7 @@ public class InterpolatorFilterReaderLin
 
             key.append( (char) ch );
 
-            if ( ch == this.endToken.charAt( end - 1 ) )
+            if ( ch == this.endToken.charAt( endTokenSize - end ) )
             {
                 end--;
                 if ( end == 0 )
@@ -337,7 +338,7 @@ public class InterpolatorFilterReaderLin
             }
             else
             {
-                end = endToken.length();
+                end = endTokenSize;
             }
 
             ch = in.read();

Added: maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java?rev=1567794&view=auto
==============================================================================
--- maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java (added)
+++ maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java Wed Feb 12 23:16:50 2014
@@ -0,0 +1,72 @@
+package org.apache.maven.shared.filtering;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.when;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public abstract class AbstractInterpolatorFilterReaderLineEndingTest
+{
+
+    @Mock 
+    private Interpolator interpolator;
+
+    @Before
+    public void onSetup()
+    {
+        MockitoAnnotations.initMocks( this );
+    }
+
+    // MSHARED-198: custom delimiters doesn't work as expected
+    @Test
+    public void testCustomDelimiters()
+        throws Exception
+    {
+        when( interpolator.interpolate( eq( "aaaFILTER.a.MEaaa" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE" );
+        when( interpolator.interpolate( eq( "abcFILTER.a.MEabc" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE" );
+    
+        Reader in = new StringReader( "aaaFILTER.a.MEaaa" );
+        Reader reader = getAaa_AaaReader( in, interpolator );
+            
+        assertEquals( "DONE", IOUtil.toString( reader ) );
+    
+        in = new StringReader( "abcFILTER.a.MEabc" );
+        reader = getAbc_AbcReader( in, interpolator );
+        assertEquals( "DONE", IOUtil.toString( reader ) );
+    }
+    
+    protected abstract Reader getAbc_AbcReader( Reader in, Interpolator interpolator );
+    
+    protected abstract Reader getAaa_AaaReader( Reader in, Interpolator interpolator );
+
+}
\ No newline at end of file

Added: maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java?rev=1567794&view=auto
==============================================================================
--- maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java (added)
+++ maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java Wed Feb 12 23:16:50 2014
@@ -0,0 +1,40 @@
+package org.apache.maven.shared.filtering;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.Reader;
+
+import org.codehaus.plexus.interpolation.Interpolator;
+
+public class InterpolatorFilterReaderLineEndingTest
+    extends AbstractInterpolatorFilterReaderLineEndingTest
+{
+    @Override
+    protected Reader getAaa_AaaReader( Reader in, Interpolator interpolator )
+    {
+        return new InterpolatorFilterReaderLineEnding( in, interpolator, "aaa", "aaa", true );
+    }
+
+    @Override
+    protected Reader getAbc_AbcReader( Reader in, Interpolator interpolator )
+    {
+        return new InterpolatorFilterReaderLineEnding( in, interpolator, "abc", "abc", true );
+    }
+}

Added: maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java?rev=1567794&view=auto
==============================================================================
--- maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java (added)
+++ maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java Wed Feb 12 23:16:50 2014
@@ -0,0 +1,84 @@
+package org.apache.maven.shared.filtering;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.when;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class MultiDelimiterInterpolatorFilterReaderLineEndingTest extends AbstractInterpolatorFilterReaderLineEndingTest
+{
+
+    @Mock 
+    private Interpolator interpolator;
+
+    @Before
+    public void onSetup()
+    {
+        MockitoAnnotations.initMocks( this );
+    }
+    
+    @Override
+    protected Reader getAaa_AaaReader( Reader in, Interpolator interpolator )
+    {
+        MultiDelimiterInterpolatorFilterReaderLineEnding reader = new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+        reader.setDelimiterSpecs( Collections.singleton( "aaa*aaa" ) );
+        return reader;
+    }
+    
+    @Override
+    protected Reader getAbc_AbcReader( Reader in, Interpolator interpolator )
+    {
+        MultiDelimiterInterpolatorFilterReaderLineEnding reader = new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+        reader.setDelimiterSpecs( Collections.singleton( "abc*abc" ) );
+        return reader;
+    }
+
+    // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open
+    @Test
+    public void testLineWithSingleAtAndExpression()
+        throws Exception
+    {
+        when( interpolator.interpolate( eq( "${foo}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "bar" );
+
+        Reader in = new StringReader( "toto@titi.com ${foo}" );
+        MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+            new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+        reader.setDelimiterSpecs( new HashSet<String>( Arrays.asList( "${*}", "@" ) ) );
+        
+        assertEquals( "toto@titi.com bar", IOUtil.toString( reader ) );
+    }
+
+}