Questions tagged [powermockrunner]

23 questions
4
votes
2 answers

How to mock a return from a call to a private method

I have a class which has a method I want to test, but it calls a private method in the same class to get a Map value. I want to mock what the private method returns to the method I want to test. import java.util.*; public class ClassOne { …
Shakakhan
  • 41
  • 1
  • 1
  • 2
2
votes
1 answer

Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp

I recently upgraded my Java version to Java11 for 8 and since then i am seeing this error: java.lang.NoClassDefFoundError: Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp at…
2
votes
1 answer

Mock File.createTempFile() and return our mocked File object

How can we mock File.createTempFile() to return our mocked File object? It should return our mocked file object instead of creating a new temp file and return new object.
Knot
  • 141
  • 13
2
votes
0 answers

PowerMock prepare a class for test without using @PrepareForTest annotation

I have inherited a complex JUnit 4 test class which uses @RunWith(MockitoJUnitRunner.class) Because of a change in implementation I need to use some features from PowerMock to mock static and private methods. But when I try to switch at class level…
Serg M Ten
  • 5,568
  • 4
  • 25
  • 48
1
vote
0 answers

While Running PowerMock getting some exception, hence not able to run Test Cases

java.lang.RuntimeException: Internal error: Failed to find the "modifiers" field in method setInternalState. at org.powermock.reflect.internal.WhiteboxImpl.sedModifiersToField(WhiteboxImpl.java:2348) at…
1
vote
1 answer

Mock static method call using @RunWith(MockitoJUnitRunner.class)

I'm using @RunWith(MockitoJUnitRunner.class). i need to mock a static method call, MosConfigFactory.getInstance(). I can't use @RunWith(PowerMockRunner.class). how can i mock a static method call using MockitoJUnitRunner?
1
vote
0 answers

PowerMockRunner Tests working on Eclipse fail on STS by java.lang.reflect.InvocationTargetException

I'm running a project with some JUnit4 tests that are using PowerMockRunner on Eclipse with no problem, all tests ok. But running the same on Spring Tool Suite (over Eclipse), those tests that use PowerMockRunner fail by initializationError caused…
1
vote
1 answer

Mutation Test Coverage fails when mock static method

I'm trying to get the mutation coverage of unit test but getting weird exception from pitest: 7:55:09 PM PIT >> INFO : MINION : 7:55:09 PM PIT >> SEVERE : Error calculating coverage. Process will exit. java.lang.ExceptionInInitializerError …
fywe
  • 433
  • 1
  • 7
  • 17
1
vote
0 answers

using Powermock annotations via interface or annotation type

We are trying to use Powermock and for starters we feel that it is a very good unit test tool for static method testing. We could not figure out how to use Powermock annotations in interface or annotation types. When we use them in an abstract…
simpleusr
  • 354
  • 4
  • 23
1
vote
0 answers

Powermock 2.x verifyStatic(System.class) is throwing NotAMockException

Mocking System class with Powermock 2.x is failing on verifying calls. The same test passes successfully using Powermock 1.x version. Class: public class SysConfigurer { public void setConfig(String key, String value){ …
ERiverb
  • 11
  • 3
0
votes
0 answers

Powermock Failed to find the "modifiers" field in method setInternalState

I am trying to mock static class with Powermock. I am using JDK 14. However I am getting the below error: Internal error: Failed to find the "modifiers" field in method setInternalState. java.lang.RuntimeException: Internal error: Failed to find…
Spartacus
  • 337
  • 4
  • 12
0
votes
2 answers

Mocking class return NULL even after set the value manually

I'm new to unit testing and try to understand how mocking works. I got the code as below, where I mock PdRequest.class using PowerMockRunner. However, it return Null for all the variables. I also tried to set the value manually but its the same. Is…
anggor
  • 79
  • 1
  • 10
0
votes
0 answers

Can I directly replace @RunWith(PowerMockRunner.class) with @RunWith(MockitoJunitRunner.class)

@RunWith(PowerMockRunner.class) is not working with Eclemma and it is showing 0% coverage for the classes annotated with @RunWith(PowerMockRunner.class) If I replace @RunWith(PowerMockRunner.class) with @RunWith(MockitoJunitRunner.class) the code…
sagar
  • 1
  • 4
0
votes
1 answer

PowerMock ExpectNew creating real objects instead of mocked Ones

public class PersistenceManager { public boolean addUser(User user) { UserPersistor userPersistor = new UserPersistor(user) { @Override void somemethod() { // TODO Auto-generated method stub …
0
votes
4 answers

java.lang.NullPointerException for null input in null safe static method

@Test fun isEmpty_null_true(){ Assert.assertEquals(StringUtils.isEmpty(null),true) } public static boolean isEmpty(@Nullable String value) { return (TextUtils.isEmpty(value) || value.trim().isEmpty()); } All test methods except above one…
Harish Gyanani
  • 1,366
  • 2
  • 22
  • 43
1
2