polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [05/35] zest-java git commit: testsupport: introduce @NotYetImplemented annotation and its JUnit rule
Date Sat, 19 Nov 2016 22:50:06 GMT
testsupport: introduce @NotYetImplemented annotation and its JUnit rule

Do not ignore the test
Fail if it passes
Print stacktrace to stderr


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/93355d69
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/93355d69
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/93355d69

Branch: refs/heads/develop
Commit: 93355d69f8ad0e8f3702366b6825f75ea003db95
Parents: 8039b61
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Fri Nov 11 17:19:00 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Fri Nov 11 17:19:00 2016 +0100

----------------------------------------------------------------------
 .../apache/zest/test/AbstractZestBaseTest.java  |  4 +
 .../zest/test/util/NotYetImplemented.java       | 80 ++++++++++++++++++++
 2 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/93355d69/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
index a905a37..f785247 100644
--- a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
+++ b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
@@ -19,6 +19,7 @@
  */
 package org.apache.zest.test;
 
+import org.apache.zest.test.util.NotYetImplemented;
 import org.junit.After;
 import org.junit.Before;
 import org.apache.zest.api.ZestAPI;
@@ -30,9 +31,12 @@ import org.apache.zest.bootstrap.ApplicationAssemblyFactory;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.Energy4Java;
 import org.apache.zest.spi.ZestSPI;
+import org.junit.Rule;
 
 public abstract class AbstractZestBaseTest
 {
+    @Rule public NotYetImplemented.Rule notYetImplementedRule = new NotYetImplemented.Rule();
+
     protected ZestAPI api;
     protected ZestSPI spi;
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/93355d69/core/testsupport/src/main/java/org/apache/zest/test/util/NotYetImplemented.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/zest/test/util/NotYetImplemented.java
b/core/testsupport/src/main/java/org/apache/zest/test/util/NotYetImplemented.java
new file mode 100644
index 0000000..9b44ff4
--- /dev/null
+++ b/core/testsupport/src/main/java/org/apache/zest/test/util/NotYetImplemented.java
@@ -0,0 +1,80 @@
+/*
+ *  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.
+ */
+package org.apache.zest.test.util;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import junit.framework.AssertionFailedError;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * JUnit annotation and rule to mark not yet implemented tests.
+ *
+ * In order to use this annotation you must register the corresponding {@link NotYetImplemented.Rule}.
+ *
+ * Not yet implemented tests are run an expected to fail, an assertion error is thrown if
they pass.
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.TYPE, ElementType.METHOD } )
+@Documented
+public @interface NotYetImplemented
+{
+    String reason() default "";
+
+    class Rule implements TestRule
+    {
+        @Override
+        public Statement apply( Statement base, Description description )
+        {
+            if( description.getAnnotation( NotYetImplemented.class ) == null )
+            {
+                return base;
+            }
+            return new Statement()
+            {
+                @Override
+                public void evaluate() throws Throwable
+                {
+                    boolean passed = false;
+                    try
+                    {
+                        base.evaluate();
+                        passed = true;
+                    }
+                    catch( Throwable ex )
+                    {
+                        System.err.println( "Not yet implemented test expectedly failed"
);
+                        ex.printStackTrace( System.err );
+                    }
+                    if( passed )
+                    {
+                        throw new AssertionFailedError(
+                            "Test " + description.getDisplayName()
+                            + " is annotated as not yet implemented, expected it to fail
but it passed."
+                        );
+                    }
+                }
+            };
+        }
+    }
+}


Mime
View raw message