diff --git a/build.gradle b/build.gradle index 5d31395d1f..2bcb72d43d 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ subprojects { assertjVersion = '1.7.0' slf4jVersion = '1.7.7' cglibVersion = '2.2.2' - paranamerVersion = '2.7' + paranamerVersion = '2.8' jansiVersion = '1.11' gsonVersion = '2.3' guavaVersion = '18.0' diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ParameterNameUtil.java b/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ParameterNameUtil.java index bf421ecf46..a73aaa38a7 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ParameterNameUtil.java +++ b/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ParameterNameUtil.java @@ -3,7 +3,6 @@ import static java.lang.String.format; import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -22,23 +21,8 @@ public class ParameterNameUtil { private static final Paranamer PARANAMER = new BytecodeReadingParanamer(); - private static final Method GET_PARAMETERS_METHOD = getParametersMethod(); - private static Method getNameMethod; - - private static Method getParametersMethod() { - try { - /** - * This method only exist since Java 8, thus we have to use reflection to use it, - * to stay compatible with Java 6 - */ - return Method.class.getMethod( "getParameters" ); - } catch( NoSuchMethodException e ) { - return null; - } - } - - /** - * @throws NullPointerException iif {@code constructorOrMethod} is {@code null} + /** + * @throws NullPointerException iif {@code constructorOrMethod} is {@code null} */ public static List mapArgumentsWithParameterNames( AccessibleObject constructorOrMethod, List arguments ) { Preconditions.checkNotNull( constructorOrMethod, "constructorOrMethod must not be null." ); @@ -48,7 +32,7 @@ public static List mapArgumentsWithParameterNames( AccessibleObje return Collections.emptyList(); } - List names = getParameterNames( constructorOrMethod ); + List names = getParameterNamesUsingParanamer( constructorOrMethod ); List result = Lists.newArrayList(); if( names.size() == arguments.size() ) { @@ -65,36 +49,6 @@ public static List mapArgumentsWithParameterNames( AccessibleObje return result; } - private static List getParameterNames( AccessibleObject constructorOrMethod ) { - if( GET_PARAMETERS_METHOD != null ) { - return getParameterNamesUsingJava8( constructorOrMethod ); - } else { - return getParameterNamesUsingParanamer( constructorOrMethod ); - } - } - - private static List getParameterNamesUsingJava8( AccessibleObject constructorOrMethod ) { - try { - Object[] parameters = (Object[]) GET_PARAMETERS_METHOD.invoke( constructorOrMethod ); - List parameterNames = Lists.newArrayList(); - for( Object parameter : parameters ) { - String name = (String) getNameMethod( parameter.getClass() ).invoke( parameter ); - parameterNames.add( name ); - } - return parameterNames; - } catch( Exception e ) { - log.warn( format( "Could not call method getParameters on '%s'", constructorOrMethod ), e ); - return Collections.emptyList(); - } - } - - private static Method getNameMethod( Class aClass ) throws NoSuchMethodException { - if( getNameMethod == null ) { - getNameMethod = aClass.getMethod( "getName" ); - } - return getNameMethod; - } - private static List getParameterNamesUsingParanamer( AccessibleObject constructorOrMethod ) { try { return Arrays.asList( PARANAMER.lookupParameterNames( constructorOrMethod ) ); diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ReflectionUtil.java b/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ReflectionUtil.java index f10d8e01d7..724194aa99 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ReflectionUtil.java +++ b/jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/ReflectionUtil.java @@ -3,7 +3,12 @@ import static java.lang.String.format; import java.lang.annotation.Annotation; -import java.lang.reflect.*; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.List; @@ -249,7 +254,7 @@ public static void makeAccessible( AccessibleObject object, String errorDescript object.setAccessible( true ); } catch( SecurityException e ) { log.debug( "Caught exception: ", e ); - log.warn( "Could not make %s accessible, trying to access it nevertheless and hoping for the best.", + log.warn( "Could not make {} accessible, trying to access it nevertheless and hoping for the best.", toReadableString( object ), errorDescription ); } } diff --git a/jgiven-java8-tests/src/test/java/com/tngtech/jgiven/tests/java8/Java8Test.java b/jgiven-java8-tests/src/test/java/com/tngtech/jgiven/tests/java8/Java8Test.java index 4c52e27435..65251bdd38 100644 --- a/jgiven-java8-tests/src/test/java/com/tngtech/jgiven/tests/java8/Java8Test.java +++ b/jgiven-java8-tests/src/test/java/com/tngtech/jgiven/tests/java8/Java8Test.java @@ -7,7 +7,7 @@ import com.tngtech.jgiven.junit.SimpleScenarioTest; import com.tngtech.jgiven.report.model.StepModel; -public class Java8Test extends SimpleScenarioTest { +public class Java8Test extends SimpleScenarioTest> { @Test public void lambda_steps_work() {