org.junit.internal.AssumptionViolatedException Java Examples

The following examples show how to use org.junit.internal.AssumptionViolatedException. 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: LuceneTestCase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for {@link #expectThrows} and {@link #expectThrowsAnyOf} that takes care of propagating
 * any {@link AssertionError} or {@link AssumptionViolatedException} instances thrown if and only if they 
 * are super classes of the <code>expectedTypes</code>.  Otherwise simply returns any {@link Throwable} 
 * thrown, regardless of type, or null if the <code>runnable</code> completed w/o error.
 */
private static Throwable _expectThrows(List<? extends Class<?>> expectedTypes, ThrowingRunnable runnable) {
                                       
  try {
    runnable.run();
  } catch (AssertionError | AssumptionViolatedException ae) {
    for (Class<?> expectedType : expectedTypes) {
      if (expectedType.isInstance(ae)) { // user is expecting this type explicitly
        return ae;
      }
    }
    throw ae;
  } catch (Throwable e) {
    return e;
  }
  return null;
}
 
Example #2
Source File: FlowableContentRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #3
Source File: UnsafeDeopt.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testByteBuffer() {
    int m = 42;
    try {
        ResolvedJavaMethod method = getResolvedJavaMethod("readWriteReadByteBuffer");
        Object receiver = method.isStatic() ? null : this;
        Result expect = executeExpected(method, receiver, ByteBuffer.allocateDirect(32), m);
        if (getCodeCache() == null) {
            return;
        }
        ByteBuffer warmupBuffer = ByteBuffer.allocateDirect(32);
        for (int i = 0; i < 10000; ++i) {
            readWriteReadByteBuffer(warmupBuffer, (i % 50) + 1);
            warmupBuffer.putInt(0, 0);
        }
        testAgainstExpected(method, expect, receiver, ByteBuffer.allocateDirect(32), m);
    } catch (AssumptionViolatedException e) {
        // Suppress so that subsequent calls to this method within the
        // same Junit @Test annotated method can proceed.
    }
}
 
Example #4
Source File: UnsafeDeopt.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testUnsafe() {
    int m = 42;
    long addr1 = createBuffer();
    long addr2 = createBuffer();
    try {
        ResolvedJavaMethod method = getResolvedJavaMethod("readWriteReadUnsafe");
        Object receiver = method.isStatic() ? null : this;
        Result expect = executeExpected(method, receiver, addr1, m);
        if (getCodeCache() == null) {
            return;
        }
        testAgainstExpected(method, expect, receiver, addr2, m);
    } catch (AssumptionViolatedException e) {
        // Suppress so that subsequent calls to this method within the
        // same Junit @Test annotated method can proceed.
    } finally {
        disposeBuffer(addr1);
        disposeBuffer(addr2);
    }
}
 
Example #5
Source File: ParameterizedTestWatcher.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description, final Object[] params) {
	return new Statement() {
		public void evaluate() throws Throwable {
			ArrayList<Throwable> errors = new ArrayList<Throwable>();
			ParameterizedTestWatcher.this.startingQuietly(description, errors, params);

			try {
				base.evaluate();
				ParameterizedTestWatcher.this.succeededQuietly(description, errors, params);
			} catch (AssumptionViolatedException var7) {
				errors.add(var7);
				ParameterizedTestWatcher.this.skippedQuietly(var7, description, errors, params);
			} catch (Throwable var8) {
				errors.add(var8);
				ParameterizedTestWatcher.this.failedQuietly(var8, description, errors, params);
			} finally {
				ParameterizedTestWatcher.this.finishedQuietly(description, errors, params);
			}

			MultipleFailureException.assertEmpty(errors);
		}
	};
}
 
Example #6
Source File: ActivitiDmnRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<Throwable>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #7
Source File: FlowableEventRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #8
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			List<Throwable> errors = new ArrayList<Throwable>();

			startingQuietly(description, errors);
			try {
				base.evaluate();
				succeededQuietly(description, errors);
			} catch (AssumptionViolatedException e) {
				errors.add(e);
				skippedQuietly(e, description, errors);
			} catch (Throwable t) {
				errors.add(t);
				failedQuietly(t, description, errors);
			} finally {
				finishedQuietly(description, errors);
			}

			MultipleFailureException.assertEmpty(errors);
		}
	};
}
 
Example #9
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      List<Throwable> errors = new ArrayList<Throwable>();

      startingQuietly(description, errors);
      try {
        base.evaluate();
        succeededQuietly(description, errors);
      } catch (AssumptionViolatedException e) {
        errors.add(e);
        skippedQuietly(e, description, errors);
      } catch (Throwable t) {
        errors.add(t);
        failedQuietly(t, description, errors);
      } finally {
        finishedQuietly(description, errors);
      }

      MultipleFailureException.assertEmpty(errors);
    }
  };
}
 
