Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

java.lang.IllegalStateException.When using EasyMock!

Thread view: 
vysh - 26 Sep 2007 13:03 GMT
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
GArlington - 26 Sep 2007 16:36 GMT
> Hi everyone,
>                     I am using EasyMock in my junit testcases.But it
[quoted text clipped - 47 lines]
> 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...
Lew - 26 Sep 2007 21:46 GMT
> 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'.

Signature

Lew

Roedy Green - 26 Sep 2007 23:39 GMT
>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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.