Title: [jbehave] [618] trunk/core/src/java/jbehave/core/behaviour: [dn] fixed bug where behaviour class instance was being reused across behaviour methods

Diff

Modified: trunk/core/src/behaviour/jbehave/core/behaviour/BehaviourClassBehaviour.java (617 => 618)

--- trunk/core/src/behaviour/jbehave/core/behaviour/BehaviourClassBehaviour.java	2006-12-06 15:57:24 UTC (rev 617)
+++ trunk/core/src/behaviour/jbehave/core/behaviour/BehaviourClassBehaviour.java	2006-12-06 20:37:15 UTC (rev 618)
@@ -7,6 +7,9 @@
  */
 package jbehave.core.behaviour;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import jbehave.core.listener.BehaviourListener;
 import jbehave.core.minimock.UsingMiniMock;
 import jbehave.core.mock.Matcher;
@@ -51,7 +54,7 @@
     }
     
     public void shouldVerifySingleBehaviourMethod() throws Exception {
-        // given...
+        // given
         Mock listener = mock(BehaviourListener.class);
         final Behaviour[] capturedBehaviour = new Behaviour[1]; // the behaviour
         
@@ -62,18 +65,18 @@
         };
         Behaviour behaviour = new BehaviourClass(ClassWithOneBehaviourMethod.class, verifier);
 
-        // when...
+        // when
         behaviour.verifyTo((BehaviourListener) listener);
         
-        // then...
+        // then
         ensureThat(capturedBehaviour[0], isBehaviourMethodFor("shouldDoOneThing"));
     }
     
     public void shouldCountSingleBehaviourMethod() throws Exception {
-        // given...
+        // given
         Behaviour behaviour = new BehaviourClass(ClassWithOneBehaviourMethod.class, nullVerifier);
 
-        // then...
+        // then
         ensureThat(behaviour.countBehaviours(), eq(1));
     }
     
@@ -83,27 +86,27 @@
     }
     
     public void shouldVerifyMultipleBehaviourMethods() throws Exception {
-        // given...
+        // given
         Mock listener = mock(BehaviourListener.class);
         Behaviour behaviour = new BehaviourClass(
                 ClassWithTwoBehaviourMethods.class, new BehaviourVerifier((BehaviourListener) listener));
         
-        // expect...
+        // expect
         listener.expects("gotResult").with(successfulResultFromMethodCalled("shouldDoOneThing"));
         listener.expects("gotResult").with(successfulResultFromMethodCalled("shouldDoAnotherThing"));
         
-        // when...
+        // when
         behaviour.verifyTo((BehaviourListener) listener);
         
-        // then...
+        // then
         verifyMocks();
     }
     
     public void shouldCountMultipleBehaviourMethods() throws Exception {
-        // given...
+        // given
         Behaviour behaviour = new BehaviourClass(ClassWithTwoBehaviourMethods.class, nullVerifier);
 
-        // then...
+        // then
         ensureThat(behaviour.countBehaviours(), eq(2));
     }
 
@@ -125,28 +128,31 @@
     }
     
     public void shouldVerifyNestedBehaviourClasses() throws Exception {
-        // given...
+        // given
         Mock listener = mock(BehaviourListener.class);
         Behaviour behaviour = new BehaviourClass(
                 ClassWithNestedClasses.class, new BehaviourVerifier((BehaviourListener) listener));
         
-        // expect...
+        // expect
         listener.expects("gotResult").with(successfulResultFromMethodCalled("shouldDoSomething1"));
         listener.expects("gotResult").with(successfulResultFromMethodCalled("shouldDoSomething2"));
         
-        // when...
+        // when
         behaviour.verifyTo((BehaviourListener) listener);
         
-        // then...
+        // then
         verifyMocks();
     }
     
     public void shouldCountNestedBehaviourClasses() throws Exception {
-        // given...
+        // given
         Behaviour behaviour = new BehaviourClass(ClassWithNestedClasses.class, nullVerifier);
 
-        // then...
-        ensureThat(behaviour.countBehaviours(), eq(2));
+        // when
+        int count = behaviour.countBehaviours();
+        
+        // then
+        ensureThat(count, eq(2));
     }
     
     public static class ClassWithDeeplyNestedClasses implements Behaviours {
@@ -156,28 +162,31 @@
     }
     
     public void shouldVerifyDeeplyNestedBehaviourClasses() throws Exception {
-        // given...
+        // given
         Mock listener = mock(BehaviourListener.class);
         Behaviour behaviour = new BehaviourClass(
                 ClassWithDeeplyNestedClasses.class, new BehaviourVerifier((BehaviourListener) listener));
         
-        // expect...
+        // expect
         listener.expects("gotResult").with(successfulResultFromMethodCalled("shouldDoSomething1"));
         listener.expects("gotResult").with(successfulResultFromMethodCalled("shouldDoSomething2"));
         
-        // when...
+        // when
         behaviour.verifyTo((BehaviourListener) listener);
         
-        // then...
+        // then
         verifyMocks();
     }
     
     public void shouldCountDeeplyNestedBehaviourMethods() throws Exception {
-        // given...
+        // given
         Behaviour behaviour = new BehaviourClass(ClassWithDeeplyNestedClasses.class, nullVerifier);
 
-        // then...
-        ensureThat(behaviour.countBehaviours(), eq(2));
+        // when
+        int count = behaviour.countBehaviours();
+        
+        // then
+        ensureThat(count, eq(2));
     }
     
     public static class HasNoBehaviourMethods {
@@ -185,17 +194,17 @@
     }
     
     public void shouldIgnorePublicMethodsThatDontStartWithShould() throws Exception {
-        // given...
+        // given
         Mock listener = mock(BehaviourListener.class);
         Behaviour behaviour = new BehaviourClass(HasNoBehaviourMethods.class, nullVerifier);
         
-        // expect...
+        // expect
         listener.expects("gotResult").never();
         
-        // when...
+        // when
         behaviour.verifyTo((BehaviourListener) listener);
         
-        // then...
+        // then
         verifyMocks();
     }
     
