Newest 'powermock' Questions - Stack Overflow

Questions tagged [powermock]

Use this tag for questions about PowerMock, a Java library for creating mock objects for classes and methods. Questions about PowerMock's extension for Mockito should be tagged [powermockito] instead.

0
votes
0answers
14 views

EasyMock/PowerMock - Mocking Static Methods Throws Error: no last call on a mock available

I'm writing a simple Java Class to test EasyMock/PowerMock functionality to mock static methods from class. So I'm just mocking Math.random method to return a constant value for testing purpose. ...
0
votes
1answer
14 views

Android -> EasyMock -> PowerMock -> BluetoothAdapter -> Failed resolution of: MocksControl$MockType

This app shows you can use createMock(BluetoothAdapter.class): https://github.com/riis/AndroidArduino.git So to try that, I add EasyMock and PowerMock to my build.gradle: ...
0
votes
0answers
15 views

Running powermock + mockito on java 11 http client

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', ...
0
votes
1answer
17 views

PowerMockito doesn't mock the new instance called in the tested class

I have the following class where, in the constructor, I call another constructor to build a field of the class: public class ClassIWantToTest { private ClassIWantToMock anotherClass; public ...
0
votes
2answers
47 views

Mocking constructor using powermock on the class which needs to be tested

I am able to mock a constructor call using powermock from inside a class which I want to test. This works when I add the class I want to test in @PrepareForTest. But once I add my class there, even ...
0
votes
0answers
18 views

verifyPrivate not working in Android unit tests

I have been struggling to verify number of calls of a private method in my Android code. The unit tests that I am using is listed below. The signature of the private method that I am testing is ...
0
votes
0answers
17 views

Mockito Mocking of final class static method not always working [duplicate]

Setup: Two classes, both final with static methods: UUID (java), BUKKIT (spigot-api). import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.junit.Before; import org.junit.Test; ...
1
vote
2answers
39 views

Mocking static method inside static method on powermock

I have a static method that looks for the current userSession object and returns a string. public static String getCurrentUser() { UserSession userSession = buildUserSession(); ...
0
votes
0answers
18 views

JUnit Testing Log4j2 logging with Lombok

I have a java class annotated with lombok like so: @Log4j2 public class Foo { private boolean logStr = true; public void doStuff(String str) { if (logStr) { log.info(str); } ...
0
votes
1answer
17 views

Adding @RunWith(PowerMockrunner.class) to test gives all other tests NPE

I have a testclass where I am running Mockito tests, like: public class ViewModelTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } @...
1
vote
1answer
37 views

Mocking static method doesn't work in newer mockito-core version

I'm experiencing strange error while changing mockito-core version. My code: import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org....
0
votes
1answer
37 views

Unit testing for a protected is failing

I have a class EllaService and I would like to test the EllaService::isTrafficIgnored method there. The code is provided below, @Service public class EllaService { @Autowired @Qualifier( ...
0
votes
1answer
22 views

Wanted but not invoked - Error with Powermock while calling static method from another static method with predicate parameter

I am trying to test a utility class having static methods , most of them static and returning Optional. Lot of other objects and parameter are being passed as parameters which i have mocked using ...
0
votes
0answers
9 views

JUnit: Mock private method call inside static method

Mocking private method is pretty easy via PowerMock. But my use case is to mock private method which is being called from the Public static method. Sample code: public class ...
0
votes
1answer
38 views

java.lang.NullPointerException on Url mock tests

My test for Url connection worked correctly. Then after 1 month I ran all tests in the app and test for URL connection failed, I don't know why as I didn't change this class. Please, could someone ...
0
votes
2answers
54 views

Make sure a condition return false when mock calling

I have a class and the code is provided below, @Service public class EllaService { private static final String SHOP_ID_STRING_SEPARATOR = ","; public static final int IRIS_ACCEPT = 0; ...
0
votes
0answers
20 views

UnfinishedStubbingException from the updating a test

I have a class and I would like to test the invokeEllaAsync method from the class. @Service public class EllaService { private static final String SHOP_ID_STRING_SEPARATOR = ","; public ...
2
votes
0answers
28 views

Test a private static method with the PowerMock

I have a POJO class provided below, @JsonInclude( JsonInclude.Include.NON_NULL ) @Getter @Setter public class EllaRequestDto extends BaseDto { private String trackingId; @NotNull ...
1
vote
1answer
41 views

What does @PrepareForTest in PowerMock really mean?

What does the annotation @PrepareForTest in PowerMockito really mean? What should be placed there apart of classes which have static methods?
2
votes
1answer
43 views

How to test a code that invokes Instant.now() with JUnit 5?

I have a code that looks somehow like this: MyObject getMyObject() { Instant now = Instant.now(); return myService.doSomething(now); } I know that PowerMock is not supported in JUnit 5, but ...
0
votes
1answer
20 views

PowerMock with Mockito doesn't create mock for constructor invocations

I'm trying to use PowerMock with mockito to create mock each time any constructor of FileOutputStream is created but it seems to return a real instance instead of a mocked one. My test class : @...
0
votes
0answers
26 views

VerifyStatic on System class is failing with PowerMock 2.0.2

Reference to verifystatic on System class is failing after upgrading powermock version to 2X from 1X Below are my current configurations mockito-core - 2.27.0 powermock-api-mockito2 - 2.0.2 powermock-...
1
vote
1answer
43 views

Exception occurred when mock a class which having static method [duplicate]

I'm writing unit test (using TestNG) for a static method. When mocking the class of the static method I'm getting an exception. @RunWith(PowerMockRunner.class) @PrepareForTest(TempClass.class) public ...
1
vote
0answers
24 views

Mocking Jenkins class for unit testing

I have written a class for cancelling a build of a particular job based on build number. Now I am not understanding how to mock Jenkins related stuffs for my unit tests This is the class /** * ...
0
votes
0answers
12 views

How to mock enum method from another class in junit?

I have a enum class HeatMapStrategy which has a execute function.This function I am calling from another class HeatMapService .When I am running below junit code its not creating the mock of ...
0
votes
2answers
32 views

How to check the values of object created in method under test?

I am testing a method of service layer which creates a new object and calls another service with that object. There is some processing involved in the method upon which some values are set into the ...
0
votes
1answer
18 views

How to do partial mock of newDirectoryStream from Files.java using PowerMock with Mockito? [duplicate]

I would like to partially mock Files.java newDirectoryStream static method. Example below work perfectly fine when I use mockStatic. Unfortunately this approach mock all static methods. I would like ...
0
votes
1answer
20 views

Powermockito mock static method matcher not working

When I'm trying to mock a static method with a String input, mocked stub is getting executed when I give a specific String, but when I use anyString(), it does not work as expected. public class Foo ...
0
votes
1answer
22 views

PowerMockito mockStatic with input

I need to mock a static method which has an input argument. For other functions in the class, original methods must get called and for the function I'm trying to mock, only the mocked stub must be ...
0
votes
0answers
21 views

Powermock `ClassNotPreparedException` while `PrepareForTest` is defined

In my test I wanted to mock a class without a constructor which I found out is therefor a final class; MessageAnimation class MessageAnimation { fun fadeIn(layout: View, delay: Int) { ...
0
votes
1answer
81 views

org.powermock.api.mockito.ClassNotPreparedException in Static class mocking

I am writing a unit test to mock a static method in the verticle but getting ClassNotPreparedException always. I think that its only possible to mock this way if only the class is static, but i have ...
0
votes
2answers
38 views

Mock field injection using Mockito

I Am new in JUnit PowerMockito. Am try to test a method inside a class.that class having an autowired filed. Service Class @Service public class MyServiceRegistration { @Autowired private ...
0
votes
0answers
18 views

Attempts to resolve TooManyConstructorsFound exception failing

I'm running PowerMock 1.6.5 and attempting to mock the creation of a AnnotationConfigApplicationContext.class object. I'm receiving the TooManyConstructorsFound exception and my attempts to resolve ...
1
vote
0answers
42 views

org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner not found

Tried adding deps per Power Mockito showing error for org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner cannot be resolved but no luck. build.gradle reads: .... ...
0
votes
0answers
58 views

Junit test not running

I am facing below error when running my Junit test class: I have added Junit and powermock dependencies in build path. Junit - 4.12 Powermock - 2.0.0 If I had explicitly junit from Add library and ...
0
votes
0answers
14 views

Facing code coverage issue with `PowerMock`

Facing an issue with code coverage. I am using PowerMock for mocking. I am able to see code coverage for classes accepts those I have used with PowerMockito. I have tried answers from many other ...
0
votes
1answer
249 views

Powermock junit5 and mockito2.x not working RunnerTestSuiteChunker not found

I am running powermock with mokito 2.0 , Junit 5 and for Junit 4 having maven-surefire-plugin . Test class looks like import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith;...
0
votes
1answer
31 views

Mock buildin class AWS Logs client builder

I am trying to Mock and use a AWS buildin class. But continuous getting different error. While I am testing a entire method I was able to mock all other but when it comes to credentials formation ...
0
votes
2answers
64 views

Mocks not getting invoked with static members using PowerMockito

I am trying to mock an Impl that contains 2 static members A, B, and a static method Utils.SomeMethod. I tried to mix PowerMock and Mockito initially but was not sure if this was causing the problem ...
1
vote
1answer
35 views

How to mock an internal variable with builder

I am writing unit tests and meet a problem with builder: Here is the class to be test: public class ToBeTest() { public void enact(SomeInput input){ Session s = Session.builder()....
0
votes
1answer
71 views

How to create mockito test for Manual dependency injection

I am creating manual dependency injection using java. I am trying to create Mockito test for the same. As I am new to Mockito and I have done only for framework based before. So need your help on the ...
0
votes
0answers
179 views

How to test code dependent on environment variables using TestNG?

I have a piece of Java code which uses an environment variable. The behavior of the code depends on the value of environment variable. I would like to test this code using TestNG. I have some sample ...
1
vote
0answers
26 views

Why PowerMock runs private method when I call verifyPrivate?

I'm testing some methodA which has another one inside and I need to check that that methodB has not been called due to return. If I run this test with debug, everything works correctly. But test fails ...
0
votes
0answers
24 views

PowerMock together with TestFX4 cause test to never end when executed by surefire

A simple unit test runs infinitely when started by surefire, instead of the fact that it only performs an Assert.assertTrue(true). When the line: @RunWith(PowerMockRunner.class) together with the ...
0
votes
0answers
243 views

How can I make powermock work with Java11?

I have a service project written in Java11. It is using junit tests to cover full code coverage. I have written scheduler method to updateFiles (invoked by Files.walkFileTree) in ...
0
votes
0answers
32 views

java.lang.VerifyError: Stack map does not match the one at exception handler 315

I'm Trying to execute two test case in a class,first test method is excepting a exception and second assert test method.. So when object is created in the second method,it throws exception.. When i ...
0
votes
3answers
108 views

PowerMockito mock private methods in springboot

I am trying to mock a private method inside my class under test which is as below. public String processPayment(...) { //some lines privateMethod(...); return ""; } private Object ...
0
votes
1answer
23 views

How can I return multiple answers in sequential calls to a mocked static method

I have a function that returns the value of java.net.InetAddress.getLocalHost().getHostName() I have written a test for my function like so: @PrepareForTest({InetAddress.class, ClassUnderTest.class}...
0
votes
1answer
50 views

Mock a nested class with constructor parameters and test the methods

I am trying to Mock a class which has a nested class. That nested class was with a constructor argument. When I am trying to test using mockito instead of mocking the actual method is getting ...
1
vote
2answers
36 views

PowerMock not stubbing the right method

I am facing an weird PowerMock issue. Let me explain more in details. My code: @Service public class TestMe { @Autowired private ClassA a; @Autowired private ClassB b; @Autowired ...