com.intellij.testFramework.exceptionCases.AbstractExceptionCase Java Examples

The following examples show how to use com.intellij.testFramework.exceptionCases.AbstractExceptionCase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsvTableEditorSwingTestBase.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public <T extends Throwable> void assertException(@NotNull final Class<? extends Throwable> exceptionClass, @Nullable String expectedErrorMsg, @NotNull final ThrowableRunnable<T> runnable) throws Throwable {
    assertException(new AbstractExceptionCase() {
        public Class<? extends Throwable> getExpectedExceptionClass() {
            return exceptionClass;
        }

        public void tryClosure() throws Throwable {
            runnable.run();
        }
    }, expectedErrorMsg);
}
 
Example #2
Source File: UsefulTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void assertExceptionOccurred(boolean shouldOccur,
                                            AbstractExceptionCase exceptionCase,
                                            String expectedErrorMsg) throws Throwable {
  boolean wasThrown = false;
  try {
    exceptionCase.tryClosure();
  }
  catch (Throwable e) {
    if (shouldOccur) {
      wasThrown = true;
      final String errorMessage = exceptionCase.getAssertionErrorMessage();
      assertEquals(errorMessage, exceptionCase.getExpectedExceptionClass(), e.getClass());
      if (expectedErrorMsg != null) {
        assertEquals("Compare error messages", expectedErrorMsg, e.getMessage());
      }
    }
    else if (exceptionCase.getExpectedExceptionClass().equals(e.getClass())) {
      wasThrown = true;

      System.out.println("");
      e.printStackTrace(System.out);

      fail("Exception isn't expected here. Exception message: " + e.getMessage());
    }
    else {
      throw e;
    }
  }
  finally {
    if (shouldOccur && !wasThrown) {
      fail(exceptionCase.getAssertionErrorMessage());
    }
  }
}
 
Example #3
Source File: UsefulTestCase.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Checks that code block throw corresponding exception.
 *
 * @param exceptionCase Block annotated with some exception type
 * @throws Throwable
 */
protected void assertException(final AbstractExceptionCase exceptionCase) throws Throwable {
  assertException(exceptionCase, null);
}
 
Example #4
Source File: UsefulTestCase.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Checks that code block throw corresponding exception with expected error msg.
 * If expected error message is null it will not be checked.
 *
 * @param exceptionCase    Block annotated with some exception type
 * @param expectedErrorMsg expected error messge
 * @throws Throwable
 */
protected void assertException(final AbstractExceptionCase exceptionCase,
                               @javax.annotation.Nullable final String expectedErrorMsg) throws Throwable {
  assertExceptionOccurred(true, exceptionCase, expectedErrorMsg);
}
 
Example #5
Source File: UsefulTestCase.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Checks that code block doesn't throw corresponding exception.
 *
 * @param exceptionCase Block annotated with some exception type
 * @throws Throwable
 */
protected void assertNoException(final AbstractExceptionCase exceptionCase) throws Throwable {
  assertExceptionOccurred(false, exceptionCase, null);
}