Example #10
Source File: FlowableFormRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #11
Source File: FlowableAppRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #12
Source File: GremlinProcessRunner.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void runChild(final FrameworkMethod method, final RunNotifier notifier) {
    final Description description = describeChild(method);
    if (this.isIgnored(method)) {
        notifier.fireTestIgnored(description);
    } else {
        final EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
        eachNotifier.fireTestStarted();
        boolean ignored = false;
        try {
            this.methodBlock(method).evaluate();
        } catch (AssumptionViolatedException ave) {
            eachNotifier.addFailedAssumption(ave);
        } catch (Throwable e) {
            if (validateForGraphComputer(e)) {
                eachNotifier.fireTestIgnored();
                logger.info(e.getMessage());
                ignored = true;
            } else
                eachNotifier.addFailure(e);
        } finally {
            if (!ignored)
                eachNotifier.fireTestFinished();
        }
    }
}
 
Example #13
Source File: FlowableCmmnRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #14
Source File: ActivitiFormRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      List<Throwable> errors = new ArrayList<Throwable>();

      startingQuietly(description, errors);
      try {
        base.evaluate();
        succeededQuietly(description, errors);
      } catch (AssumptionViolatedException e) {
        errors.add(e);
        skippedQuietly(e, description, errors);
      } catch (Throwable t) {
        errors.add(t);
        failedQuietly(t, description, errors);
      } finally {
        finishedQuietly(description, errors);
      }

      MultipleFailureException.assertEmpty(errors);
    }
  };
}
 
Example #15
Source File: TestExpectThrows.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** 
 * Tests that {@link #expectThrows} behaves correctly when the Runnable contains an 
 * assumption that does not pass: by allowing that assumption to propogate and cause 
 * the test to <code>SKIP</code>.
 */
public void testNestedAssume() {
  final AtomicBoolean ran = new AtomicBoolean(false);
  AssumptionViolatedException caught = null;
  try {
    final IOException returned = expectThrows(IOException.class, () -> {
        ran.getAndSet(true);
        assumeTrue("this assumption should propogate", false);
      });
    fail("must not complete"); // NOTE: we don't use expectThrows to test expectThrows
  } catch (AssumptionViolatedException ave) {
    caught = ave;
  }
  assertTrue(ran.get());
  assertNotNull(caught);
  assertEquals("this assumption should propogate", caught.getMessage());
}
 
Example #16
Source File: TestExpectThrows.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** 
 * Tests that {@link #expectThrows} behaves correctly when the Runnable contains an 
 * assumption that does not pass but the caller has explicitly said they expect an Exception of that type: 
 * by returning that assumption failure Exception.
 */
public void testExpectingNestedAssume() {
  final AtomicBoolean ran = new AtomicBoolean(false);
  AssumptionViolatedException returned = null;
  try {
    returned = expectThrows(AssumptionViolatedException.class, () -> {
        ran.getAndSet(true);
        assumeTrue("this assumption should be returned, not propogated", false);
      });
  } catch (AssumptionViolatedException caught) { // NOTE: we don't use expectThrows to test expectThrows
    assertNull("An exception should not have been thrown", caught);
  }
  assertTrue(ran.get());
  assertNotNull(returned);
  assertEquals("this assumption should be returned, not propogated", returned.getMessage());
}
 
Example #17
Source File: S3ATestUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static S3AFileSystem createTestFileSystem(Configuration conf) throws
    IOException {
  String fsname = conf.getTrimmed(TestS3AFileSystemContract.TEST_FS_S3A_NAME, "");


  boolean liveTest = !StringUtils.isEmpty(fsname);
  URI testURI = null;
  if (liveTest) {
    testURI = URI.create(fsname);
    liveTest = testURI.getScheme().equals(Constants.FS_S3A);
  }
  if (!liveTest) {
    // This doesn't work with our JUnit 3 style test cases, so instead we'll
    // make this whole class not run by default
    throw new AssumptionViolatedException(
        "No test filesystem in " + TestS3AFileSystemContract.TEST_FS_S3A_NAME);
  }
  S3AFileSystem fs1 = new S3AFileSystem();
  //enable purging in tests
  conf.setBoolean(Constants.PURGE_EXISTING_MULTIPART, true);
  conf.setInt(Constants.PURGE_EXISTING_MULTIPART_AGE, 0);
  fs1.initialize(testURI, conf);
  return fs1;
}
 
Example #18
Source File: AbstractParallelScenarioRunner.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected Statement prepareMethodBlock(final FrameworkMethod method, final RunNotifier notifier) {
	final Statement methodBlock = superMethodBlock(method);
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			try {
				methodBlock.evaluate();
				Description description = describeChild(method);
				try {
					notifier.fireTestStarted(description);
					notifier.fireTestAssumptionFailed(new Failure(description, new AssumptionViolatedException("Method " + method.getName() + " did parse any input")));
				} finally {
					notifier.fireTestFinished(description);
				}
			} catch(TestDataCarrier testData) {
				AbstractParallelScenarioRunner.this.testData.put(method, testData.getData());
			}
		}
	};
}
 
Example #19
Source File: AbstractScenarioRunner.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void process(String data) throws Exception {
	IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate();
	if (delegate instanceof IRegistryConfigurator) {
		IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
		registryConfigurator.setupRegistry();
		try {
			ScenarioProcessor processor = delegate.getInjector().getInstance(processorClass);
			String preProcessed = processor.preProcess(data);
			if (preProcessed == null) {
				throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data);
			}
			doProcess(preProcessed, processor);
		} finally {
			registryConfigurator.restoreRegistry();
		}
	}
}
 
