Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerMockito can't partial mock public static methods #281

Closed
johanhaleby opened this issue Jul 24, 2015 · 1 comment
Closed

PowerMockito can't partial mock public static methods #281

johanhaleby opened this issue Jul 24, 2015 · 1 comment

Comments

@johanhaleby
Copy link
Collaborator

From DanFabul...@gmail.com on May 26, 2010 20:18:33

To reproduce: Apply the attached patch to add a test to PowerMock.

The patch adds new public static methods to StaticExample:

publicObjectMethod (which returns new Object())

publicObjectMethodCaller (which calls the first method).

We then spy on StaticExample and attempt to mock out publicObjectMethod,
returning "Hello Static" instead of new Object().

Expected: The test should pass

Actual: Failure: java.lang.AssertionError: expected: but
was:java.lang.Object@2927fa12

ALTERNATE REPRO: Apply this one-line patch to StaticExample.java:

Index: StaticExample.java

--- StaticExample.java ( revision 1319 )
+++ StaticExample.java (working copy)
@@ -38,7 +38,7 @@
return privateObjectMethod();
}

  •   private static Object privateObjectMethod() {
    
  •   public static Object privateObjectMethod() {
            return new Object();
    } 
    

Actual:
StaticPartialMockingTest#partialMockingOfStaticMethodReturningObjectWorks
fails java.lang.AssertionError: expected: but
was:java.lang.Object@7b2884e0

Expected: The test should continue to pass.

I'm using PowerMock 1.3.8 on OSX 10.6.3

Attachment: public-static-method.patch

Original issue: http://code.google.com/p/powermock/issues/detail?id=261

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on July 22, 2010 00:39:39

Status: Fixed
Labels: Milestone-Release1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant