wujun / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

verifyStatic is not reliable #415

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Check attached file
2.
3.

What is the expected output? What do you see instead?
When verifyStatic is called without a static call ==> failure
When verifyStatic is called before a call that was not watched ==> failure
When verifyStatic is called twice for a single base call ==> failure

What version of the product are you using? On what operating system?
Powermock 1.4.12
Mockito 1.9.0
JUnit 4.11

Please provide any additional information below.

Original issue reported on code.google.com by thomas.b...@gmail.com on 6 Dec 2012 at 2:37

Attachments:

GoogleCodeExporter commented 9 years ago
Yes there are some known quirks with verifyStatic. The problem is that it's 
hard to do something about.. There are several possibilities that I can think 
of that may work better:

1.
new VerifyStatic() {{
   MyClass.myStatic();
}};

2. verifyStatic(new StaticVerification() {

   @Override
    public void verify() {
       MyClass.myStatic();
    }
}

3. Using Java 8:
verifyStatic( () -> {MyClass.myStatic();} )

Original comment by johan.ha...@gmail.com on 7 Dec 2012 at 6:18

GoogleCodeExporter commented 9 years ago
Hi Johan
I do understand this is difficult in the current way.
In fact I was more thinking about
1) tracking the issue
2) updating the doc to state that more clearly
...
9) do somthing about it :)
  a) the way you suggest
  b) something more dirty like
    verifyStaticBegin();
    MyClass.myStatic();
    verifyStaticEnd();

Original comment by thomas.b...@gmail.com on 7 Dec 2012 at 9:02

GoogleCodeExporter commented 9 years ago
Could you help out with a bit of clarifying documentation in the Javadoc for 
this and submit a patch?

Original comment by johan.ha...@gmail.com on 7 Dec 2012 at 9:45