org.junit.internal.runners.model.MultipleFailureException Java Examples

The following examples show how to use org.junit.internal.runners.model.MultipleFailureException. 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: BaseJdbcTest.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
@Override
public void evaluate() throws Throwable {
	try {
		statement.evaluate();
	} catch (Throwable t) {
		if (t instanceof MultipleFailureException) {
			t = ((MultipleFailureException) t).getFailures().get(0);
		}
		if (t instanceof InvocationTargetException) {
			t = ((InvocationTargetException) t).getTargetException();
		}
		String assertMsg;
		if (t instanceof AssertionError) {
			throw t;
		} else if ((!isConnectionExpected) && t.getMessage() != null
				&& t.getMessage().contains(DATASOURCE_ERROR)) {
			// if we throw because of missing data-source and the db server isn't available, ignore it
			return;
		} else if (tClass == null) {
			assertMsg = "Test threw unexpected exception: " + t;
		} else if (tClass == t.getClass()) {
			// we matched our expected exception
			return;
		} else {
			assertMsg = "Expected test to throw " + tClass + " but it threw: " + t;
		}
		Error error = new AssertionError(assertMsg);
		error.initCause(t);
		throw error;
	}
	// can't be in the throw block
	if (tClass != null) {
		throw new AssertionError("Expected test to throw " + tClass);
	}
}
 
Example #2
Source File: NoAWSCredsRule.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private boolean isMissingCredsException( final Throwable t ) {

        if ( t instanceof AmazonClientException ) {

            final AmazonClientException ace = ( AmazonClientException ) t;

            if ( ace.getMessage().contains( "could not get aws access key" ) || ace.getMessage().contains(
                "could not get aws secret key from system properties" ) ) {
                //swallow
                return true;
            }
        }

        if( t instanceof AwsPropertiesNotFoundException ){
            return true;
        }

        /**
         * Handle the multiple failure junit trace
         */
        if( t instanceof MultipleFailureException ){
            for(final Throwable failure : ((MultipleFailureException)t).getFailures()){
                final boolean isMissingCreds = isMissingCredsException( failure );

                if(isMissingCreds){
                    return true;
                }
            }
        }
        final Throwable cause = t.getCause();

        if ( cause == null ) {
            return false;
        }


        return isMissingCredsException( cause );
    }
 
Example #3
Source File: NoGoogleCredsRule.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private boolean isMissingCredsException( final Throwable t ) {

        // either no filename was provided or the filename provided doesn't actually exist on the file system
        if ( t instanceof FileNotFoundException || t instanceof NullPointerException ) {
                return true;
            }


        /**
         * Handle the multiple failure junit trace
         */
        if( t instanceof MultipleFailureException ){
            for(final Throwable failure : ((MultipleFailureException)t).getFailures()){
                final boolean isMissingCreds = isMissingCredsException( failure );

                if(isMissingCreds){
                    return true;
                }
            }
        }
        final Throwable cause = t.getCause();

        if ( cause == null ) {
            return false;
        }


        return isMissingCredsException( cause );
    }
 
Example #4
Source File: NoAWSCredsRule.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private boolean isMissingCredsException( final Throwable t ) {

        if ( t instanceof AmazonClientException ) {

            final AmazonClientException ace = ( AmazonClientException ) t;

            if ( ace.getMessage().contains( "could not get aws access key" ) || ace.getMessage().contains(
                "could not get aws secret key from system properties" ) ) {
                //swallow
                return true;
            }
        }

        /**
         * Handle the multiple failure junit trace
         */
        if( t instanceof MultipleFailureException ){
            for(final Throwable failure : ((MultipleFailureException)t).getFailures()){
                final boolean isMissingCreds = isMissingCredsException( failure );

                if(isMissingCreds){
                    return true;
                }
            }
        }
        final Throwable cause = t.getCause();

        if ( cause == null ) {
            return false;
        }


        return isMissingCredsException( cause );
    }
 
Example #5
Source File: Retry.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
private Statement statement(final Statement base, final Description description) {
  return new Statement() {

    @Override
    public void evaluate() throws Throwable {
      Throwable caughtThrowable = null;
      for (; currentRetry <= retryCount; currentRetry++) {
        try {
          testReport.appendHeader(description.getClassName() + "." + description.getMethodName()
              + " - Execution " + (exceptions.size() + 1) + "/" + getRetryCount());
          base.evaluate();
          testReport.flushExtraInfoHtml();
          testReport.appendSuccess("Test ok");
          testReport.flushExtraInfoHtml();
          testReport.appendLine();
          return;
        } catch (Throwable t) {

          if (t instanceof MultipleFailureException) {
            MultipleFailureException m = (MultipleFailureException) t;
            for (Throwable throwable : m.getFailures()) {
              log.warn("Multiple exception element", throwable);
            }
          }

          exceptions.add(t);
          if (testReport != null) {
            testReport.appendWarning("Test failed in retry " + exceptions.size());
            testReport.appendException(t, testScenario);
            testReport.flushExtraInfoHtml();
            testReport.flushExtraErrorHtml();
          }

          caughtThrowable = t;
          log.error(SEPARATOR);
          log.error("{}: run {} failed", description.getDisplayName(), currentRetry, t);
          log.error(SEPARATOR);
        }
      }

      String errorMessage = "TEST ERROR: " + description.getMethodName() + " (giving up after "
          + retryCount + " retries)";
      if (exceptions.size() > 0 && testReport != null) {
        testReport.appendError(errorMessage);
        testReport.appendLine();
      }

      throw caughtThrowable;
    }
  };
}