org.junit.platform.commons.JUnitException Java Examples

The following examples show how to use org.junit.platform.commons.JUnitException. 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: SvnLinkedArtifactTest.java    From MergeProcessor with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the internally saved revision number from the given
 * {@link SvnLinkedArtifact}.
 * 
 * @param artifact the artifact
 * @return the internally saved revision number
 */
private static long getRevision(final SvnLinkedArtifact artifact) {
	try {
		final Field serializationObjectField = SvnLinkedArtifact.class.getDeclaredField("serializationObject");
		serializationObjectField.setAccessible(true);
		final Object serializationObject = serializationObjectField.get(artifact);

		final Class<?>[] classes = SvnLinkedArtifact.class.getDeclaredClasses();
		final Optional<Class<?>> internalClass = Arrays.stream(classes)
				.filter(clazz -> clazz.getSimpleName().equals("SvnLinkedArtifactSerializationObject")).findAny();
		if (internalClass.isPresent()) {
			final Field revisionField = internalClass.get().getDeclaredField("revision");
			revisionField.setAccessible(true);
			return (long) revisionField.get(serializationObject);
		} else {
			throw new JUnitException("Internal class 'SvnLinkedArtifactSerializationObject' not found.");
		}
	} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
		throw new JUnitException("Problem getting revision from SvnLinkedArtifact.", e);
	}
}
 
Example #2
Source File: NativeTestExtension.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void ensureNoInjectAnnotationIsUsed(Class<?> testClass) {
    Class<?> current = testClass;
    while (current.getSuperclass() != null) {
        for (Field field : current.getDeclaredFields()) {
            Inject injectAnnotation = field.getAnnotation(Inject.class);
            if (injectAnnotation != null) {
                throw new JUnitException(
                        "@Inject is not supported in NativeImageTest tests. Offending field is "
                                + field.getDeclaringClass().getTypeName() + "."
                                + field.getName());
            }
        }
        current = current.getSuperclass();
    }

}
 
Example #3
Source File: JaasExtension.java    From taskana with Apache License 2.0 6 votes vote down vote up
private ExtensionContext getParentMethodExtensionContent(ExtensionContext extensionContext) {
  Optional<ExtensionContext> parent = extensionContext.getParent();
  // the class MethodExtensionContext is part of junit-jupiter-engine and has only a
  // package-private visibility thus this workaround is needed.
  while (!parent
      .map(Object::getClass)
      .map(Class::getName)
      .filter(s -> s.endsWith("MethodExtensionContext"))
      .isPresent()) {
    parent = parent.flatMap(ExtensionContext::getParent);
  }
  return parent.orElseThrow(
      () ->
          new JUnitException(
              String.format(
                  "Test '%s' does not have a parent method", extensionContext.getUniqueId())));
}
 
Example #4
Source File: JaasExtension.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  if (isAnnotated(invocationContext.getExecutable(), WithAccessIds.class)) {
    throw new JUnitException("Please use @TestTemplate instead of @Test for multiple accessIds");
  }
  extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example #5
Source File: HiveTestUtil.java    From hudi with Apache License 2.0 4 votes vote down vote up
private static void checkResult(boolean result) {
  if (!result) {
    throw new JUnitException("Could not initialize");
  }
}