KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to get PowerMock to work with mockito, and I'm following the documentation here: http://code.google.com/p/powermock/wiki/MockitoUsage13 . To simplify a bit, lets say that I have a static method: StaticObj.put(String key, String val) { ... } And the class to be tested does something like this: public class ClassToTest { public void doSomething(Params p) { if (StringUtils.isNotBlank(p.getK()) StaticObj.put("k1", p.getK()); if (StringUtils.isNotBlank(p.getX()) StaticObj.put("x1", p.getX()); } } In my unit test I'd like to verify that StaticObj.put is called for K and X when they are not blank or null, so I do something like this: public void testNormalCase() { // assume that mocking setup for statics already happened in some @Before function.. Params params = new Params("k", "x"); ClassToTest classToTest = new ClassToTest(); classToTest.doSomething(params); // now I want to verify: PowerMockito.verifyStatic(times(1)); StaticObj.put("k1", "k1"); PowerMockito.verifyStatic(times(1)); StaticObj.put("x1", "x"); } This works, and it's what I'd expect. What doesn't work, is if I comment out the verification for K, then the verification for X fails! The error message indicates that ("x1", "x") is expected but got ("k1", "k"). Why is this? Am I not coding this correctly? Also it leads me to believe that the following type of test, which passes, might pass for the wrong reason entirely: public void testOtherCase() { // assume that mocking setup for statics already happened in some @Before function.. Params params = new Params("k", null); ClassToTest classToTest = new ClassToTest(); classToTest.doSomething(); // now I want to verify: PowerMockito.verifyStatic(neve
Tags (comma-separated)
Save Edits
Cancel