Author: stephenc
Date: Wed May 25 22:19:44 2011
New Revision: 1127708

URL: http://svn.apache.org/viewvc?rev=1127708&view=rev
Log:
add a rule to help when we start fixing the bugs in plexus

Added:
    
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/FixPlexusBugs.java

Added: 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/FixPlexusBugs.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/FixPlexusBugs.java?rev=1127708&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/FixPlexusBugs.java
 (added)
+++ 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/FixPlexusBugs.java
 Wed May 25 22:19:44 2011
@@ -0,0 +1,49 @@
+package org.apache.maven.tck;
+
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+/**
+ * A rule that checks for a resource called {@code /FixPlexusBugs.enforce} and 
if it exists, will invert the test
+ * result of any tests annotated with {@link ReproducesPlexusBug}. Obviously 
this invertion only occurs in test classes
+ * with this rule, e.g. have a public field like {@code @Rule public 
FixPlexusBugs fixPlexusBugs = new FixPlexusBugs();}
+ */
+public class FixPlexusBugs
+    implements MethodRule
+{
+    public Statement apply( final Statement base, FrameworkMethod method, 
Object target )
+    {
+        if ( method.getAnnotation( ReproducesPlexusBug.class ) == null )
+        {
+            return base;
+        }
+
+        if ( getClass().getResource( "/" + getClass().getSimpleName() + 
".enforce" ) == null )
+        {
+            return base;
+        }
+        return new Statement()
+        {
+            @Override
+            public void evaluate()
+                throws Throwable
+            {
+                boolean passed;
+                try
+                {
+                    base.evaluate();
+                    passed = true;
+                }
+                catch ( AssertionError t )
+                {
+                    passed = false;
+                }
+                if ( passed )
+                {
+                    throw new AssertionError( "Test verifies a bug in original 
code that should now be fixed" );
+                }
+            }
+        };
+    }
+}


Reply via email to