From 893eb3646baa408fff1b357fea7ba12f46b6c0b8 Mon Sep 17 00:00:00 2001 From: John Ferguson Smart Date: Sun, 4 Nov 2018 17:20:48 +0000 Subject: [PATCH] Fixed an issue with the upgrade to Java 9+ compatibility --- .../thucydides/core/steps/StepFactory.java | 86 +++++++++++++------ .../requirements/BaseRequirementsService.java | 7 +- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/serenity-core/src/main/java/net/thucydides/core/steps/StepFactory.java b/serenity-core/src/main/java/net/thucydides/core/steps/StepFactory.java index 365a654a5e..a0b6f504f9 100644 --- a/serenity-core/src/main/java/net/thucydides/core/steps/StepFactory.java +++ b/serenity-core/src/main/java/net/thucydides/core/steps/StepFactory.java @@ -33,7 +33,7 @@ public class StepFactory { private static final Logger LOGGER = LoggerFactory.getLogger(StepFactory.class); private final DependencyInjectorService dependencyInjectorService; - private static ThreadLocal currentStepFactory = ThreadLocal.withInitial( () -> new StepFactory() ); + private static ThreadLocal currentStepFactory = ThreadLocal.withInitial(() -> new StepFactory()); /** * Create a new step factory. @@ -54,7 +54,7 @@ public StepFactory() { } public static StepFactory getFactory() { - return currentStepFactory.get(); + return currentStepFactory.get(); } public StepFactory usingPages(Pages pages) { @@ -88,9 +88,9 @@ public T getNewStepLibraryFor(final Class scenarioStepsClass) { throw recurciveCallException; } catch (RuntimeException stepCreationFailed) { throw new StepInitialisationException("Failed to create step library for " - + scenarioStepsClass.getSimpleName() - + ":" + stepCreationFailed.getMessage(), - stepCreationFailed); + + scenarioStepsClass.getSimpleName() + + ":" + stepCreationFailed.getMessage(), + stepCreationFailed); } } @@ -242,7 +242,7 @@ private boolean parametersMatchFor(Object[] parameters, Class[] parameterType if (parameter(parameters[parameterNumber]).cannotBeAssignedTo(parameterType)) { return false; } - + if ((parameters[parameterNumber] != null) && (!isAssignableFrom(parameters[parameterNumber], parameterType))) { return false; @@ -332,32 +332,64 @@ public boolean cannotBeAssignedTo(Class parameterType) { } } - public static boolean isAssignableFrom(final Object parameter, final Class parameterType) { + public static boolean isAssignableFrom(final Object argument, final Class parameterType) { if (parameterType.isInterface()) { - return parameterType.isInstance(parameter); + return parameterType.isInstance(argument); } - Class fieldType = parameter.getClass(); - - if (fieldType.equals(Integer.class) || fieldType.equals(int.class)) { - return parameterType.equals(Integer.class) || parameterType.equals(int.class); - } else if (fieldType.equals(Float.class) || fieldType.equals(float.class)) { - return parameterType.equals(Float.class) || parameterType.equals(float.class); - } else if (fieldType.equals(Double.class) || fieldType.equals(double.class)) { - return parameterType.equals(Double.class) || parameterType.equals(double.class); - } else if (fieldType.equals(Character.class) || fieldType.equals(char.class)) { - return parameterType.equals(Character.class) || parameterType.equals(char.class); - } else if (fieldType.equals(Long.class) || fieldType.equals(long.class)) { - return parameterType.equals(Long.class) || parameterType.equals(long.class); - } else if (fieldType.equals(Short.class) || fieldType.equals(short.class)) { - return parameterType.equals(Short.class) || parameterType.equals(short.class); - } else if (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)) { - return parameterType.equals(Boolean.class) || parameterType.equals(boolean.class); - } else if (fieldType.equals(Byte.class) || fieldType.equals(byte.class)) { - return parameterType.equals(Byte.class) || parameterType.equals(byte.class); + Class argumentType = argument.getClass(); + + if (isByte(parameterType)) { + return isByte(argumentType); + } else if (isShort(parameterType)) { + return isShort(argumentType) || isByte(argumentType); + } else if (isInteger(parameterType)) { + return isInteger(argumentType) || isShort(argumentType) || isByte(argumentType); + } else if (isLong(parameterType)) { + return isLong(argumentType) || isInteger(argumentType) || isShort(argumentType) || isByte(argumentType); + } else if (isFloat(parameterType)) { + return isFloat(argumentType); + } else if (isDouble(parameterType)) { + return isDouble(argumentType) || isFloat(argumentType); + } else if (isBoolean(parameterType)) { + return isBoolean(argumentType); + } else if (isCharacter(parameterType)) { + return isCharacter(argumentType); } - return parameterType.isAssignableFrom(fieldType); + return parameterType.isAssignableFrom(argumentType); + } + + private static boolean isInteger(Class fieldType) { + return (fieldType.equals(Integer.class) || fieldType.equals(int.class)); + } + + private static boolean isFloat(Class fieldType) { + return (fieldType.equals(Float.class) || fieldType.equals(float.class)); + } + + private static boolean isDouble(Class fieldType) { + return (fieldType.equals(Double.class) || fieldType.equals(double.class)); + } + + private static boolean isCharacter(Class fieldType) { + return (fieldType.equals(Character.class) || fieldType.equals(char.class)); + } + + private static boolean isLong(Class fieldType) { + return (fieldType.equals(Long.class) || fieldType.equals(long.class)); + } + + private static boolean isShort(Class fieldType) { + return (fieldType.equals(Short.class) || fieldType.equals(short.class)); + } + + private static boolean isBoolean(Class fieldType) { + return (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)); + } + + private static boolean isByte(Class fieldType) { + return (fieldType.equals(Byte.class) || fieldType.equals(byte.class)); } diff --git a/serenity-model/src/main/java/net/thucydides/core/requirements/BaseRequirementsService.java b/serenity-model/src/main/java/net/thucydides/core/requirements/BaseRequirementsService.java index 902b05b81a..f2ffb2a00d 100644 --- a/serenity-model/src/main/java/net/thucydides/core/requirements/BaseRequirementsService.java +++ b/serenity-model/src/main/java/net/thucydides/core/requirements/BaseRequirementsService.java @@ -91,9 +91,10 @@ public List getAncestorRequirementsFor(TestOutcome testOutcome) { java.util.Optional requirement = getParentRequirementOf(testOutcome, tagProvider); if (requirement.isPresent()) { LOGGER.debug("Requirement found for test outcome " + testOutcome.getTitle() + "-" + testOutcome.getIssueKeys() + ": " + requirement); - if (matchingAncestorFor(requirement.get()).isPresent()) { - Requirement matchingAncestor = matchingAncestorFor(requirement.get()).get(); - return getRequirementAncestors().get(matchingAncestor); + Optional matchingAncestor = matchingAncestorFor(requirement.get()); + if (matchingAncestor.isPresent()) { +// Requirement matchingAncestor = matchingAncestorFor(requirement.get()).get(); + return getRequirementAncestors().get(matchingAncestor.get()); // } // // if ((getRequirementAncestors() != null) && (getRequirementAncestors().containsKey(requirement.get()))) {