Skip to content

Commit

Permalink
Create AssumptionViolatedException in org.junit and deprecate the one…
Browse files Browse the repository at this point in the history
… in org.junit.internal

Allows developers to write code that handles assumption violations without depending on internal classes
  • Loading branch information
dhasday committed Feb 12, 2014
1 parent 6dd24ff commit 92c8319
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/junit/Assume.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.hamcrest.CoreMatchers.nullValue;

import org.hamcrest.Matcher;
import org.junit.internal.AssumptionViolatedException;

/**
* A set of methods useful for stating assumptions about the conditions in which a test is meaningful.
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/junit/AssumptionViolatedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.junit;

import org.hamcrest.Matcher;

/**
* An exception class used to implement <i>assumptions</i> (state in which a given test
* is meaningful and should or should not be executed). A test for which an assumption
* fails should not generate a test case failure.
*
* @see org.junit.Assume
*/
public class AssumptionViolatedException extends org.junit.internal.AssumptionViolatedException {
private static final long serialVersionUID = 1L;

public AssumptionViolatedException(String assumption, boolean valueMatcher, Object value, Matcher<?> matcher) {
super(assumption, valueMatcher, value, matcher);
}

/**
* An assumption exception with the given <i>value</i> (String or
* Throwable) and an additional failing {@link Matcher}.
*/
public AssumptionViolatedException(Object value, Matcher<?> matcher) {
super(value, matcher);
}

/**
* An assumption exception with the given <i>value</i> (String or
* Throwable) and an additional failing {@link Matcher}.
*/
public AssumptionViolatedException(String assumption, Object value, Matcher<?> matcher) {
super(assumption, value, matcher);
}

/**
* An assumption exception with the given message only.
*/
public AssumptionViolatedException(String assumption) {
super(assumption);
}

/**
* An assumption exception with the given message and a cause.
*/
public AssumptionViolatedException(String assumption, Throwable t) {
super(assumption, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import org.junit.Assert;
import org.junit.Assume;
import org.junit.AssumptionViolatedException;
import org.junit.experimental.theories.internal.Assignments;
import org.junit.experimental.theories.internal.ParameterizedAssertionError;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
* is meaningful and should or should not be executed). A test for which an assumption
* fails should not generate a test case failure.
*
* @see Assume
* @see org.junit.Assume
*
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
*/
@Deprecated
public class AssumptionViolatedException extends RuntimeException implements SelfDescribing {
private static final long serialVersionUID = 2L;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/internal/runners/ClassRoadie.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void runBefores() throws FailedBefore {
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
} catch (org.junit.internal.AssumptionViolatedException e) {
} catch (org.junit.AssumptionViolatedException e) {
throw new FailedBefore();
} catch (Throwable e) {
addFailure(e);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/internal/runners/MethodRoadie.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.junit.internal.runners.model;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.junit.internal.runners.statements;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runners.model.Statement;

public class ExpectException extends Statement {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/rules/ExpectedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runners.model.Statement;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/rules/Stopwatch.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.junit.rules;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;

import java.util.concurrent.TimeUnit;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/rules/TestWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/rules/TestWatchman.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.junit.rules;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.Result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.Result;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junit/runners/ParentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import java.util.List;

import org.junit.AfterClass;
import org.junit.AssumptionViolatedException;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.internal.AssumptionViolatedException;
import org.junit.internal.runners.model.EachTestNotifier;
import org.junit.internal.runners.statements.RunAfters;
import org.junit.internal.runners.statements.RunBefores;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import java.util.List;

import org.junit.Assume;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AssumptionViolatedException;
import org.junit.Test;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.RunWith;

@RunWith(Theories.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.junit.tests.experimental.rules;

import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.Stopwatch;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

import org.junit.After;
import org.junit.Assume;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.TestName;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import static org.junit.experimental.results.ResultMatchers.hasFailureContaining;
import static org.junit.runner.JUnitCore.runClasses;

import org.junit.AssumptionViolatedException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.results.PrintableResult;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.hamcrest.BaseDescription;
import org.hamcrest.Description;
import org.junit.internal.AssumptionViolatedException;
import org.junit.AssumptionViolatedException;

public class Guesser<T> extends ReguessableValue {
static class GuessMap extends HashMap<MethodCall, Object> implements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Collections;
import java.util.List;

import org.junit.AssumptionViolatedException;
import org.junit.experimental.theories.PotentialAssignment;
import org.junit.internal.AssumptionViolatedException;

public class GuesserQueue extends ArrayList<ReguessableValue> {
static class ReguessableDecorator extends ReguessableValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.List;

import org.junit.AssumptionViolatedException;
import org.junit.experimental.theories.PotentialAssignment;
import org.junit.internal.AssumptionViolatedException;

public abstract class ReguessableValue extends PotentialAssignment {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AssumptionViolatedException;
import org.junit.experimental.theories.ParameterSignature;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.internal.Assignments;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
Expand Down

0 comments on commit 92c8319

Please sign in to comment.