@@ -204,17 +213,42 @@
     }
     
     public void shouldIgnoreNonPublicMethodsThatStartWithShould() throws Exception {
-        // given...
+        // given
         Mock listener = mock(BehaviourListener.class);
         Behaviour behaviour = new BehaviourClass(HasNonPublicBehaviourMethod.class, nullVerifier);
         
-        // expect...
+        // expect
         listener.expects("gotResult").never();
         
-        // when...
+        // when
         behaviour.verifyTo((BehaviourListener) listener);
         
-        // then...
+        // then
         verifyMocks();
     }
+    
+    private static List instantiatedClasses;
+    
+    public static class CapturesClassInstance {
+        public void shouldCaptureInstance() {
+            instantiatedClasses.add(this);
+        }
+        public void shouldAlsoCaptureInstance() {
+            instantiatedClasses.add(this);
+        }
+    }
+    
+    public void shouldCreateNewInstanceForEachBehaviourMethod() throws Exception {
+        // given
+        instantiatedClasses = new ArrayList();
+        BehaviourListener nullListener = (BehaviourListener) stub(BehaviourListener.class);
+        Behaviour behaviour = new BehaviourClass(CapturesClassInstance.class, nullVerifier);
+        
+        // when
+        behaviour.verifyTo(nullListener);
+        
+        // then
+        ensureThat(instantiatedClasses.size(), eq(2));
+        ensureThat(instantiatedClasses.get(0), not(sameInstanceAs(instantiatedClasses.get(1))));
+    }
 }

Modified: trunk/core/src/behaviour/jbehave/core/story/domain/MultiStepScenarioBehaviour.java (617 => 618)

--- trunk/core/src/behaviour/jbehave/core/story/domain/MultiStepScenarioBehaviour.java	2006-12-06 15:57:24 UTC (rev 617)
+++ trunk/core/src/behaviour/jbehave/core/story/domain/MultiStepScenarioBehaviour.java	2006-12-06 20:37:15 UTC (rev 618)
@@ -166,7 +166,7 @@
         // expect
         given.expects("containsMocks").will(returnValue(false));
         event.expects("containsMocks").will(returnValue(false));
-        outcome.expects("containsMocks").will(returnValue(true)); // mock mock!
+        outcome.expects("containsMocks").will(returnValue(true)); // has mocks
 
         Scenario scenario = new MultiStepScenario() {
             public void specify() {

Modified: trunk/core/src/java/jbehave/core/behaviour/BehaviourClass.java (617 => 618)

--- trunk/core/src/java/jbehave/core/behaviour/BehaviourClass.java	2006-12-06 15:57:24 UTC (rev 617)
+++ trunk/core/src/java/jbehave/core/behaviour/BehaviourClass.java	2006-12-06 20:37:15 UTC (rev 618)
@@ -23,7 +23,6 @@
 
     private static final String BEHAVIOUR_METHOD_PREFIX = "should";
     private final Class classToVerify;
-    private final Object instance;
     private final BehaviourVerifier verifier;
     private Matcher methodFilter;
     public static final Matcher ALL_METHODS = new Matcher() {
@@ -47,8 +46,8 @@
 
     public BehaviourClass(Class classToVerify, final String methodName, BehaviourVerifier verifier) {
         this.classToVerify = classToVerify;
-        this.instance = createInstance();
         this.verifier = verifier;
+        
         if (methodName.length() == 0) {
             this.methodFilter = ALL_METHODS;
         } else {
@@ -84,7 +83,7 @@
     }
     
     public BehaviourMethod createBehaviourMethod(Method method) {
-        return new BehaviourMethod(instance, method);
+        return new BehaviourMethod(createInstance(), method);
     }
     
     private Method[] getMethods(Matcher methodFilter){

Modified: trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java (617 => 618)

--- trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java	2006-12-06 15:57:24 UTC (rev 617)
+++ trunk/extensions/swing/src/behaviour/jbehave/extensions/threaded/swing/DefaultWindowWrapperBehaviour.java	2006-12-06 20:37:15 UTC (rev 618)
@@ -22,7 +22,6 @@
 public class DefaultWindowWrapperBehaviour extends UsingMiniMock {
 	
 	public void shouldClickAButtonOnAWindow() throws Exception {
-        todo("find out why this is platform dependent");
 		checkForHeadless();
 		DefaultWindowWrapper wrapper = new DefaultWindowWrapper("a.window");
         
@@ -53,7 +52,7 @@
 
 	
 	public void shouldEnterTextIntoTextComponents() throws Exception {
-        todo("find out why this is platform dependent");
+        todo("not working on linux");
         checkForHeadless();
         DefaultWindowWrapper wrapper = new DefaultWindowWrapper("a.window");
 
@@ -126,7 +125,7 @@
     }
     
     public void shouldSimulateKeyPressesForInputMap() throws TimeoutException {
-        todo("find out why this is platform dependent");
+        todo("not working on linux");
         checkForHeadless();
 		DefaultWindowWrapper wrapper = new DefaultWindowWrapper("a.window");
 		
@@ -148,7 +147,6 @@
     }
     
     public void shouldSimulateKeyPressesForKeyListeners() throws TimeoutException {
-        todo("find out why this is platform dependent");
         checkForHeadless();
         DefaultWindowWrapper wrapper = new DefaultWindowWrapper("a.window");
         


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to