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
4
votes
2 answers

how to mock an instance method invocation from static method while writing junit for static method?

how to mock an instance method invocation from static method while writing junit for static method?I'm writing tests for existing code. class A { public static D methodX() { B b = new B(); C c = b.doSomething(); } } class B { …
AVVD
  • 78
  • 1
  • 10
4
votes
1 answer

PowerMockito is calling real method instead of mocked private one

I have a class that have a private method and calls another private method in its body. So I want to invoke first private method and to mock second one. Here is an example: public class ClassWithPrivateMethod { private int count; public…
Vanguard
  • 1,336
  • 1
  • 15
  • 30
4
votes
2 answers

How to correctly test ORM in android using Mockito?

I am new to Mockito testing in Android and have a problem understanding how to test the data source methods. I use RushOrm that is initialized in the Application class of the app: AndroidInitializeConfig config = new…
Gabi Radu
  • 1,107
  • 2
  • 16
  • 35
4
votes
2 answers

After upgrading from PowerMock 1.6.2 to 1.6.6 to integrate JaCoCo 0.7.8, a "whenNew" call result in a null value

I have a largish Maven multiproject build, with unit tests mostly using PowerMock, at version 1.6.2. I decided to integrate JaCoCo, so we could start to publish our code coverage metrics. The latest version of JaCoCo, 0.7.8, requires PowerMock…
David M. Karr
  • 14,317
  • 20
  • 94
  • 199
4
votes
2 answers

JUnit/Mockito Test case gets passed in Debug Mode but not in Run mode

I am using following method to test the Profile Object updation in my project. import org.apache.commons.collections.MapUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import…
Yogesh Verma
  • 41
  • 1
  • 4
4
votes
2 answers

PowerMock: mocking multiple calls of same method with different parameters behave abnormally

I am new to Mockito, and having an issue that took lot of my time. Below is my problem statement and executable code. Problem Whenever i try to mock multiple behaviours from same method with different arguments mockito/powermockito use the last…
Khalid Shah
  • 3,132
  • 3
  • 20
  • 39
4
votes
1 answer

Ignoring invoking internal static call

public static ResponseBean call(Bean bean) throws Exception { // statements... IgnoreCall.ignoreMethodCall(bean); // statements... // return } With the code snippet above, is it possible to test the method ignoring invocation of…
David B
  • 3,269
  • 12
  • 48
  • 80
4
votes
2 answers

Powermock 1.6.3 with Javassist 3.18.2-GA produces a NoSuchMethodError

I am using Powermock 1.6.3 with Javassist 3.18.2-GA, Mockito 1.10.19, JUnit 4.11 and JDK1.8. I did not write the tests or the test classes and therefore, I am not very familiar with these libraries. Did not have any problems building on JDK1.7. I…
porctree2803
  • 103
  • 2
  • 8
4
votes
1 answer

How to unit test Log.e in android?

I need to perform an unit test where I need to check if an error message is logged when a certain condition occurs in my app. try { //do something } catch (ClassCastException | IndexOutOfBoundsException e) { Log.e(INFOTAG,…
NewOne
  • 401
  • 5
  • 19
4
votes
2 answers

Why do I get UnfinishedStubbingException here?

The test code is: import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import java.time.LocalTime; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import…
traveh
  • 2,700
  • 3
  • 27
  • 44
4
votes
1 answer

Mocking method for all instances of class with PowerMockito

I am trying to mock a method whatever the instance that calls this method is. As far as I could got reading this can't happen with Mockito and should be done with PowerMockito, but I can't figure out the way it should be done. I have public class…
Jeni
  • 1,088
  • 12
  • 30
4
votes
3 answers

Instantiating a Class with private constructor using Java/Mockito/PowerMockito

I am writing a test case using JUnit and the method under test takes a final class with a private constructor as a parameter. Since I cannot instantiate it with the new keyword I tried using Mockito but found out that Mockito doesn't like final…
user5192032
4
votes
1 answer

Testing private static method that internally uses another private static method in Java

I have a class A, that looks like the following: public class A { // there is a public API that uses both // method1 and method2, but that's not important // in this question. public Integer publicApi(Integer a, Integer b) { // a bunch…
Nishant Kelkar
  • 412
  • 1
  • 4
  • 20
4
votes
2 answers

PowerMock + Robolectric + Dagger2. Part I

This question was created from first part of PowerMock + Robolectric + Dagger2 So i'm a little bit again. Sorry. I test custom view class which contain: android ui elements some logic static methods callings dagger2 dependencies So i use next…
xoxol_89
  • 1,242
  • 11
  • 17
4
votes
0 answers

Scala / PowerMockito - Java final classes causing build error in Scala Tests using Powermockito

I have a final class: public final class AClass { private final AConfig aClassConfig; public final static BeanName = "aClass" } and I'm trying to mock it in…
Bryce Langlotz
  • 303
  • 1
  • 4
  • 17