2,033 questions
1 vote
1 answer
112 views
Why failed when using mockito3 + powermock2 to mock new object
I am trying to mock a constructor method. But failed with messages said unnecessary stubbings. What modify should I make to succesfully run this unit test? Plus, Better not to modify the version of ...
0 votes
0 answers
103 views
Could not reconfigure JMX java.lang.LinkageError
Java 8 Maven 3.9,7 I want to validate that a private method was called once. In my pom.xml: <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</...
0 votes
1 answer
120 views
java.lang.NoSuchMethodError: org.mockito.invocation.InvocationFactory.createInvocation(Ljava/lang/Object
Java 8 Maven 3.9. I want to verify is void private method call. I try PowerMock. pom.xml <properties> <powermock.version>2.0.2</powermock.version> </properties> ...
0 votes
0 answers
28 views
Vaadin 14 UI unit test exception when creating the test layout
I am writing my UI unit test code with Junit 4.12 and PowerMock 1.6.5. I have a MyLayout which extends Vaadin 14 VerticalLayout and try to test it. When I create a new instance for MyLayout (new ...
0 votes
0 answers
38 views
Getting org.powermock.api.mockito.ClassNotPreparedException, class is not prepared for test
Original Scala Code, the method in the XYZ class and OauthProvider: Here we are trying to test a static method. At first, you may see the original code and then you can see that how I have written the ...
1 vote
0 answers
42 views
Ignoring specific library for a module in Gradle
I have migrated our multi-module Gradle project from Mockito v1 to Mockito v3. As part of the migration, the following libraries were upgraded or added: mockito-core from 1.10.19 to 3.12.4 (and added ...
0 votes
1 answer
50 views
mock throw exception and new object seems not to be working using powermock
I have following simple test case that use powermock to mock throw exception from the method of ExceptionClass.getRandom by mocking the creation of Random object. But, from the test result, it looks ...
0 votes
1 answer
105 views
Failed to transform org.apache.hadoop.fs.FileSystem$Cache. org.apache.hadoop.fs.FileSystem$Cache$Key class is frozen
I am trying to mock the hadoop filesystem in my scala test. Any Idea how to go around this please: import java.net.URI import org.apache.hadoop.conf.Configuration import org.apache.hadoop.fs....
0 votes
1 answer
211 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. ...
0 votes
0 answers
85 views
How to throw exception with super constructor been mocked
I have an exception class public class FooStudioException extends SpamException { public FooStudioException(String message, String localizedMessage, Throwable cause) { super(...
0 votes
1 answer
806 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 ...
1 vote
0 answers
92 views
How to mock constructors using mockito? [duplicate]
I am testing a method some class which has a new constructor call of BuildingBlockDbHandler.class. I was earlier using powermock to mock constructors like this way - BuildingBlockDbHandler ...
0 votes
0 answers
540 views
How can you assign a mock to a private static field in Java 17?
Suppose I need to assert on the behavior of an object stored in a private static final field (and I can't change the modifiers because, for example, it's a write-only class or generated code) public ...
1 vote
1 answer
604 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 ...
1 vote
0 answers
60 views
Mocking Singleton Class Constructor using Powemock
The problem is exactly similar to the one described How to mock enum singleton with jmockit?. I am using powermock with Junit in Java. there are some other singlton classes too without constructor ...