use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class Invoker method targetMethod.
private static Method targetMethod(Object target, Method method) {
Class<?> targetClass = target.getClass();
Class<?> declaringClass = method.getDeclaringClass();
// same.
if (targetClass.getClassLoader().equals(declaringClass.getClassLoader())) {
return method;
}
try {
// from interfaces are always public.
if (Modifier.isPublic(method.getModifiers())) {
return targetClass.getMethod(method.getName(), method.getParameterTypes());
}
// Loop through all the super classes until the declared method is
// found.
Class<?> currentClass = targetClass;
while (currentClass != Object.class) {
try {
return currentClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
} catch (NoSuchMethodException e) {
currentClass = currentClass.getSuperclass();
}
}
// The method does not exist in the class hierarchy.
throw new NoSuchMethodException(String.valueOf(method));
} catch (NoSuchMethodException e) {
throw new CucumberBackendException("Could not find target method", e);
}
}
use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class GuiceFactoryTest method shouldThrowExceptionIfTwoDifferentInjectorSourcesAreFound.
@Test
void shouldThrowExceptionIfTwoDifferentInjectorSourcesAreFound() {
factory = new GuiceFactory();
assertTrue(factory.addClass(YourInjectorSource.class));
Executable testMethod = () -> factory.addClass(SecondInjectorSource.class);
CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
String exceptionMessage = String.format("" + "Glue class %1$s and %2$s are both implementing io.cucumber.guice.InjectorSource.\n" + "Please ensure only one class configures the Guice context\n" + "\n" + "By default Cucumber scans the entire classpath for context configuration.\n" + "You can restrict this by configuring the glue path.\n" + ClasspathSupport.configurationExamples(), SecondInjectorSource.class, YourInjectorSource.class);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(exceptionMessage));
}
Aggregations