Results 1 to 4 of 4

Thread: EasyMock :: unexpected call call

  1. #1
    Join Date
    Jul 2008
    Posts
    3

    Default EasyMock :: unexpected call call

    Hello,

    I have a problem with easymock when i test a method the error is :

    Code:
    java.lang.AssertionError: 
      Unexpected method call openSession("user", "password"):
        openSession("user", "password"): expected: 1, actual: 1 (+1)
    	at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:29)
    	at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:45)
    	at $Proxy2.openSession(Unknown Source)
    	at com.mypackage.SdaSynchronizer.synchronize(SdaSynchronizer.java:47)
    	at com.mypackage.TelephonySynchroServiceImpl.synchronize(TelephonySynchroServiceImpl.java:164)
    	at com.mypackage.tests.TelephonySynchroServiceImplTestCase.testSynchronizeLine(TelephonySynchroServiceImplTestCase.java:143)
    	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 junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	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)
    I don't understand why this exception is called . can some one help me

    thank's
    Last edited by kakachis; Aug 19th, 2008 at 05:36 AM. Reason: change packages

  2. #2

    Default The expect() on the method call is wrong

    in your mock object you would have written an expectation for method openSession("user", "password")
    i guess your code will be something like

    expect(mockServiceObj.openSession("user", "password")).andReturn()...
    or
    mockServiceObj.openSession("user", "password");

    Easy mock assumes that the above call willbe made only once throughout the testcase method. But your service layer tries to do this call more than once. Try to look into your implementation, find out the number of time the above method is being called and rewrite the expectation (Which might look something like below)


    expect(mockServiceObj.openSession("user", "password")).andReturn().anyTimes()
    or
    expect(mockServiceObj.openSession("user", "password")).andReturn().times(n);

    where n: number of times the method gets called.

    mockServiceObj.openSession("user", "password");
    expectLastCall().times(n);


    Hope this helps.

  3. #3
    Join Date
    Jul 2008
    Posts
    3

    Default

    Tank you parveen ,

    really i have the expect method. the problem i had is that i have a bean wich call my client this client abstract the real web service. i solved the problem withe expectandstubreturn method.

    Really i don't understand the principle but my problem is solved.

    Thank you

  4. #4
    Join Date
    Jun 2011
    Posts
    1

    Default I also have the same problem.

    I have a somehow different question, though. What is meant by mock objects expectation. sorry if this might sound dumb. i am a newbie in mock objects.

    in my case actually, I have something like this in my testClass:

    EM em = EasyMock.createMock(EM.class);
    RD roleD = EasyMock.createMock(RD.class);
    // add mock object expectations here

    EasyMock.replay(em);
    EasyMock.replay(roleD);

    RD result = testClass.methodCalled(em, rD);

    // add additional test code here
    EasyMock.verify(em);
    EasyMock.verify(roleDetails);

    assertNotNull(result);

    so the error said:
    java.lang.AssertionError
    Unexpected method <unexpectedMethodCalled>
    where <unexpectedMethodCalled> is actually called in the <methodCalled> in the real code

    what could be the possible cause for this? how do i solve it?

    thanks so much.
    Last edited by sedfrey18; Jun 13th, 2011 at 09:50 AM. Reason: lacking point

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •