aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/runner
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/junit/runner')
-rw-r--r--src/main/java/org/junit/runner/Computer.java12
-rw-r--r--src/main/java/org/junit/runner/Describable.java2
-rw-r--r--src/main/java/org/junit/runner/Description.java13
-rw-r--r--src/main/java/org/junit/runner/FilterFactory.java3
-rw-r--r--src/main/java/org/junit/runner/JUnitCommandLineParseResult.java8
-rw-r--r--src/main/java/org/junit/runner/OrderWith.java28
-rw-r--r--src/main/java/org/junit/runner/OrderWithValidator.java38
-rw-r--r--src/main/java/org/junit/runner/Request.java58
-rw-r--r--src/main/java/org/junit/runner/Result.java31
-rw-r--r--src/main/java/org/junit/runner/manipulation/Alphanumeric.java27
-rw-r--r--src/main/java/org/junit/runner/manipulation/InvalidOrderingException.java21
-rw-r--r--src/main/java/org/junit/runner/manipulation/Orderable.java21
-rw-r--r--src/main/java/org/junit/runner/manipulation/Orderer.java62
-rw-r--r--src/main/java/org/junit/runner/manipulation/Ordering.java172
-rw-r--r--src/main/java/org/junit/runner/manipulation/Sortable.java2
-rw-r--r--src/main/java/org/junit/runner/manipulation/Sorter.java54
-rw-r--r--src/main/java/org/junit/runner/notification/Failure.java23
-rw-r--r--src/main/java/org/junit/runner/notification/RunListener.java28
-rw-r--r--src/main/java/org/junit/runner/notification/RunNotifier.java41
-rw-r--r--src/main/java/org/junit/runner/notification/SynchronizedRunListener.java33
20 files changed, 48 insertions, 629 deletions
diff --git a/src/main/java/org/junit/runner/Computer.java b/src/main/java/org/junit/runner/Computer.java
index 18d0d31..8bb4b20 100644
--- a/src/main/java/org/junit/runner/Computer.java
+++ b/src/main/java/org/junit/runner/Computer.java
@@ -30,17 +30,7 @@ public class Computer {
public Runner runnerForClass(Class<?> testClass) throws Throwable {
return getRunner(builder, testClass);
}
- }, classes) {
- @Override
- protected String getName() {
- /*
- * #1320 The generated suite is not based on a real class so
- * only a 'null' description can be generated from it. This name
- * will be overridden here.
- */
- return "classes";
- }
- };
+ }, classes);
}
/**
diff --git a/src/main/java/org/junit/runner/Describable.java b/src/main/java/org/junit/runner/Describable.java
index 293fdb3..1514141 100644
--- a/src/main/java/org/junit/runner/Describable.java
+++ b/src/main/java/org/junit/runner/Describable.java
@@ -10,5 +10,5 @@ public interface Describable {
/**
* @return a {@link Description} showing the tests to be run by the receiver
*/
- Description getDescription();
+ public abstract Description getDescription();
} \ No newline at end of file
diff --git a/src/main/java/org/junit/runner/Description.java b/src/main/java/org/junit/runner/Description.java
index 0846a1e..fe47eac 100644
--- a/src/main/java/org/junit/runner/Description.java
+++ b/src/main/java/org/junit/runner/Description.java
@@ -125,17 +125,6 @@ public class Description implements Serializable {
}
/**
- * Create a <code>Description</code> named after <code>testClass</code>
- *
- * @param testClass A not null {@link Class} containing tests
- * @param annotations meta-data about the test, for downstream interpreters
- * @return a <code>Description</code> of <code>testClass</code>
- */
- public static Description createSuiteDescription(Class<?> testClass, Annotation... annotations) {
- return new Description(testClass, testClass.getName(), annotations);
- }
-
- /**
* Describes a Runner which runs no tests
*/
public static final Description EMPTY = new Description(null, "No Tests");
@@ -150,7 +139,7 @@ public class Description implements Serializable {
/*
* We have to use the f prefix until the next major release to ensure
* serialization compatibility.
- * See https://github.com/junit-team/junit4/issues/976
+ * See https://github.com/junit-team/junit/issues/976
*/
private final Collection<Description> fChildren = new ConcurrentLinkedQueue<Description>();
private final String fDisplayName;
diff --git a/src/main/java/org/junit/runner/FilterFactory.java b/src/main/java/org/junit/runner/FilterFactory.java
index e2bfb73..57b4eaa 100644
--- a/src/main/java/org/junit/runner/FilterFactory.java
+++ b/src/main/java/org/junit/runner/FilterFactory.java
@@ -16,8 +16,7 @@ public interface FilterFactory {
/**
* Exception thrown if the {@link Filter} cannot be created.
*/
- @SuppressWarnings("serial")
- class FilterNotCreatedException extends Exception {
+ public static class FilterNotCreatedException extends Exception {
public FilterNotCreatedException(Exception exception) {
super(exception.getMessage(), exception);
}
diff --git a/src/main/java/org/junit/runner/JUnitCommandLineParseResult.java b/src/main/java/org/junit/runner/JUnitCommandLineParseResult.java
index 3383407..434157c 100644
--- a/src/main/java/org/junit/runner/JUnitCommandLineParseResult.java
+++ b/src/main/java/org/junit/runner/JUnitCommandLineParseResult.java
@@ -85,11 +85,13 @@ class JUnitCommandLineParseResult {
}
private String[] copyArray(String[] args, int from, int to) {
- String[] result = new String[to - from];
+ ArrayList<String> result = new ArrayList<String>();
+
for (int j = from; j != to; ++j) {
- result[j - from] = args[j];
+ result.add(args[j]);
}
- return result;
+
+ return result.toArray(new String[result.size()]);
}
void parseParameters(String[] args) {
diff --git a/src/main/java/org/junit/runner/OrderWith.java b/src/main/java/org/junit/runner/OrderWith.java
deleted file mode 100644
index e8470c9..0000000
--- a/src/main/java/org/junit/runner/OrderWith.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.junit.runner;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.junit.runner.manipulation.Ordering;
-import org.junit.validator.ValidateWith;
-
-/**
- * When a test class is annotated with <code>&#064;OrderWith</code> or extends a class annotated
- * with <code>&#064;OrderWith</code>, JUnit will order the tests in the test class (and child
- * test classes, if any) using the ordering defined by the {@link Ordering} class.
- *
- * @since 4.13
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-@Inherited
-@ValidateWith(OrderWithValidator.class)
-public @interface OrderWith {
- /**
- * Gets a class that extends {@link Ordering}. The class must have a public no-arg constructor.
- */
- Class<? extends Ordering.Factory> value();
-}
diff --git a/src/main/java/org/junit/runner/OrderWithValidator.java b/src/main/java/org/junit/runner/OrderWithValidator.java
deleted file mode 100644
index f8eab25..0000000
--- a/src/main/java/org/junit/runner/OrderWithValidator.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.junit.runner;
-
-import static java.util.Collections.emptyList;
-import static java.util.Collections.singletonList;
-
-import java.util.List;
-
-import org.junit.FixMethodOrder;
-import org.junit.runners.model.TestClass;
-import org.junit.validator.AnnotationValidator;
-
-/**
- * Validates that there are no errors in the use of the {@code OrderWith}
- * annotation. If there is, a {@code Throwable} object will be added to the list
- * of errors.
- *
- * @since 4.13
- */
-public final class OrderWithValidator extends AnnotationValidator {
-
- /**
- * Adds to {@code errors} a throwable for each problem detected. Looks for
- * {@code FixMethodOrder} annotations.
- *
- * @param testClass that is being validated
- * @return A list of exceptions detected
- *
- * @since 4.13
- */
- @Override
- public List<Exception> validateAnnotatedClass(TestClass testClass) {
- if (testClass.getAnnotation(FixMethodOrder.class) != null) {
- return singletonList(
- new Exception("@FixMethodOrder cannot be combined with @OrderWith"));
- }
- return emptyList();
- }
-}
diff --git a/src/main/java/org/junit/runner/Request.java b/src/main/java/org/junit/runner/Request.java
index 7b9a990..79c0f1e 100644
--- a/src/main/java/org/junit/runner/Request.java
+++ b/src/main/java/org/junit/runner/Request.java
@@ -5,11 +5,9 @@ import java.util.Comparator;
import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
import org.junit.internal.requests.ClassRequest;
import org.junit.internal.requests.FilterRequest;
-import org.junit.internal.requests.OrderingRequest;
import org.junit.internal.requests.SortingRequest;
import org.junit.internal.runners.ErrorReportingRunner;
import org.junit.runner.manipulation.Filter;
-import org.junit.runner.manipulation.Ordering;
import org.junit.runners.model.InitializationError;
/**
@@ -73,11 +71,12 @@ public abstract class Request {
*/
public static Request classes(Computer computer, Class<?>... classes) {
try {
- AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder();
+ AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(true);
Runner suite = computer.getSuite(builder, classes);
return runner(suite);
} catch (InitializationError e) {
- return runner(new ErrorReportingRunner(e, classes));
+ throw new RuntimeException(
+ "Bug in saff's brain: Suite constructor, called as above, should always complete");
}
}
@@ -133,16 +132,13 @@ public abstract class Request {
}
/**
- * Returns a Request that only runs tests whose {@link Description}
- * matches the given description.
+ * Returns a Request that only runs contains tests whose {@link Description}
+ * equals <code>desiredDescription</code>
*
- * <p>Returns an empty {@code Request} if {@code desiredDescription} is not a single test and filters all but the single
- * test if {@code desiredDescription} is a single test.</p>
- *
- * @param desiredDescription {@code Description} of those tests that should be run
+ * @param desiredDescription {@link Description} of those tests that should be run
* @return the filtered Request
*/
- public Request filterWith(Description desiredDescription) {
+ public Request filterWith(final Description desiredDescription) {
return filterWith(Filter.matchMethodDescription(desiredDescription));
}
@@ -153,15 +149,15 @@ public abstract class Request {
* For example, here is code to run a test suite in alphabetical order:
* <pre>
* private static Comparator&lt;Description&gt; forward() {
- * return new Comparator&lt;Description&gt;() {
- * public int compare(Description o1, Description o2) {
- * return o1.getDisplayName().compareTo(o2.getDisplayName());
- * }
- * };
+ * return new Comparator&lt;Description&gt;() {
+ * public int compare(Description o1, Description o2) {
+ * return o1.getDisplayName().compareTo(o2.getDisplayName());
+ * }
+ * };
* }
*
* public static main() {
- * new JUnitCore().run(Request.aClass(AllTests.class).sortWith(forward()));
+ * new JUnitCore().run(Request.aClass(AllTests.class).sortWith(forward()));
* }
* </pre>
*
@@ -171,32 +167,4 @@ public abstract class Request {
public Request sortWith(Comparator<Description> comparator) {
return new SortingRequest(this, comparator);
}
-
- /**
- * Returns a Request whose Tests can be run in a certain order, defined by
- * <code>ordering</code>
- * <p>
- * For example, here is code to run a test suite in reverse order:
- * <pre>
- * private static Ordering reverse() {
- * return new Ordering() {
- * public List&lt;Description&gt; orderItems(Collection&lt;Description&gt; descriptions) {
- * List&lt;Description&gt; ordered = new ArrayList&lt;&gt;(descriptions);
- * Collections.reverse(ordered);
- * return ordered;
- * }
- * }
- * }
- *
- * public static main() {
- * new JUnitCore().run(Request.aClass(AllTests.class).orderWith(reverse()));
- * }
- * </pre>
- *
- * @return a Request with ordered Tests
- * @since 4.13
- */
- public Request orderWith(Ordering ordering) {
- return new OrderingRequest(this, ordering);
- }
}
diff --git a/src/main/java/org/junit/runner/Result.java b/src/main/java/org/junit/runner/Result.java
index 4b5f4a4..73ad059 100644
--- a/src/main/java/org/junit/runner/Result.java
+++ b/src/main/java/org/junit/runner/Result.java
@@ -28,7 +28,6 @@ public class Result implements Serializable {
ObjectStreamClass.lookup(SerializedForm.class).getFields();
private final AtomicInteger count;
private final AtomicInteger ignoreCount;
- private final AtomicInteger assumptionFailureCount;
private final CopyOnWriteArrayList<Failure> failures;
private final AtomicLong runTime;
private final AtomicLong startTime;
@@ -39,7 +38,6 @@ public class Result implements Serializable {
public Result() {
count = new AtomicInteger();
ignoreCount = new AtomicInteger();
- assumptionFailureCount = new AtomicInteger();
failures = new CopyOnWriteArrayList<Failure>();
runTime = new AtomicLong();
startTime = new AtomicLong();
@@ -48,35 +46,34 @@ public class Result implements Serializable {
private Result(SerializedForm serializedForm) {
count = serializedForm.fCount;
ignoreCount = serializedForm.fIgnoreCount;
- assumptionFailureCount = serializedForm.assumptionFailureCount;
failures = new CopyOnWriteArrayList<Failure>(serializedForm.fFailures);
runTime = new AtomicLong(serializedForm.fRunTime);
startTime = new AtomicLong(serializedForm.fStartTime);
}
/**
- * Returns the number of tests run
+ * @return the number of tests run
*/
public int getRunCount() {
return count.get();
}
/**
- * Returns the number of tests that failed during the run
+ * @return the number of tests that failed during the run
*/
public int getFailureCount() {
return failures.size();
}
/**
- * Returns the number of milliseconds it took to run the entire suite to run
+ * @return the number of milliseconds it took to run the entire suite to run
*/
public long getRunTime() {
return runTime.get();
}
/**
- * Returns the {@link Failure}s describing tests that failed and the problems they encountered
+ * @return the {@link Failure}s describing tests that failed and the problems they encountered
*/
public List<Failure> getFailures() {
return failures;
@@ -90,20 +87,6 @@ public class Result implements Serializable {
}
/**
- * Returns the number of tests skipped because of an assumption failure
- *
- * @throws UnsupportedOperationException if the result was serialized in a version before JUnit 4.13
- * @since 4.13
- */
- public int getAssumptionFailureCount() {
- if (assumptionFailureCount == null) {
- throw new UnsupportedOperationException(
- "Result was serialized from a version of JUnit that doesn't support this method");
- }
- return assumptionFailureCount.get();
- }
-
- /**
* @return <code>true</code> if all tests succeeded
*/
public boolean wasSuccessful() {
@@ -154,7 +137,7 @@ public class Result implements Serializable {
@Override
public void testAssumptionFailure(Failure failure) {
- assumptionFailureCount.getAndIncrement();
+ // do nothing: same as passing (for 4.5; may change in 4.6)
}
}
@@ -173,7 +156,6 @@ public class Result implements Serializable {
private static final long serialVersionUID = 1L;
private final AtomicInteger fCount;
private final AtomicInteger fIgnoreCount;
- private final AtomicInteger assumptionFailureCount;
private final List<Failure> fFailures;
private final long fRunTime;
private final long fStartTime;
@@ -181,7 +163,6 @@ public class Result implements Serializable {
public SerializedForm(Result result) {
fCount = result.count;
fIgnoreCount = result.ignoreCount;
- assumptionFailureCount = result.assumptionFailureCount;
fFailures = Collections.synchronizedList(new ArrayList<Failure>(result.failures));
fRunTime = result.runTime.longValue();
fStartTime = result.startTime.longValue();
@@ -191,7 +172,6 @@ public class Result implements Serializable {
private SerializedForm(ObjectInputStream.GetField fields) throws IOException {
fCount = (AtomicInteger) fields.get("fCount", null);
fIgnoreCount = (AtomicInteger) fields.get("fIgnoreCount", null);
- assumptionFailureCount = (AtomicInteger) fields.get("assumptionFailureCount", null);
fFailures = (List<Failure>) fields.get("fFailures", null);
fRunTime = fields.get("fRunTime", 0L);
fStartTime = fields.get("fStartTime", 0L);
@@ -204,7 +184,6 @@ public class Result implements Serializable {
fields.put("fFailures", fFailures);
fields.put("fRunTime", fRunTime);
fields.put("fStartTime", fStartTime);
- fields.put("assumptionFailureCount", assumptionFailureCount);
s.writeFields();
}
diff --git a/src/main/java/org/junit/runner/manipulation/Alphanumeric.java b/src/main/java/org/junit/runner/manipulation/Alphanumeric.java
deleted file mode 100644
index 8388d21..0000000
--- a/src/main/java/org/junit/runner/manipulation/Alphanumeric.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.junit.runner.manipulation;
-
-import java.util.Comparator;
-
-import org.junit.runner.Description;
-
-/**
- * A sorter that orders tests alphanumerically by test name.
- *
- * @since 4.13
- */
-public final class Alphanumeric extends Sorter implements Ordering.Factory {
-
- public Alphanumeric() {
- super(COMPARATOR);
- }
-
- public Ordering create(Context context) {
- return this;
- }
-
- private static final Comparator<Description> COMPARATOR = new Comparator<Description>() {
- public int compare(Description o1, Description o2) {
- return o1.getDisplayName().compareTo(o2.getDisplayName());
- }
- };
-}
diff --git a/src/main/java/org/junit/runner/manipulation/InvalidOrderingException.java b/src/main/java/org/junit/runner/manipulation/InvalidOrderingException.java
deleted file mode 100644
index d9d60f7..0000000
--- a/src/main/java/org/junit/runner/manipulation/InvalidOrderingException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.junit.runner.manipulation;
-
-/**
- * Thrown when an ordering does something invalid (like remove or add children)
- *
- * @since 4.13
- */
-public class InvalidOrderingException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public InvalidOrderingException() {
- }
-
- public InvalidOrderingException(String message) {
- super(message);
- }
-
- public InvalidOrderingException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/src/main/java/org/junit/runner/manipulation/Orderable.java b/src/main/java/org/junit/runner/manipulation/Orderable.java
deleted file mode 100644
index 9a12a3b..0000000
--- a/src/main/java/org/junit/runner/manipulation/Orderable.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.junit.runner.manipulation;
-
-/**
- * Interface for runners that allow ordering of tests.
- *
- * <p>Beware of using this interface to cope with order dependencies between tests.
- * Tests that are isolated from each other are less expensive to maintain and
- * can be run individually.
- *
- * @since 4.13
- */
-public interface Orderable extends Sortable {
-
- /**
- * Orders the tests using <code>orderer</code>
- *
- * @throws InvalidOrderingException if orderer does something invalid (like remove or add
- * children)
- */
- void order(Orderer orderer) throws InvalidOrderingException;
-}
diff --git a/src/main/java/org/junit/runner/manipulation/Orderer.java b/src/main/java/org/junit/runner/manipulation/Orderer.java
deleted file mode 100644
index eb13054..0000000
--- a/src/main/java/org/junit/runner/manipulation/Orderer.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.junit.runner.manipulation;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.runner.Description;
-
-/**
- * Orders tests.
- *
- * @since 4.13
- */
-public final class Orderer {
- private final Ordering ordering;
-
- Orderer(Ordering delegate) {
- this.ordering = delegate;
- }
-
- /**
- * Orders the descriptions.
- *
- * @return descriptions in order
- */
- public List<Description> order(Collection<Description> descriptions)
- throws InvalidOrderingException {
- List<Description> inOrder = ordering.orderItems(
- Collections.unmodifiableCollection(descriptions));
- if (!ordering.validateOrderingIsCorrect()) {
- return inOrder;
- }
-
- Set<Description> uniqueDescriptions = new HashSet<Description>(descriptions);
- if (!uniqueDescriptions.containsAll(inOrder)) {
- throw new InvalidOrderingException("Ordering added items");
- }
- Set<Description> resultAsSet = new HashSet<Description>(inOrder);
- if (resultAsSet.size() != inOrder.size()) {
- throw new InvalidOrderingException("Ordering duplicated items");
- } else if (!resultAsSet.containsAll(uniqueDescriptions)) {
- throw new InvalidOrderingException("Ordering removed items");
- }
-
- return inOrder;
- }
-
- /**
- * Order the tests in <code>target</code>.
- *
- * @throws InvalidOrderingException if ordering does something invalid (like remove or add
- * children)
- */
- public void apply(Object target) throws InvalidOrderingException {
- if (target instanceof Orderable) {
- Orderable orderable = (Orderable) target;
- orderable.order(this);
- }
- }
-}
diff --git a/src/main/java/org/junit/runner/manipulation/Ordering.java b/src/main/java/org/junit/runner/manipulation/Ordering.java
deleted file mode 100644
index 0d0ce93..0000000
--- a/src/main/java/org/junit/runner/manipulation/Ordering.java
+++ /dev/null
@@ -1,172 +0,0 @@
-package org.junit.runner.manipulation;
-
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import org.junit.runner.Description;
-import org.junit.runner.OrderWith;
-
-/**
- * Reorders tests. An {@code Ordering} can reverse the order of tests, sort the
- * order or even shuffle the order.
- *
- * <p>In general you will not need to use a <code>Ordering</code> directly.
- * Instead, use {@link org.junit.runner.Request#orderWith(Ordering)}.
- *
- * @since 4.13
- */
-public abstract class Ordering {
- private static final String CONSTRUCTOR_ERROR_FORMAT
- = "Ordering class %s should have a public constructor with signature "
- + "%s(Ordering.Context context)";
-
- /**
- * Creates an {@link Ordering} that shuffles the items using the given
- * {@link Random} instance.
- */
- public static Ordering shuffledBy(final Random random) {
- return new Ordering() {
- @Override
- boolean validateOrderingIsCorrect() {
- return false;
- }
-
- @Override
- protected List<Description> orderItems(Collection<Description> descriptions) {
- List<Description> shuffled = new ArrayList<Description>(descriptions);
- Collections.shuffle(shuffled, random);
- return shuffled;
- }
- };
- }
-
- /**
- * Creates an {@link Ordering} from the given factory class. The class must have a public no-arg
- * constructor.
- *
- * @param factoryClass class to use to create the ordering
- * @param annotatedTestClass test class that is annotated with {@link OrderWith}.
- * @throws InvalidOrderingException if the instance could not be created
- */
- public static Ordering definedBy(
- Class<? extends Ordering.Factory> factoryClass, Description annotatedTestClass)
- throws InvalidOrderingException {
- if (factoryClass == null) {
- throw new NullPointerException("factoryClass cannot be null");
- }
- if (annotatedTestClass == null) {
- throw new NullPointerException("annotatedTestClass cannot be null");
- }
-
- Ordering.Factory factory;
- try {
- Constructor<? extends Ordering.Factory> constructor = factoryClass.getConstructor();
- factory = constructor.newInstance();
- } catch (NoSuchMethodException e) {
- throw new InvalidOrderingException(String.format(
- CONSTRUCTOR_ERROR_FORMAT,
- getClassName(factoryClass),
- factoryClass.getSimpleName()));
- } catch (Exception e) {
- throw new InvalidOrderingException(
- "Could not create ordering for " + annotatedTestClass, e);
- }
- return definedBy(factory, annotatedTestClass);
- }
-
- /**
- * Creates an {@link Ordering} from the given factory.
- *
- * @param factory factory to use to create the ordering
- * @param annotatedTestClass test class that is annotated with {@link OrderWith}.
- * @throws InvalidOrderingException if the instance could not be created
- */
- public static Ordering definedBy(
- Ordering.Factory factory, Description annotatedTestClass)
- throws InvalidOrderingException {
- if (factory == null) {
- throw new NullPointerException("factory cannot be null");
- }
- if (annotatedTestClass == null) {
- throw new NullPointerException("annotatedTestClass cannot be null");
- }
-
- return factory.create(new Ordering.Context(annotatedTestClass));
- }
-
- private static String getClassName(Class<?> clazz) {
- String name = clazz.getCanonicalName();
- if (name == null) {
- return clazz.getName();
- }
- return name;
- }
-
- /**
- * Order the tests in <code>target</code> using this ordering.
- *
- * @throws InvalidOrderingException if ordering does something invalid (like remove or add
- * children)
- */
- public void apply(Object target) throws InvalidOrderingException {
- /*
- * Note that some subclasses of Ordering override apply(). The Sorter
- * subclass of Ordering overrides apply() to apply the sort (this is
- * done because sorting is more efficient than ordering).
- */
- if (target instanceof Orderable) {
- Orderable orderable = (Orderable) target;
- orderable.order(new Orderer(this));
- }
- }
-
- /**
- * Returns {@code true} if this ordering could produce invalid results (i.e.
- * if it could add or remove values).
- */
- boolean validateOrderingIsCorrect() {
- return true;
- }
-
- /**
- * Implemented by sub-classes to order the descriptions.
- *
- * @return descriptions in order
- */
- protected abstract List<Description> orderItems(Collection<Description> descriptions);
-
- /** Context about the ordering being applied. */
- public static class Context {
- private final Description description;
-
- /**
- * Gets the description for the top-level target being ordered.
- */
- public Description getTarget() {
- return description;
- }
-
- private Context(Description description) {
- this.description = description;
- }
- }
-
- /**
- * Factory for creating {@link Ordering} instances.
- *
- * <p>For a factory to be used with {@code @OrderWith} it needs to have a public no-arg
- * constructor.
- */
- public interface Factory {
- /**
- * Creates an Ordering instance using the given context. Implementations
- * of this method that do not need to use the context can return the
- * same instance every time.
- */
- Ordering create(Context context);
- }
-}
diff --git a/src/main/java/org/junit/runner/manipulation/Sortable.java b/src/main/java/org/junit/runner/manipulation/Sortable.java
index 0c59f33..9ac864c 100644
--- a/src/main/java/org/junit/runner/manipulation/Sortable.java
+++ b/src/main/java/org/junit/runner/manipulation/Sortable.java
@@ -15,6 +15,6 @@ public interface Sortable {
*
* @param sorter the {@link Sorter} to use for sorting the tests
*/
- void sort(Sorter sorter);
+ public void sort(Sorter sorter);
}
diff --git a/src/main/java/org/junit/runner/manipulation/Sorter.java b/src/main/java/org/junit/runner/manipulation/Sorter.java
index 4b5274c..20192d0 100644
--- a/src/main/java/org/junit/runner/manipulation/Sorter.java
+++ b/src/main/java/org/junit/runner/manipulation/Sorter.java
@@ -1,21 +1,16 @@
package org.junit.runner.manipulation;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Comparator;
-import java.util.List;
import org.junit.runner.Description;
/**
* A <code>Sorter</code> orders tests. In general you will not need
- * to use a <code>Sorter</code> directly. Instead, use
- * {@link org.junit.runner.Request#sortWith(Comparator)}.
+ * to use a <code>Sorter</code> directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}.
*
* @since 4.0
*/
-public class Sorter extends Ordering implements Comparator<Description> {
+public class Sorter implements Comparator<Description> {
/**
* NULL is a <code>Sorter</code> that leaves elements in an undefined order
*/
@@ -32,26 +27,17 @@ public class Sorter extends Ordering implements Comparator<Description> {
* to sort tests
*
* @param comparator the {@link Comparator} to use when sorting tests
- * @since 4.0
*/
public Sorter(Comparator<Description> comparator) {
this.comparator = comparator;
}
/**
- * Sorts the tests in <code>target</code> using <code>comparator</code>.
- *
- * @since 4.0
+ * Sorts the test in <code>runner</code> using <code>comparator</code>
*/
- @Override
- public void apply(Object target) {
- /*
- * Note that all runners that are Orderable are also Sortable (because
- * Orderable extends Sortable). Sorting is more efficient than ordering,
- * so we override the parent behavior so we sort instead.
- */
- if (target instanceof Sortable) {
- Sortable sortable = (Sortable) target;
+ public void apply(Object object) {
+ if (object instanceof Sortable) {
+ Sortable sortable = (Sortable) object;
sortable.sort(this);
}
}
@@ -59,32 +45,4 @@ public class Sorter extends Ordering implements Comparator<Description> {
public int compare(Description o1, Description o2) {
return comparator.compare(o1, o2);
}
-
- /**
- * {@inheritDoc}
- *
- * @since 4.13
- */
- @Override
- protected final List<Description> orderItems(Collection<Description> descriptions) {
- /*
- * In practice, we will never get here--Sorters do their work in the
- * compare() method--but the Liskov substitution principle demands that
- * we obey the general contract of Orderable. Luckily, it's trivial to
- * implement.
- */
- List<Description> sorted = new ArrayList<Description>(descriptions);
- Collections.sort(sorted, this); // Note: it would be incorrect to pass in "comparator"
- return sorted;
- }
-
- /**
- * {@inheritDoc}
- *
- * @since 4.13
- */
- @Override
- boolean validateOrderingIsCorrect() {
- return false;
- }
}
diff --git a/src/main/java/org/junit/runner/notification/Failure.java b/src/main/java/org/junit/runner/notification/Failure.java
index 4551302..c03b4c1 100644
--- a/src/main/java/org/junit/runner/notification/Failure.java
+++ b/src/main/java/org/junit/runner/notification/Failure.java
@@ -1,8 +1,9 @@
package org.junit.runner.notification;
+import java.io.PrintWriter;
import java.io.Serializable;
+import java.io.StringWriter;
-import org.junit.internal.Throwables;
import org.junit.runner.Description;
/**
@@ -20,7 +21,7 @@ public class Failure implements Serializable {
/*
* We have to use the f prefix until the next major release to ensure
* serialization compatibility.
- * See https://github.com/junit-team/junit4/issues/976
+ * See https://github.com/junit-team/junit/issues/976
*/
private final Description fDescription;
private final Throwable fThrownException;
@@ -64,19 +65,15 @@ public class Failure implements Serializable {
}
/**
- * Gets the printed form of the exception and its stack trace.
+ * Convenience method
+ *
+ * @return the printed form of the exception
*/
public String getTrace() {
- return Throwables.getStacktrace(getException());
- }
-
- /**
- * Gets a the printed form of the exception, with a trimmed version of the stack trace.
- * This method will attempt to filter out frames of the stack trace that are below
- * the test method call.
- */
- public String getTrimmedTrace() {
- return Throwables.getTrimmedStackTrace(getException());
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter writer = new PrintWriter(stringWriter);
+ getException().printStackTrace(writer);
+ return stringWriter.toString();
}
/**
diff --git a/src/main/java/org/junit/runner/notification/RunListener.java b/src/main/java/org/junit/runner/notification/RunListener.java
index d7cac00..db9d8c1 100644
--- a/src/main/java/org/junit/runner/notification/RunListener.java
+++ b/src/main/java/org/junit/runner/notification/RunListener.java
@@ -70,34 +70,6 @@ public class RunListener {
}
/**
- * Called when a test suite is about to be started. If this method is
- * called for a given {@link Description}, then {@link #testSuiteFinished(Description)}
- * will also be called for the same {@code Description}.
- *
- * <p>Note that not all runners will call this method, so runners should
- * be prepared to handle {@link #testStarted(Description)} calls for tests
- * where there was no corresponding {@code testSuiteStarted()} call for
- * the parent {@code Description}.
- *
- * @param description the description of the test suite that is about to be run
- * (generally a class name)
- * @since 4.13
- */
- public void testSuiteStarted(Description description) throws Exception {
- }
-
- /**
- * Called when a test suite has finished, whether the test suite succeeds or fails.
- * This method will not be called for a given {@link Description} unless
- * {@link #testSuiteStarted(Description)} was called for the same @code Description}.
- *
- * @param description the description of the test suite that just ran
- * @since 4.13
- */
- public void testSuiteFinished(Description description) throws Exception {
- }
-
- /**
* Called when an atomic test is about to be started.
*
* @param description the description of the test that is about to be run
diff --git a/src/main/java/org/junit/runner/notification/RunNotifier.java b/src/main/java/org/junit/runner/notification/RunNotifier.java
index 752fa3b..6875f76 100644
--- a/src/main/java/org/junit/runner/notification/RunNotifier.java
+++ b/src/main/java/org/junit/runner/notification/RunNotifier.java
@@ -65,8 +65,8 @@ public class RunNotifier {
void run() {
int capacity = currentListeners.size();
- List<RunListener> safeListeners = new ArrayList<RunListener>(capacity);
- List<Failure> failures = new ArrayList<Failure>(capacity);
+ ArrayList<RunListener> safeListeners = new ArrayList<RunListener>(capacity);
+ ArrayList<Failure> failures = new ArrayList<Failure>(capacity);
for (RunListener listener : currentListeners) {
try {
notifyListener(listener);
@@ -78,7 +78,7 @@ public class RunNotifier {
fireTestFailures(safeListeners, failures);
}
- protected abstract void notifyListener(RunListener each) throws Exception;
+ abstract protected void notifyListener(RunListener each) throws Exception;
}
/**
@@ -106,41 +106,6 @@ public class RunNotifier {
}
/**
- * Invoke to tell listeners that a test suite is about to start. Runners are strongly
- * encouraged--but not required--to call this method. If this method is called for
- * a given {@link Description} then {@link #fireTestSuiteFinished(Description)} MUST
- * be called for the same {@code Description}.
- *
- * @param description the description of the suite test (generally a class name)
- * @since 4.13
- */
- public void fireTestSuiteStarted(final Description description) {
- new SafeNotifier() {
- @Override
- protected void notifyListener(RunListener each) throws Exception {
- each.testSuiteStarted(description);
- }
- }.run();
- }
-
- /**
- * Invoke to tell listeners that a test suite is about to finish. Always invoke
- * this method if you invoke {@link #fireTestSuiteStarted(Description)}
- * as listeners are likely to expect them to come in pairs.
- *
- * @param description the description of the suite test (generally a class name)
- * @since 4.13
- */
- public void fireTestSuiteFinished(final Description description) {
- new SafeNotifier() {
- @Override
- protected void notifyListener(RunListener each) throws Exception {
- each.testSuiteFinished(description);
- }
- }.run();
- }
-
- /**
* Invoke to tell listeners that an atomic test is about to start.
*
* @param description the description of the atomic test (generally a class and method name)
diff --git a/src/main/java/org/junit/runner/notification/SynchronizedRunListener.java b/src/main/java/org/junit/runner/notification/SynchronizedRunListener.java
index 400fed8..c53c1ee 100644
--- a/src/main/java/org/junit/runner/notification/SynchronizedRunListener.java
+++ b/src/main/java/org/junit/runner/notification/SynchronizedRunListener.java
@@ -10,7 +10,7 @@ import org.junit.runner.Result;
* <p>This class synchronizes all listener calls on a RunNotifier instance. This is done because
* prior to JUnit 4.12, all listeners were called in a synchronized block in RunNotifier,
* so no two listeners were ever called concurrently. If we instead made the methods here
- * synchronized, clients that added multiple listeners that called common code might see
+ * sychronized, clients that added multiple listeners that called common code might see
* issues due to the reduced synchronization.
*
* @author Tibor Digana (tibor17)
@@ -43,37 +43,6 @@ final class SynchronizedRunListener extends RunListener {
}
}
- /**
- * {@inheritDoc}
- * <p/>
- * Synchronized decorator for {@link RunListener#testSuiteStarted(Description)}.
- * @param description the description of the test suite that is about to be run
- * (generally a class name).
- * @throws Exception if any occurs.
- * @since 4.13
- */
- @Override
- public void testSuiteStarted(Description description) throws Exception {
- synchronized (monitor) {
- listener.testSuiteStarted(description);
- }
- }
-
- /**
- * {@inheritDoc}
- * <p/>
- * Synchronized decorator for {@link RunListener#testSuiteFinished(Description)}.
- * @param description the description of the test suite that just ran.
- * @throws Exception
- * @since 4.13
- */
- @Override
- public void testSuiteFinished(Description description) throws Exception {
- synchronized (monitor) {
- listener.testSuiteFinished(description);
- }
- }
-
@Override
public void testStarted(Description description) throws Exception {
synchronized (monitor) {