java.lang.IllegalStateException.When using EasyMock!

Discussion in 'Java' started by vysh, Sep 26, 2007.

  1. vysh

    vysh Guest

    Hi everyone,
    I am using EasyMock in my junit testcases.But it
    is giving an exception, which I failed to resolve.

    This is my code
    ------------------------


    SOAPHeader unsubHead =
    currCntxt.getMessage().getSOAPHeader();

    Here currCntxt is a MessageContext object.I need to expect this
    particular method.

    My test class contains this code.

    MessageContext currCntxt =
    EasyMock.createMock(MessageContext.class);
    SOAPHeader sphead =
    EasyMock.createMock(SOAPHeader.class);


    EasyMock.expect(currCntxt.getMessage().getSOAPHeader()).andReturn(sphead).once();

    replay(currCntxt);
    replay(sphead);

    but its giving the follwing exception.

    Caused an ERROR
    0 matchers expected, 1 recorded.
    java.lang.IllegalStateException: 0 matchers expected, 1 recorded.
    at
    org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:
    42)
    at
    org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:
    34)
    at
    org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:
    26)
    at org.easymock.internal.RecordState.invoke(RecordState.java:64)
    at
    org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:
    24)
    at
    org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:
    56)

    It would me helpful if anyone could put some lights on the issue.

    thanks,
    vysh
    vysh, Sep 26, 2007
    #1
    1. Advertising

  2. vysh

    GArlington Guest

    On 26 Sep, 13:03, vysh <> wrote:
    > Hi everyone,
    > I am using EasyMock in my junit testcases.But it
    > is giving an exception, which I failed to resolve.
    >
    > This is my code
    > ------------------------
    >
    > SOAPHeader unsubHead =
    > currCntxt.getMessage().getSOAPHeader();
    >
    > Here currCntxt is a MessageContext object.I need to expect this
    > particular method.
    >
    > My test class contains this code.
    >
    > MessageContext currCntxt =
    > EasyMock.createMock(MessageContext.class);
    > SOAPHeader sphead =
    > EasyMock.createMock(SOAPHeader.class);
    >
    > EasyMock.expect(currCntxt.getMessage().getSOAPHeader()).andReturn(sphead).once();
    >
    > replay(currCntxt);
    > replay(sphead);
    >
    > but its giving the follwing exception.
    >
    > Caused an ERROR
    > 0 matchers expected, 1 recorded.
    > java.lang.IllegalStateException: 0 matchers expected, 1 recorded.
    > at
    > org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:
    > 42)
    > at
    > org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:
    > 34)
    > at
    > org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:
    > 26)
    > at org.easymock.internal.RecordState.invoke(RecordState.java:64)
    > at
    > org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:
    > 24)
    > at
    > org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:
    > 56)
    >
    > It would me helpful if anyone could put some lights on the issue.
    >
    > thanks,
    > vysh



    As far as I can see your problem is here:
    > EasyMock.expect(currCntxt.getMessage().getSOAPHeader()).andReturn(sphead).once();

    should be
    EasyMock.expect(currCntxt.getMessage().getSOAPHeader()).andReturn(sphead.class).once();
    if you are checking for type, or you should currCntxt message
    SOAPHeader to sphead ifyou are expecting the value...
    GArlington, Sep 26, 2007
    #2
    1. Advertising

  3. vysh

    Lew Guest

    GArlington wrote:
    > As far as I can see your problem is here:
    >> EasyMock.expect(currCntxt.getMessage().getSOAPHeader()).andReturn(sphead).once();

    > should be
    > EasyMock.expect(currCntxt.getMessage().getSOAPHeader()).andReturn(sphead.class).once();
    > if you are checking for type, or you should currCntxt message
    > SOAPHeader to sphead ifyou are expecting the value...


    If 'sphead' is a class, it should be spelled with an initial upper-case
    letter, by convention. Likewise, the 'H' of 'Head' should be upper case, by
    convention.

    If 'sphead' is a variable, the 'H' should still be upper case (by convention),
    and the class should be obtained through the instance method 'getClass()'
    instead of the class variable 'class'.

    --
    Lew
    Lew, Sep 26, 2007
    #3
  4. vysh

    Roedy Green Guest

    >If 'sphead' is a class, it should be spelled with an initial upper-case
    >letter, by convention. Likewise, the 'H' of 'Head' should be upper case, by
    >convention.
    >If 'sphead' is a variable, the 'H' should still be upper case (by convention),
    >and the class should be obtained through the instance method 'getClass()'
    >instead of the class variable 'class'.

    see http://mindprod.com/jgloss/codingconventions.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Sep 26, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page