Questions tagged [powermockito]

Use this tag for questions about PowerMockito, a Java Framework that allows the mocking of usually un-mockable types, i.e. statics, and private methods, in conjunction with the Mockito framework. Questions about using PowerMock with EasyMock should be tagged [powermock] instead.

PowerMockito is used in addition with the Java Framework Mockito. PowerMockito's main strength is the ability to mock Static and Private Methods. A good example of PowerMocktio is the ability to mock Singletons which are generally difficult when unit testing.

Heres a great link to starting out with PowerMockito: Using PowerMock with Mockito

1326 questions
3
votes
2 answers

Mock Protected Parent Method When the Parent is in a Different Package

I need to mock a protected method in the parent class of my class under test but the parent class is in a different package so my test class cannot access that method so I cannot mock it. There's gotta be a solution for this issue without…
javaPlease42
  • 4,699
  • 7
  • 36
  • 65
3
votes
0 answers

Is it possible to mock a static void method in powermock

A class has a method inside which there are several calls of other class's static void methods. i.e. public class Foo() { public void Bar() { //some code OtherClass.callVoidMethod1(); // some code OtherClass.callVoidMethod2(); } } In my unit…
Iwavenice
  • 556
  • 5
  • 22
3
votes
2 answers

How do you cast RuntimeEnvironment.application?

When running Robolectric tests, RuntimeEnvironment.application's type is determined by your configuration. Say I configured RoboApplication.class as my test application, I can cast RuntimeEnvironment.application to my type without…
Some Noob Student
  • 14,186
  • 13
  • 65
  • 103
3
votes
1 answer

Right version for mockito and powermockito to run with testng and java8

I want to know the compatible versions of mockito and powermockito to run with testng and java8. Tests are running fine with java 6, but when the application is upgraded to java 8, all the test cases involving powermock, fail. I also want to know if…
sam100rav
  • 3,733
  • 4
  • 27
  • 43
3
votes
0 answers

JacocoTestReport doesn't cover PowerMock

I am using JacocoTestReport for code coverage and it doesn't cover Power mock code coverage. I know Jacoco and Powermockito don't go well together but wondering if there is a workaround in gradle. I am using the below jacoco in gradle dependencies…
Sweety Bertilla
  • 972
  • 10
  • 35
3
votes
2 answers

PowerMock affecting tests in other test classes

I'm using PowerMock to test the error handling in case of an InterruptedException. Unfortunately, these test sometime seem to have some side effects on other test classes: Mocks that I configure in one test class seem to be still alive in another…
Jan Gassen
  • 3,406
  • 2
  • 26
  • 44
3
votes
1 answer

How to mock hadoop filesystem

I am trying to mock hadoop file system and a constructor using power mock and mockito .But I am getting the following error . I am new to mockitos so I am not sure what is wrong . >java.lang.VerifyError: Inconsistent stackmap frames at branch…
Pramod
  • 493
  • 1
  • 8
  • 16
3
votes
1 answer

java.lang.VerifyError in while running a JUNIT mockito and powermock for maven project

This is the exception when I am running clean cobertura:cobertura. I tried running this as JUNIT from eclipse but still no luck. I am using the following dependencies for My project. org.mockito mockito-all 1.10.19 org.mockito mockito-core…
amitdeol
  • 279
  • 1
  • 14
3
votes
1 answer

Mockito/PowerMockito: Weird Stubbing Exception

I'm getting this org.mockito.exceptions.misusing.UnfinishedStubbingException but based on all posts and descriptions I could find at internet, it doesn't seem to make sense. The exception method states a thenReturn may be missing, but it's not. I…
Sidney de Moraes
  • 993
  • 3
  • 11
  • 29
3
votes
1 answer

Unit testing using the real implementation (classes)

I'm wondering if there is a way to avoid mocking some classes. I'm working on a bigger unit testing thing related with notifications. I run into multiple issues which I was able to fix mostly. Now I'm stuck with some classes like PendingIntent,…
rekire
  • 47,260
  • 30
  • 167
  • 264
3
votes
1 answer

Mock private static method in final class using PowerMockito

I have a final class with private static method which is invoked inside another static method public final class GenerateResponse{ private static Map getErrorDetails(JSONObject jsonObject) { // implementation } …
Harshad Ranganathan
  • 1,820
  • 16
  • 31
3
votes
2 answers

Getting PowerMockito to mock a static method on an Interface?

I have a library I am trying to mock for testing... There is a Java 8 interface with a static method implementation like this: public interface Router { public static Router router(Object param) { return new RouterImpl(param); …
Deven Phillips
  • 1,129
  • 14
  • 39
3
votes
1 answer

PowerMockito.whenNew not working on android's Intent class

I am trying to use a mock Intent object but when using whenNew from PowerMockito, I am not able to mock the constructor. I have tried all possible combination of Arguments, but it just doesn't work.
Nitin Jain
  • 197
  • 1
  • 9
3
votes
2 answers

How to capture constructor arguments using PowerMockito

class A { public B getB(){ // somehow get argType1 and argType2 return new B(argType1, argType2); } } class B{ public B(Type1 t1, Type2 t2){ // something } } I want to Test A, and verify that constructor of B is…
Dhrumil Upadhyaya
  • 1,014
  • 2
  • 10
  • 14
3
votes
1 answer

mock java.nio.file.Paths.get do nothing but throw InvalidPathException

I have two line of code: File file = new File("report_はな.html"); Path path = Paths.get(file.getCanonicalPath()); Is there anyway that I can mock the static method: Paths.get(file.getCanonicalPath()); And only throw the exception…
XL Zheng
  • 363
  • 1
  • 6
  • 14