Revision: 296
Author: limpbizkit
Date: Sat Mar 1 15:31:08 2014 UTC
Log: Support @Ignore.
http://code.google.com/p/vogar/source/detail?r=296
Added:
/trunk/src/org/junit/Ignore.java
Modified:
/trunk/src/vogar/target/junit/Junit4.java
=======================================
--- /dev/null
+++ /trunk/src/org/junit/Ignore.java Sat Mar 1 15:31:08 2014 UTC
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed 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.junit;
+
+//Note: this class was written without inspecting the org.junit code
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Ignore {
+}
=======================================
--- /trunk/src/vogar/target/junit/Junit4.java Tue Apr 16 03:51:56 2013 UTC
+++ /trunk/src/vogar/target/junit/Junit4.java Sat Mar 1 15:31:08 2014 UTC
@@ -28,6 +28,7 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@@ -60,19 +61,13 @@
/* JUnit 4.x: methods marked with @Test annotation. */
if (args.length == 0) {
for (Method m : testClass.getMethods()) {
- boolean isTest = false;
- for (Annotation a : m.getAnnotations()) {
- if
(org.junit.Test.class.isAssignableFrom(a.annotationType())) {
- isTest = true;
- }
- }
- if (!isTest) {
- continue;
- }
+ if (!m.isAnnotationPresent(org.junit.Test.class)) continue;
isJunit4TestClass = true;
- if (m.getParameterTypes().length == 0) {
+ if (m.isAnnotationPresent(Ignore.class)) {
+ out.add(new IgnoredTest(testClass, m));
+ } else if (m.getParameterTypes().length == 0) {
addAllParameterizedTests(out, testClass, m,
argCollection);
} else {
out.add(new ConfigurationError(testClass.getName()
+ "#" + m.getName(),
@@ -209,8 +204,6 @@
Object testCase = getTestCase();
Throwable failure = null;
- // TODO: add @Ignore support
-
try {
Class.forName("org.mockito.MockitoAnnotations")
.getMethod("initMocks", Object.class)
@@ -332,6 +325,24 @@
@Override protected Object getTestCase() throws Exception {
return constructor.newInstance(constructorArgs);
}
+
+ @Override public String toString() {
+ return testClass.getName() + "#" + method.getName();
+ }
+ }
+
+ private static class IgnoredTest extends VogarJUnitTest {
+ private IgnoredTest(Class<?> testClass, Method method) {
+ super(testClass, method);
+ }
+
+ @Override public void run() throws Throwable {
+ System.out.println("@Ignored.");
+ }
+
+ @Override protected Object getTestCase() {
+ throw new UnsupportedOperationException();
+ }
@Override public String toString() {
return testClass.getName() + "#" + method.getName();