powermockito Questions

4

Recently I was upgrading my project from JDK 11 to JDK 17. After upgrading, powermock seems to have an issue. While running AUT's , I am getting following error: java.lang.RuntimeException: PowerMo...
Vickievicksburg asked 9/11, 2021 at 10:3

2

I get an error when running my PowerMockito2 tests on Java 11. I was able to resolve this error by putting this annotation at class level but I do not want to do this. Is there a way not to get thi...
Occlude asked 10/12, 2021 at 17:23

3

I want to use testng + powermock + spring to run test code,my jar version is: powermock = 1.6.2 powermock-module-testng = 1.6.2 mockito = 1.10.19 testng = 6.8.7 spring = 4.1.1.RELEASE JDK = 1.8.0...
Pinzler asked 7/3, 2016 at 5:51

2

I am using Mockito to mock spring beans. It works fine when I mock an interface. In our application, there are few @Component beans which do not implement any interface. When I try to mock such ...
Ecclesiology asked 5/2, 2017 at 7:8

7

Solved

Given a Kotlin singleton object and a fun that call it's method object SomeObject { fun someFun() {} } fun callerFun() { SomeObject.someFun() } Is there a way to mock call to SomeObject.someF...
Livia asked 22/6, 2016 at 20:7

9

I'm having an issue with mockito and powermock, I can mock an abstract class with a final static method with no problems. When trying to mock an Interface as with WebIServerSession I'm getting the ...
Farthing asked 8/11, 2018 at 13:48

2

Today I created a small test project for java 16 preview. I created a sealed interface and a final implementation. I want to know if there is anyway to be able to mock the sealed interface so that ...
Sorce asked 19/7, 2021 at 6:6

5

Solved

While running the test I am getting the error , I am not able to understand why am I getting this error , this code is working with fine in java 8 , while running it in java 17 it is giving error. ...
Teeters asked 28/2, 2022 at 14:49

4

Solved

the below posted method in the code section contains a static method which is "with()". I want to test the code in below, so I coded the test of this method as shown in the testing section. i trie...
Billbillabong asked 18/9, 2017 at 10:23

3

Solved

I am using Powermockito to mock and spy static classes. Version: 2.0.4 Also using mockito-core version 3.0.0. In, one of my projects, i am able to mockStatic by enabling mock-maker-inline as speci...
Interphase asked 17/2, 2020 at 17:48

9

Solved

How I can mock a field variable which is being initialized inline? class Test { private Person person = new Person(); ... public void testMethod() { person.someMethod(); ... } } Here I want ...
Curlew asked 23/3, 2016 at 9:14

7

We are using PowerMock in few of our historical projects. Unfortunately PowerMock is quite dead and is not compatible with Java 11. And we are using mockStatic(). Yes, we know its considered harmf...
Eruptive asked 24/10, 2018 at 10:40

5

Solved

First-timer here, apologies if I've missed anything. I'm hoping to get around a call to a static method using Spock. Feedback would be great With groovy mocks, I thought I'd be able to get past th...
Moonshine asked 5/4, 2013 at 1:9

1

I am migrating all old legacy Log4j1.x Test cases to Log4j2.x based test cases, I've a test case like below, which I am not able to convert, condition is I dont want to change anything in asserts. ...
Transposition asked 9/6, 2022 at 7:21

1

Solved

I am migrating old legacy app from Log4j1.x to 2.x and getting below error while running the test cases. I already went through link: Powermock - java.lang.IllegalStateException: Failed to transfor...
Severable asked 7/6, 2022 at 14:25

2

I have the below method which I need to write unit tests for. But I cannot spy the class KeyStore. It throws the below exception. org.mockito.exceptions.base.MockitoException: Unable to create moc...
Blithesome asked 1/4, 2016 at 10:42

2

Java reflection is becoming more and more restricted: Up to Java 8 all operations are allowed Starting from Java 9 to 15 you are still able to perform the operations, but you will receive a warnin...
Landahl asked 22/6, 2021 at 17:50

2

Why i get nullPointerException despite if i remove observer and use mLivedata.getValue() and assertNotNull(mLiveData) it works well? @RunWith(PowerMockRunner.class) public class LoginRepositoryTes...
Ablution asked 16/9, 2019 at 22:51

2

Solved

I have a code like this for which I would like to write unit test. public class TestClass { private final Executor executor; private final Handler handler; TestClass(Executor executor, Handler h...
Guanabana asked 20/6, 2017 at 11:3

2

I'm using Mockito and PowerMockito to write my Unit Test on Android. I've managed to work with almost all by back stuff, but I'm stuck with the CountDownTimer and Handler. I'm able to mock a su...
Brahmin asked 31/5, 2016 at 14:40

2

Solved

I am trying to verify that a static method is not called in a certain configuration, in a unit test. I am thus using PowerMock (powermock-core:2.0.4 & powermock-module-junit4:2.0.4) and its M...
Pelting asked 7/11, 2019 at 16:18

1

I want to mock a constructor and return a mock object when the constructor is called. This can be achieved using powermockito's whenNew method like this. PowerMockito.whenNew(ClassName.class).withA...
Bourgeon asked 19/11, 2020 at 5:35

2

The Test case I am writing for: public class AClassUnderTest { // This test class has a method call public Long methodUnderTest() { // Uses the FinalUtilityClass which contains static final m...
Maressa asked 11/7, 2017 at 12:19

2

I am trying to run powermock + mockito with Java 11 for unit test cases. I am using the below versions: testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'org.mockito',...
Casting asked 21/6, 2019 at 8:53

1

Solved

When I try to mock certain final classes like SearchGoogleAdsRequest from a certain Google library they give me IllegalAccessError , I have added @PrepareForTest annotation on top of the class. @Ru...
Freudberg asked 26/3, 2021 at 15:14

© 2022 - 2025 — McMap. All rights reserved.