Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] Problem facing during mocking of a Concrete Class

Avinash Nayak

2008-07-14

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,
I am facing a prob while mocking a concrete class.
I am giving a simplified version of the prob.
In the given testcase,
its trying to run the method, when i call mockery.checking().
Is it an expected behaviour?
Because of this,
i am not able to use mocking of a concrete class.
I am using JMock 2.4.0.

Thanks,
avinash


package com.nayak;

public class OpClass {
 public final void execute(boolean validate) {
   System.out.println("In execute() : " + validate);
   if (validate)
     validate();
 }

 private void validate() {
   // No Validations done
   System.out.println("In validate()");
 }
}

package com.nayak;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.action.VoidAction;
import org.jmock.lib.legacy.ClassImposteriser;

import junit.framework.TestCase;

public class OpClassUTEST extends TestCase {
 public void testExecute() {
   Mockery mockery = new Mockery();
   mockery.setImposteriser(ClassImposteriser.INSTANCE);
   final OpClass opClass = mockery.mock(OpClass.class);

   mockery.checking(new Expectations() {
     {
       one(opClass).execute(with(any(Boolean.class)));
       will(VoidAction.INSTANCE);
     }
   });
   mockery.assertIsSatisfied();
 }
}

Output : "In execute() : false"


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.