Skip to content

Commit

Permalink
introduced ArgumentResolutionException (->johannes, marc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Merdes authored and Matthias Merdes committed Nov 11, 2015
1 parent 03fd06c commit 4bfeac3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
Expand Up @@ -64,7 +64,6 @@ public static Object invokeMethod(Method method, Object target, Object... argume
return method.invoke(target, arguments);
}


public static Optional<Class<?>> loadClass(String name) {
return loadClass(name, getDefaultClassLoader());
}
Expand Down
Expand Up @@ -76,6 +76,9 @@ public void execute(EngineExecutionContext context) {
if (ex instanceof InvocationTargetException) {
exceptionThrown = ((InvocationTargetException) ex).getTargetException();
}
if (ex instanceof ArgumentResolutionException) {
exceptionThrown = ex.getCause();
}
}
finally {
exceptionThrown = executeAfterMethods(context, testClass, testInstance, exceptionThrown);
Expand All @@ -98,7 +101,7 @@ else if (exceptionThrown instanceof TestAbortedException) {
}

private void invokeTestMethod(EngineExecutionContext context, Object testInstance)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
throws InvocationTargetException, IllegalAccessException, ArgumentResolutionException {

MethodTestDescriptor methodTestDescriptor = getTestDescriptor();

Expand All @@ -109,7 +112,7 @@ private void invokeTestMethod(EngineExecutionContext context, Object testInstanc
}

private List<Object> prepareArguments(MethodTestDescriptor methodTestDescriptor)
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
throws ArgumentResolutionException {

//todo: should probably not be instantiated here, maybe be brought along by the executionContext
MethodArgumentResolverEngine argumentResolver = new MethodArgumentResolverEngine();
Expand Down
@@ -0,0 +1,19 @@
/*
* Copyright 2015 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.junit.gen5.engine.junit5.execution.injection;

public class ArgumentResolutionException extends Exception {

public ArgumentResolutionException(String message, Throwable cause) {
super(message, cause);
}

}
Expand Up @@ -26,15 +26,21 @@ public class MethodArgumentResolverEngine {
*
* @param methodTestDescriptor the test descriptor for the underlying (test) method
* @return a list of Objects to be used as arguments in the method call - will be an empty list in case of no-arg methods
* @throws NoSuchMethodException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws ArgumentResolutionException
*/
public List<Object> prepareArguments(MethodTestDescriptor methodTestDescriptor) throws ArgumentResolutionException {

public List<Object> prepareArguments(MethodTestDescriptor methodTestDescriptor)
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
try {
return this.doPrepareArguments(methodTestDescriptor);
}
catch (Exception root) {
throw new ArgumentResolutionException("problem with argument resolution", root);
}

}

private List<Object> doPrepareArguments(MethodTestDescriptor methodTestDescriptor)
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
Method testMethod = methodTestDescriptor.getTestMethod();

List<Object> arguments = new ArrayList<>();
Expand Down

0 comments on commit 4bfeac3

Please sign in to comment.