Hi everybody,
today while I was writing a JUnitAdapter for my behaviours I realized that
it's ignoring the behaviour methods
of nested Behaviours. In the example below, it would ignore the Foo and Bar
behaviour methods.
public class AllBehaviours implements Behaviours {
public Class[] getBehaviours() {
return new Class[] { AllCoreBehaviours.class };
}
}
public class AllCoreBehaviours implements Behaviours {
public Class[] getBehaviours() {
return new Class[] {
FooBehaviour.class,
BarBehaviour.class
};
}
}
I wrote the code to make it possible and I'm sending attached the patch for
you to take a look.
I hope I can help you as you've been helping me.
Cheers,
______________________
Alexandre Martins Nunes
http://m.artins.net
Index:
/Users/amartinsn/Documents/Programming/Projects/jbehave/extensions/junit/src/behaviour/org/jbehave/junit/JUnitAdapterBehaviour.java
===================================================================
---
/Users/amartinsn/Documents/Programming/Projects/jbehave/extensions/junit/src/behaviour/org/jbehave/junit/JUnitAdapterBehaviour.java
(revision 725)
+++
/Users/amartinsn/Documents/Programming/Projects/jbehave/extensions/junit/src/behaviour/org/jbehave/junit/JUnitAdapterBehaviour.java
(working copy)
@@ -77,6 +77,42 @@
}
}
+ public void shouldCountMultipleBehaviourMethodsAsTestsRecursively() {
+ // setup
+ JUnitAdapter.setBehaviours (new BehavioursWithOneBehavioursClass());
+ Test suite = JUnitAdapter.suite();
+ // execute
+ int testCaseCount = suite.countTestCases();
+
+ // verify
+ ensureThat(testCaseCount, eq(3));
+ }
+
+ public static class BehavioursWithOneBehavioursClass implements Behaviours
{
+ public Class[] getBehaviours() {
+ return new Class[] {
+ new AnotherBehavioursWithOneBehavioursClass().getClass()
+ };
+ }
+ }
+
+ public static class AnotherBehavioursWithOneBehavioursClass implements
Behaviours {
+ public Class[] getBehaviours() {
+ return new Class[] {
+ new BehavioursWithTwoBehaviourClasses().getClass()
+ };
+ }
+ }
+
+ public static class BehavioursWithTwoBehaviourClasses implements
Behaviours {
+ public Class[] getBehaviours() {
+ return new Class[] {
+ HasTwoMethods.class,
+ HasSingleMethod.class
+ };
+ }
+ }
+
public void shouldNotExecuteBehaviourMethodsWhileCountingThem() throws
Exception {
// setup
JUnitAdapter.setBehaviours(new
BehavioursAdapter(HasFailingMethod.class));
Index:
/Users/amartinsn/Documents/Programming/Projects/jbehave/extensions/junit/src/java/org/jbehave/junit/JUnitAdapter.java
===================================================================
---
/Users/amartinsn/Documents/Programming/Projects/jbehave/extensions/junit/src/java/org/jbehave/junit/JUnitAdapter.java
(revision 725)
+++
/Users/amartinsn/Documents/Programming/Projects/jbehave/extensions/junit/src/java/org/jbehave/junit/JUnitAdapter.java
(working copy)
@@ -89,10 +89,14 @@
}
private static TestSuite createBehavioursTestSuite(Behaviours behaviours) {
- TestSuite suite = new TestSuite(behaviours.toString());
- Class[] behaviourClasses = behaviours.getBehaviours();
- for ( int i = 0; i < behaviourClasses.length; i++ ){
- suite.addTest(createBehaviourTestSuite(new
BehaviourClass(behaviourClasses[i])));
+ TestSuite suite = new TestSuite(behaviours.toString());
+ Class[] behaviourClasses = behaviours.getBehaviours ();
+ for ( int i = 0; i < behaviourClasses.length; i++ ) {
+ if (isBehavioursType(behaviourClasses[i])) {
+
suite.addTest(createBehavioursTestSuite((Behaviours)newInstance(behaviourClasses[i])));
+ } else {
+ suite.addTest(createBehaviourTestSuite(new
BehaviourClass(behaviourClasses[i])));
+ }
}
return suite;
}
@@ -106,6 +110,16 @@
return suite;
}
+ private static boolean isBehavioursType(Class clazz) {
+ Class[] interfaces = clazz.getInterfaces();
+ for ( int i = 0; i < interfaces.length; i++ ) {
+ if (interfaces[i].equals(Behaviours.class)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private static Behaviours getBehaviours() {
if ( behaviours != null ){
return behaviours;
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email