Skip to main content
The 2024 Developer Survey results are live! See the results

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
0 votes
1 answer
39 views

Use PowerMock to mock java.io.File not effectively

I have code such as: File file = File createTempFile(“xxx”, “txt”); So, when I use PowerMock to mock this file object, such as: @RunWith(PowerMockRunner.class) @PrepareForTest({File.class,StringUtils....
Chenet Chen's user avatar
0 votes
0 answers
11 views

android - unit test spy behavior different between Mokito and PowerMokito

Below two case pass test but why the times is different? Mokito case is 1 and 1 but PowerMokito case is 2 and 1 for the add api call. package com.example; import static org.junit.Assert.assertEquals; ...
lucky1928's user avatar
  • 8,611
0 votes
0 answers
44 views

How to mock Files API from java.nio.file.*

I am using Java nio API and have a below code, but unable to perform mocking on the below code. Path path = Paths.get(filePath); long sizeInBytes = Files.size(path); long recordCount = 0; try (Stream&...
PAA's user avatar
  • 11.5k
0 votes
0 answers
28 views

InvocationTargetException when using PowerMockito to test Static Methods

I have a final class ConfigurationManager that has a method getProps(CONF). I have to mock and return "true" when this method is called. public final class ConfigurationManager { ...
John K Jose's user avatar
0 votes
1 answer
35 views

Issue with using PowerMock to a project which is using Robolectric

I am writing tests for a class which requires Android specific components to be available. Versions used: robolectric:4.10.3 powermock: 2.0.9 I am getting this error Failed to instantiate DeepCloner. ...
SyntaxSage's user avatar
0 votes
0 answers
37 views

Mockito MockedStatic Object, pass as an argument to class

Unable to pass type MockedStatic object into method/ constructor I have this legacy code - class Mom { Mom(Class StaticBaby){ } } I've used Mockito's mockstatic (v5.12) to mock out StaticBaby ...
user24031969's user avatar
0 votes
0 answers
12 views

ArgumentCaptor works on String type but fail on Intent type

I have a function with two argument, one is android Intent, another one is String. I use ArgumentCaptor to capture it but the Intent Object verify fail, the String one works fine. Error: Expected :...
lucky1928's user avatar
  • 8,611
0 votes
1 answer
33 views

Mocking an object without a getter

I want to mock a function that has following code - // Getting all ad insights objects from API Connection<AdsInsights> insightsConnection = facebookClient.fetchConnection( adAccountId + ...
ujjawal's user avatar
0 votes
1 answer
99 views

Power Mock and Mockito Version Incompatible

I'm working on a legacy code base using JDK 1.8. For one of my unit tests, I want to use PowerMock so that I can call the PowerMock.mockStatic() method on a static method (Provider.provider()) from ...
TechGoose's user avatar
0 votes
0 answers
26 views

How to read the written data from the Servlet's Response [duplicate]

1.Now, I have this Response object, and I'm using the Response.getWriter object to write to it and some JSON data. PrintWriter writer = response.getWriter(); writer.write("hello world"); ...
沐雨听风's user avatar
0 votes
0 answers
44 views

maven build/verify scanning class but not showing in coverage report

Trying to generate jacoco code coverage report , test class is getting scanned but getting below warning : [WARNING] Classes in bundle '<module_name>' do not match with execution data. For ...
Gunjan SHrivastava's user avatar
0 votes
0 answers
63 views

Mockito exeception : java.lang.IllegalStateException: Failed to transform class

I am using JAVA 1.8 with the Javaassist version as 3.23.1 and power mock 1.6.6. I am facing this issue when I am including a class in @PrepareForTest.Here the MainClass class here is the annotations @...
Saurabh Raj's user avatar
1 vote
0 answers
91 views

PowerMock WhenNew rewrite

I am updating to JDK17 and it seems PowerMock is not compatible, as a result one of my test classes is not working and the code that I am trying to replace is : whenNew(A::class.java).withAnyArguments(...
mmdreza baqalpour's user avatar
1 vote
1 answer
247 views

Not prepared for test

I have a test which is getting an error while integrating the static mock. org.powermock.api.mockito.ClassNotPreparedException: [Ljava.lang.Object;@76304b46 The class com.sda.helper.IbanUtil not ...
Berlin's user avatar
  • 11
1 vote
1 answer
347 views

NoSuchMethodException JDK17 Spring

We are working on migrating the application from jdk11 to jdk17. As we have to mock final static method we are using powermockrunner. We are using PowerMockito.mockStatic to mock the static class. If ...
mohitkira's user avatar

15 30 50 per page
1
2 3 4 5
88