Example #20
Source File: FlowableDmnRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #21
Source File: FlowableIdmRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #22
Source File: ActivitiRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<Throwable>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #23
Source File: S3ATestUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static S3AFileSystem createTestFileSystem(Configuration conf) throws
    IOException {
  String fsname = conf.getTrimmed(TestS3AFileSystemContract.TEST_FS_S3A_NAME, "");


  boolean liveTest = !StringUtils.isEmpty(fsname);
  URI testURI = null;
  if (liveTest) {
    testURI = URI.create(fsname);
    liveTest = testURI.getScheme().equals(Constants.FS_S3A);
  }
  if (!liveTest) {
    // This doesn't work with our JUnit 3 style test cases, so instead we'll
    // make this whole class not run by default
    throw new AssumptionViolatedException(
        "No test filesystem in " + TestS3AFileSystemContract.TEST_FS_S3A_NAME);
  }
  S3AFileSystem fs1 = new S3AFileSystem();
  //enable purging in tests
  conf.setBoolean(Constants.PURGE_EXISTING_MULTIPART, true);
  conf.setInt(Constants.PURGE_EXISTING_MULTIPART_AGE, 0);
  fs1.initialize(testURI, conf);
  return fs1;
}
 
Example #24
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Creates a new instance of {@link jenkins.model.Jenkins}. If the derived class wants to create it in a different way,
 * you can override it.
 */
protected Hudson newHudson() throws Exception {
    jettyLevel(Level.WARNING);
    ServletContext webServer = createWebServer();
    File home = homeLoader.allocate();
    for (JenkinsRecipe.Runner r : recipes)
        r.decorateHome(this,home);
    try {
        return new Hudson(home, webServer, getPluginManager());
    } catch (InterruptedException x) {
        throw new AssumptionViolatedException("Jenkins startup interrupted", x);
    } finally {
        jettyLevel(Level.INFO);
    }
}
 
Example #25
Source File: RetryRule.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected Statement retryIfFailed(Statement base, FrameworkMethod method, Object target) {
   return new Statement() {
      @Override
      public void evaluate() throws Throwable {
         Throwable currentException = null;
         try {
            base.evaluate();
         } catch (Throwable t) {

            if (t instanceof AssumptionViolatedException) {
               throw t;
            }

            currentException = t;

            int retries = getNumberOfRetries(method);

            for (int retryNr = 0; retryNr < retries; retryNr++) {
               logger.warn("RETRY " + (retryNr + 1) + " of " + retries + " on " + target.getClass() + "::" + method.getName(), currentException);
               currentException = null;
               try {
                  base.evaluate();
                  logger.warn("RETRY " + (retryNr + 1)  + " of " + retries + " on " + target.getClass() + "::" + method.getName() + " succeeded");
                  break;
               } catch (Throwable t2) {
                  logger.warn("RETRY " + (retryNr + 1)  + " of " + retries + " on " + target.getClass() + "::" + method.getName() + " failed ", t2);
                  currentException = t2;
               }
            }
            if (currentException != null) {
               throw currentException;
            }
         }
      }
   };
}
 
Example #26
Source File: AbstractParallelScenarioRunner.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void process(String data) throws Exception {
	IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate();
	ScenarioProcessor processor = delegate.getInjector().getInstance(getProcessorClass());
	String preProcessed = processor.preProcess(data);
	if (preProcessed == null) {
		throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data);
	}
	doProcess(preProcessed, processor);
}
 
Example #27
Source File: FlowableFormRule.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void skippedQuietly(AssumptionViolatedException e, Description description, List<Throwable> errors) {
    try {
        skipped(e, description);
    } catch (Throwable t) {
        errors.add(t);
    }
}
 
Example #28
Source File: TestRuleMarkFailure.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Is a given exception (or a MultipleFailureException) an 
 * {@link AssumptionViolatedException}?
 */
public static boolean isAssumption(Throwable t) {
  for (Throwable t2 : expandFromMultiple(t)) {
    if (!(t2 instanceof AssumptionViolatedException)) {
      return false;
    }
  }
  return true;
}
 
Example #29
Source File: AllureRunListener.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
public void fireTestCaseFailure(Throwable throwable) {
    if (throwable instanceof AssumptionViolatedException) {
        getLifecycle().fire(new TestCaseCanceledEvent().withThrowable(throwable));
    } else {
        getLifecycle().fire(new TestCaseFailureEvent().withThrowable(throwable));
    }
}
 
Example #30
Source File: RetryRunner.java    From java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
  EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
  Statement statement = classBlock(notifier);
  try {
    statement.evaluate();
  } catch (AssumptionViolatedException ave) {
    testNotifier.fireTestIgnored();
  } catch (StoppedByUserException sbue) {
    throw sbue;
  } catch (Throwable t) {
    LOG.warning("Retry class: " + getDescription().getDisplayName());
    retry(testNotifier, statement, t, getDescription());
  }
}