Skip to content

Commit

Permalink
Fixed an issue with the upgrade to Java 9+ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Nov 4, 2018
1 parent b5078d3 commit 893eb36
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class StepFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(StepFactory.class);
private final DependencyInjectorService dependencyInjectorService;

private static ThreadLocal<StepFactory> currentStepFactory = ThreadLocal.withInitial( () -> new StepFactory() );
private static ThreadLocal<StepFactory> currentStepFactory = ThreadLocal.withInitial(() -> new StepFactory());

/**
* Create a new step factory.
Expand All @@ -54,7 +54,7 @@ public StepFactory() {
}

public static StepFactory getFactory() {
return currentStepFactory.get();
return currentStepFactory.get();
}

public StepFactory usingPages(Pages pages) {
Expand Down Expand Up @@ -88,9 +88,9 @@ public <T> T getNewStepLibraryFor(final Class<T> 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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ public List<Requirement> getAncestorRequirementsFor(TestOutcome testOutcome) {
java.util.Optional<Requirement> 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<Requirement> 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()))) {
Expand Down

0 comments on commit 893eb36

Please sign in to comment.