use of org.junit.internal.AssumptionViolatedException in project junit4 by junit-team.
the class ParentRunner method run.
@Override
public void run(final RunNotifier notifier) {
EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
testNotifier.fireTestSuiteStarted();
try {
Statement statement = classBlock(notifier);
statement.evaluate();
} catch (AssumptionViolatedException e) {
testNotifier.addFailedAssumption(e);
} catch (StoppedByUserException e) {
throw e;
} catch (Throwable e) {
testNotifier.addFailure(e);
} finally {
testNotifier.fireTestSuiteFinished();
}
}
use of org.junit.internal.AssumptionViolatedException in project junit4 by junit-team.
the class ParentRunner method runLeaf.
/**
* Runs a {@link Statement} that represents a leaf (aka atomic) test.
*/
protected final void runLeaf(Statement statement, Description description, RunNotifier notifier) {
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
statement.evaluate();
} catch (AssumptionViolatedException e) {
eachNotifier.addFailedAssumption(e);
} catch (Throwable e) {
eachNotifier.addFailure(e);
} finally {
eachNotifier.fireTestFinished();
}
}
use of org.junit.internal.AssumptionViolatedException in project junit4 by junit-team.
the class ExpectException method evaluate.
@Override
public void evaluate() throws Exception {
boolean complete = false;
try {
next.evaluate();
complete = true;
} catch (AssumptionViolatedException e) {
if (!expected.isAssignableFrom(e.getClass())) {
throw e;
}
} catch (Throwable e) {
if (!expected.isAssignableFrom(e.getClass())) {
String message = "Unexpected exception, expected<" + expected.getName() + "> but was<" + e.getClass().getName() + ">";
throw new Exception(message, e);
}
}
if (complete) {
throw new AssertionError("Expected exception: " + expected.getName());
}
}
use of org.junit.internal.AssumptionViolatedException in project hadoop by apache.
the class ContractTestUtils method downgrade.
/**
* downgrade a failure to a message and a warning, then an
* exception for the Junit test runner to mark as failed.
* @param message text message
* @param failure what failed
* @throws AssumptionViolatedException always
*/
public static void downgrade(String message, Throwable failure) {
LOG.warn("Downgrading test " + message, failure);
AssumptionViolatedException ave = new AssumptionViolatedException(failure, null);
throw ave;
}
use of org.junit.internal.AssumptionViolatedException in project hadoop by apache.
the class AbstractContractCreateTest method testOverwriteNonEmptyDirectory.
@Test
public void testOverwriteNonEmptyDirectory() throws Throwable {
describe("verify trying to create a file over a non-empty dir fails");
Path path = path("testOverwriteNonEmptyDirectory");
mkdirs(path);
try {
assertIsDirectory(path);
} catch (AssertionError failure) {
if (isSupported(CREATE_OVERWRITES_DIRECTORY)) {
// file/directory hack surfaces here
throw new AssumptionViolatedException(failure.toString(), failure);
}
// else: rethrow
throw failure;
}
Path child = new Path(path, "child");
writeTextFile(getFileSystem(), child, "child file", true);
byte[] data = dataset(256, 'a', 'z');
try {
writeDataset(getFileSystem(), path, data, data.length, 1024, true);
FileStatus status = getFileSystem().getFileStatus(path);
boolean isDir = status.isDirectory();
if (!isDir && isSupported(CREATE_OVERWRITES_DIRECTORY)) {
// For some file systems, downgrade to a skip so that the failure is
// visible in test results.
skip("This Filesystem allows a file to overwrite a directory");
}
fail("write of file over dir succeeded");
} catch (FileAlreadyExistsException expected) {
//expected
handleExpectedException(expected);
} catch (FileNotFoundException e) {
handleRelaxedException("overwriting a dir with a file ", "FileAlreadyExistsException", e);
} catch (IOException e) {
handleRelaxedException("overwriting a dir with a file ", "FileAlreadyExistsException", e);
}
assertIsDirectory(path);
assertIsFile(child);
}
Aggregations