Search in sources :

Example 16 with AssumptionViolatedException

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();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) StoppedByUserException(org.junit.runner.notification.StoppedByUserException)

Example 17 with AssumptionViolatedException

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();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier)

Example 18 with AssumptionViolatedException

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());
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException)

Example 19 with AssumptionViolatedException

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;
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException)

Example 20 with AssumptionViolatedException

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);
}
Also used : Path(org.apache.hadoop.fs.Path) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) FileStatus(org.apache.hadoop.fs.FileStatus) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)26 Test (org.junit.Test)7 Statement (org.junit.runners.model.Statement)6 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)4 Failure (org.junit.runner.notification.Failure)4 URI (java.net.URI)3 Description (org.junit.runner.Description)3 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 Path (org.apache.hadoop.fs.Path)2 SuppressForbidden (com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1