cucumber/cucumber-jvm — pull request #188 by vasiliygagin (2012-02-01 23:52:04+00:00)
Title: For issue #186. Cucumber tries to instantiate parent classes via Spring

As requested I've created failing test:
java/src/test/java/cucumber/runtime/java/ClasspathMethodScannerTest.java
java/src/test/java/cucumber/runtime/java/test2/Stepdefs2.java

To fix the bug, I've passed additions parameter "Class candidateClass" to JavaBackend.addHook and JavaBackend.addStepDefinition methods. Fixed affected test cases.

While running build I've noticed that cucumber-spring test cases broke. That was because some inner class with hooks was discovered. Not sure if those should be ignored or instantiated by creating parent class first. To be safe I've just "replaced" such classes with their super classes. That is what happening in current implementation.
See following ClasspathMethodScanner chunk of code for details:

while (candidateClass.getEnclosingClass() != null && !Modifier.isStatic(candidateClass.getModifiers())
&& candidateClass != Object.class) {
// those can't be instantiated without container class present.
candidateClass = candidateClass.getSuperclass();
}