Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] unexpected invocations

ckujawa

2008-01-18

Replies: Find Java Web Hosting

Author LoginPost Reply

Greetings!

 

I’ve encountered a problem while writing some tests I was hoping you could help me with.  I’m mocking an object in my test using the following code in my setup method:

                  noFormat = new JUnit4Mockery()

                  {{setImposteriser(ClassImposteriser.INSTANCE);}};

            noFrmtError = noFormat.mock(JcfdError.class);

            noFormat.checking(new Expectations() {{

                  atLeast(1).of (noFrmtError).setErrCode(JcfdError.errorCode.failed);

                  atLeast(1).of (noFrmtError).setFailReason("Task is missing 'FORMAT' command.");

            }});

 

When I run the tests and pass “noFrmtError” into the method under test, setErrCode and setFailReason should be called one time each. After I tried using an invocation-count of one and seeing the test fail, I used atLeast(1) and the test still fails.  My Failure Trace is:

java.lang.AssertionError: unexpected invocation: jcfdError.setFailReason("Task has no PRINTERNUMBER or PRINTERNAME command.")

expectations:

  allowed, already invoked 2 times: jcfdError.setErrCode(<failed>); returns a default value

  allowed, already invoked 1 time: jcfdError.setFailReason("Task is missing 'FORMAT' command."); returns a default value

      at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:56)

      at org.jmock.Mockery.dispatch(Mockery.java:204)

      at org.jmock.Mockery.access$000(Mockery.java:37)

      at org.jmock.Mockery$MockObject.invoke(Mockery.java:246)

      at org.jmock.internal.InvocationDiverter.invoke(InvocationDiverter.java:27)

      at org.jmock.internal.ProxiedObjectIdentity.invoke(ProxiedObjectIdentity.java:36)

      at org.jmock.lib.legacy.ClassImposteriser$4.invoke(ClassImposteriser.java:137)

      at com.loftware.jcfda.error.JcfdError$$EnhancerByCGLIB$$2f7032e9.setFailReason(<generated>)

      at com.loftware.jcfda.mapper.translators.Task.Validate(Task.java:259)

      at com.loftware.jcfda.test.Task_junit.testValidate_noFormat(Task_junit.java:451)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:585)

      at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)

      at org.jmock.integration.junit4.JMock$1.invoke(JMock.java:36)

      at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)

      at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)

      at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)

      at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)

      at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)

      at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)

      at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)

      at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)

      at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)

      at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)

      at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)

      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)

      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 

Any insight as to what I’m doing wrong/how to work around this would be greatly appreciated.

 

Thank you!

 

-Chris

 

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