You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/06/25 16:57:30 UTC

svn commit: r788374 - /maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2690MojoLoadingErrorsTest.java

Author: bentmann
Date: Thu Jun 25 14:57:30 2009
New Revision: 788374

URL: http://svn.apache.org/viewvc?rev=788374&view=rev
Log:
o Reduced coupling to format of warning

Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2690MojoLoadingErrorsTest.java

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2690MojoLoadingErrorsTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2690MojoLoadingErrorsTest.java?rev=788374&r1=788373&r2=788374&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2690MojoLoadingErrorsTest.java (original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2690MojoLoadingErrorsTest.java Thu Jun 25 14:57:30 2009
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import junit.framework.TestCase;
 
@@ -71,26 +72,11 @@
 
         List lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
 
-        boolean foundMessage = false;
-        boolean foundClass = false;
-        for ( Iterator it = lines.iterator(); it.hasNext(); )
-        {
-            String line = (String) it.next();
-            if ( line.indexOf( "A required class is missing" ) > -1 )
-            {
-                foundMessage = true;
-            }
-
-            // trigger AFTER the required-class message is found, since the class name should come afterward.
-            if ( foundMessage && line.replace( '/', '.' ).indexOf( TestCase.class.getName() ) > -1 )
-            {
-                foundClass = true;
-                break;
-            }
-        }
+        int msg = indexOf( lines, "(?i).*required class is missing.*" );
+        assertTrue( "User-friendly message was not found in output.", msg >= 0 );
 
-        assertTrue( "User-friendly message was not found in output.", foundMessage );
-        assertTrue( "Missing class name was not found in output.", foundClass );
+        int cls = lines.get( msg ).toString().replace( '/', '.' ).indexOf( TestCase.class.getName() );
+        assertTrue( "Missing class name was not found in output.", cls >= 0 );
     }
 
     public void testNoClassDefFromMojoConfiguration()
@@ -118,26 +104,11 @@
 
         List lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
 
-        boolean foundMessage = false;
-        boolean foundClass = false;
-        for ( Iterator it = lines.iterator(); it.hasNext(); )
-        {
-            String line = (String) it.next();
-            if ( line.indexOf( "A required class was missing during mojo configuration" ) > -1 )
-            {
-                foundMessage = true;
-            }
-
-            // trigger AFTER the required-class message is found, since the class name should come afterward.
-            if ( foundMessage && line.replace( '/', '.' ).indexOf( TestCase.class.getName() ) > -1 )
-            {
-                foundClass = true;
-                break;
-            }
-        }
+        int msg = indexOf( lines, "(?i).*required class was missing during mojo configuration.*" );
+        assertTrue( "User-friendly message was not found in output.", msg >= 0 );
 
-        assertTrue( "User-friendly message was not found in output.", foundMessage );
-        assertTrue( "Missing class name was not found in output.", foundClass );
+        int cls = lines.get( msg ).toString().replace( '/', '.' ).indexOf( TestCase.class.getName() );
+        assertTrue( "Missing class name was not found in output.", cls >= 0 );
     }
 
     public void testMojoComponentLookupException()
@@ -165,23 +136,11 @@
 
         List lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
 
-        String compLookupMessage =
-            "Unable to find the mojo 'mojo-component-lookup-exception' "
-                + "(or one of its required components) in the plugin "
-                + "'org.apache.maven.its.plugins:maven-it-plugin-error";
-
-        boolean foundMessage = false;
-        for ( Iterator it = lines.iterator(); it.hasNext(); )
-        {
-            String line = (String) it.next();
-            if ( line.indexOf( compLookupMessage ) > -1 )
-            {
-                foundMessage = true;
-                break;
-            }
-        }
+        String compLookupMsg =
+            "(?i).*unable to .* mojo 'mojo-component-lookup-exception' .* plugin "
+                + "'org\\.apache\\.maven\\.its\\.plugins:maven-it-plugin-error.*";
 
-        assertTrue( "User-friendly message was not found in output.", foundMessage );
+        assertTrue( "User-friendly message was not found in output.", indexOf( lines, compLookupMsg ) > 0 );
     }
 
     public void testMojoRequirementComponentLookupException()
@@ -209,23 +168,28 @@
 
         List lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
 
-        String compLookupMessage =
-            "Unable to find the mojo 'requirement-component-lookup-exception' "
-                + "(or one of its required components) in the plugin "
-                + "'org.apache.maven.its.plugins:maven-it-plugin-error";
+        String compLookupMsg =
+            "(?i).*unable to .* mojo 'requirement-component-lookup-exception' .* plugin "
+                + "'org\\.apache\\.maven\\.its\\.plugins:maven-it-plugin-error.*";
+
+        assertTrue( "User-friendly message was not found in output.", indexOf( lines, compLookupMsg ) > 0 );
+    }
+
+    private int indexOf( List logLines, String regex )
+    {
+        Pattern pattern = Pattern.compile( regex );
 
-        boolean foundMessage = false;
-        for ( Iterator it = lines.iterator(); it.hasNext(); )
+        for ( int i = 0; i < logLines.size(); i++ )
         {
-            String line = (String) it.next();
-            if ( line.indexOf( compLookupMessage ) > -1 )
+            String logLine = (String) logLines.get( i );
+
+            if ( pattern.matcher( logLine ).matches() )
             {
-                foundMessage = true;
-                break;
+                return i;
             }
         }
 
-        assertTrue( "User-friendly message was not found in output.", foundMessage );
+        return -1;
     }
 
 }