verifyStatic - how to verify that concrete static method has been called with given parameters values

5,907 views
Skip to first unread message

jumarko

unread,
Feb 21, 2012, 5:10:21 AM2/21/12
to PowerMock
Hi,

I wonder if it is possible to verify that some concrete static method
of given class has been called.
E.g. let's have a MyClass class with metod

public static void setStaticField(String fieldValue) {
staticField = fieldValue;
}


Somewhere in code that I want to test is call
MyClass.setStaticField("someValue");

At the end of test I want to check if method MyClass#setStaticField
has been called with parameter "someValue".


Thanks.

Johan Haleby

unread,
Feb 21, 2012, 6:14:14 AM2/21/12
to powe...@googlegroups.com
Are you using Mockito or EasyMock? With the Mockito extension API you can do:
PowerMockito.verifyStatic();
Static.firstStaticMethod(param);
With EasyMock:

StaticService.sayHello();
expectLastCall().once();




--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powermock?hl=en.


Jean-Christophe DEROUET

unread,
Feb 21, 2012, 6:14:41 AM2/21/12
to powe...@googlegroups.com
Hi, not sure, but if you use Powermockito, you can add the concept of ArgumentMatcher, though I never tried this with a static field

2012/2/21 jumarko <jum...@gmail.com>

Juraj Martinka

unread,
Feb 21, 2012, 8:31:12 AM2/21/12
to powe...@googlegroups.com
This is exactly what I want. Thank you very much and sorry for this silly question - now I can see that this is mentioned in documentation:

PS: I'm using Mockito


2012/2/21 Johan Haleby <johan....@gmail.com>
Reply all
Reply to author
Forward
0 new messages