Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
26 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 ...
seened's user avatar
  • 43
-1 votes
0 answers
41 views

java.lang.NoClassDefFoundError: org.apache.hadoop.security.SecurityUtil (initialization failure)

I have a spark structured streaming application, with hadoop dependencies included. To support java 17 I have added below jvm args in build.gradle test { jvmArgs += [ '--add-exports=...
Ams's user avatar
  • 19
0 votes
1 answer
34 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 ...
Tom's user avatar
  • 6,302
0 votes
1 answer
42 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....
rahman's user avatar
  • 4,928
0 votes
1 answer
116 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
75 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(...
Abhijit's user avatar
  • 63.6k
0 votes
1 answer
403 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
1 vote
0 answers
91 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 ...
Arjun's user avatar
  • 23
0 votes
0 answers
367 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 ...
Powet's user avatar
  • 167
0 votes
0 answers
200 views

<module_name> Classes in bundle ' do not match with execution data. For report generation the same class files must be used as at runtime

Getting below warning and classes are not showing in code coverage: [WARNING] Classes in bundle '<module_name>' do not match with execution data. For report generation the same class files must ...
Gunjan SHrivastava's user avatar
0 votes
0 answers
92 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
1 answer
506 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
1 vote
0 answers
45 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 ...
gansha9451's user avatar
0 votes
0 answers
34 views

Powermock failed to find the 'modifiers' field in method setInternalState [duplicate]

I am trying to run java test cases. Its a spring boot application. When we run the test classes we get "java.lang.RuntimeException: Internal error: Failed to find the 'modifiers' field in method ...
Joe1988's user avatar
  • 161
0 votes
0 answers
56 views

How to write JUnit test cases for Settings.Global methods?

Could you please support to write Junit test for the following functions storeDataScrollableFromSWC() and readDataScrollableFromSWC()? These belong to a viewmodel class. I tried multiple ways, but ...
Dev_Cob's user avatar
  • 97
3 votes
1 answer
11k views

Migration from Java 8 to Java 17 And Spring 6 JUnit4 failing due to version mismatch

I'm migrating an enterprise product. The things I have migrated are as follows: JDK 1.8 to JDK 17 Spring 5.2.2.RELEASE to Spring 6.0.0 Now, in the process of migration, some tests have started to ...
KuldeeP ChoudharY's user avatar
0 votes
1 answer
2k views

Mockito is not mocking a final class method

I have this code in my service and I'm trying to mock this execute(), context() and build(): Attributes attributes = targetClient.getAttributes( TargetDeliveryRequest.builder() ...
Gustavo Rey's user avatar
0 votes
0 answers
37 views

mock a private method which doesn't return anything using Junit

I am writing a test case in Junit for function which is public[firstFunction] and its invoking another function which is private. public firstFunction(Object1 object1 , Object2 object2){ ...
PG24's user avatar
  • 1
0 votes
1 answer
67 views

Mocked but still null when using PowerMock to mock private method

Here are the brief codes of my project, class Foo: public class Foo { @Autowired protected Mapper mapper; protected User getUser() { // ... return user; } } class Bar ...
vurtne yuan's user avatar
0 votes
0 answers
369 views

Mock java elasticsearch RestHighLevelClient

I want to mock RestHighLevelClient like this: RestHighLevelClient client = mock(RestHighLevelClient.class);, but when I do, it says that mocked client is null. Like it's not properly mocking. So when ...
ReallyNicePerson's user avatar
0 votes
1 answer
4k views

Doing `whenNew` with Mockito 3.5+ (and without PowerMock)

Before you say it, I know this is a piece of code that is hard to test. It is a legacy that I was going to refactor it at some point, but I just didn't want to do it right now. I am currently in the ...
Jovan Perovic's user avatar
0 votes
1 answer
251 views

Unit Test in Java, using Powermock, how to mock/spy xml parser class private method

I would like to write unit test a function that calls another private function. This private function is responsible for reading an XML file from disk. However, I want to avoid dependencies on a real ...
Melih's user avatar
  • 1
0 votes
0 answers
16 views

How to test a method that receives 2 lists as parameters and a Properties to generate a json

I need to test a method that basically contains the generation of a json with different data, the method receives 2 lists and a Properties as parameters. I put code of the method to test: public ...
Jonathan Ortiz's user avatar
0 votes
1 answer
206 views

How do I mock methods of a private final client that's being initialized inside a dependency class?

I have a class that looks like this : class A { private final B b; public A(String x, String y){ b = new B(x,y); } public void someMethod() { b.externalMethod(); }...
abhi gang's user avatar
0 votes
1 answer
209 views

EasyMock mock new instance of a class with arguments

So I'm trying to get rid of PowerMock as I'm updating to java 17 by using EasyMock. But I hit a wall trying to convert this : PowerMock.expectNew(File.class, "path").andReturn(fileMock)....
user2137817's user avatar
  • 1,853
0 votes
1 answer
234 views

How to mock the @ value using power mock not with Mockito?

Need to set the @Value of the service class using power mockito not using Mockito. Tried to set the value using Reflection.utils(class , name , value) it did not work , Since the class was using ...
user1669692's user avatar
1 vote
1 answer
1k views

How to mock a static method in scala?

I have a static method in scala and by static method I mean to say that this method is inside an Object named as MyObject. I also have a class named as MyClass where there is a method which calls the ...
gaurav narang's user avatar
0 votes
0 answers
62 views

how to mock a protected method in an abstract class called from BaseClass

Updating the original question. I will put the original code piece and then put in questions. Class under test package my.main.class.package; public class MyClassHelper extends MySession { //Session ...
Abhinash Jha's user avatar
0 votes
1 answer
119 views

How to mock default method of unimplemented interface?

I'm doing some hands on with Junit/Mockito/PowerMockito I have an interface class import retrofit2.Call; import com.learning.model.user.User; import java.io.IOException; public interface UserService {...
Đức Trường Đặng's user avatar
1 vote
1 answer
3k views

How to use Mockito verify to unit test @Slf4j logging in Spring Boot

I have a requirement to inject the logger as a mock and verify the log method invocation without creating a custom appender. But I'm not able to verify that log method invocation with this approach. @...
Dave's user avatar
  • 35
0 votes
0 answers
117 views

PowerMockitoExtension.class not found

I am using this for my new test cases @ExtendWith(PowerMockitoExtension.class) i have added dependencies in my grade as follow testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io....
Abhishek Khaiwale's user avatar
0 votes
1 answer
112 views

Test case using powerMock in java for class new object mock

I am trying to mock the class instance of a user which is created inside another class which is MyClass method count. I want to write unit test case for Myclass method count Below is sample code ...
aman kumar's user avatar
  • 3,146
0 votes
1 answer
2k views

How to cover by mock test static method InetAddress.getLocalHost()?

I would like to cover by mock test one standard Java method, not all its realisation but only throwing an exception. It looks like: public static InetAddress getLocalHost() throws UnknownHostException ...
Jack's user avatar
  • 33
1 vote
0 answers
120 views

PowerMock.VerifyStatic alternate in mockito

PowerMock.verifyStatic(Util.class) I use this method in powermockito to verify this class, What is the method I need to use in mockito to verify the similar behaviour ?
Aakash V's user avatar
1 vote
0 answers
310 views

org.testng.TestNGException: Error creating object factory

I'm trying to compile a maven project on IntelliJ (Ubuntu 22.04), but during a specific test this happened: ... [ERROR] There was an error in the forked process [ERROR] [ERROR] Error creating object ...
erica's user avatar
  • 13
0 votes
1 answer
117 views

JUnit incompability issue when using powermock and spock

I am trying to run tests and running into this issue warning causing tests not to be run when running a maven build Mar 07, 2023 8:57:49 AM org.junit.platform.launcher.core.DefaultLauncher ...
Geogrio's user avatar
  • 141
0 votes
0 answers
174 views

Why is the PowerMock.whenNew not working here?

I have this simple class: import java.io.File; public class TestPowerMock { public File createFileAndReturnIt() { return new File("/"); } } And this simple test: import ...
Omegaspard's user avatar
  • 1,960
6 votes
1 answer
3k views

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. ...
Spartacus's user avatar
  • 442
0 votes
1 answer
50 views

Not getting how to write power mock test cases for below use case

I am having one java code scenario but not getting how to write power mock test cases for that. Class Test { ClosableHttpClient c; } Class MainTest extends Test{ // code for httpPost and ...
JohnD's user avatar
  • 5
0 votes
1 answer
415 views

Error:org.mockito.exceptions.misusing.MissingMethodInvocationException

I am getting the below error while upgrading java to 17 and mockito to 3.7.7 and junit4 to junit 5 and also I am using these powermock dependencies. 'org.powermock:powermock-...
Aditi Mogha's user avatar
0 votes
0 answers
207 views

How to mock static object inside an Interface by using JUnit5 in Java?

Currently I am using JUnit5 for creating test cases in Java. But in some places I could not implement the test cases due to Mock issue. This is my interface: public interface EntityLookup extends ...
Pamba's user avatar
  • 822
0 votes
1 answer
521 views

Unable to mock Aggregations#get method from elasticsearch

I am trying to test a class using elasticsearch aggregation framework and for some reason am unable to mock the get method of the Aggregations object. I have the relevant classes in @PrepareForTest ...
sudhanva's user avatar
  • 709
0 votes
0 answers
674 views

How to migrate PowerMockito whenNew thenThrow to Mockito Inline MockedConstruction

We're migrating all our code away from PowerMock to Mockito Inline, I've mostly been able to migrate all cases but I don't know how to throw an exception when an instance of a specific class is ...
Neets's user avatar
  • 4,214
0 votes
2 answers
67 views

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 ...
anggor's user avatar
  • 105
0 votes
1 answer
255 views

Log.w() throws `java.lang.RuntimeException: Stub!` despite `@PrepareForTest(Log.class)`

I am trying to write a JUnit (5) for a class that indirectly uses Log.w(). When I first encountered java.lang.RuntimeException: Stub! as a result, I quickly found out that this is a well known issue ...
WebViewer's user avatar
  • 801
0 votes
0 answers
189 views

PowerMock private void method with arguments

I'm looking for a unit test for Controllers using Mockito and PowerMock. Every controller has only private void methods with a single argument and a @Autowired service dependency: public class ...
music bot's user avatar
0 votes
1 answer
460 views

org.jetbrains.annotations @NotNull interfare with Mockito when mock a private method

I'm trying to mock a private method of my service with powermock by passing it the mockito matcher "eq" for its arguments. One of those argument is annotated with the @NotNull decorator from ...
Ugo Evola's user avatar
  • 647
0 votes
0 answers
675 views

Verify invoking a private and static method with ArgumentCaptor

I have a private and static method in a class with private constructor: private static void foo(Obj1 obj1, Obj2 obj2) { //some implementation } I used reflection to invoke it ...
icolak's user avatar
  • 51
1 vote
1 answer
254 views

Java PowerMock: Mock NewDate whenNew, ava.lang.NoClassDefFoundError: org/powermock/tests/utils/ArrayMerger

I am getting 3 errors below when trying to mock New Date, using PrepareForTest. How can I fix this? Reference: https://stackoverflow.com/a/30415404/15435022 java.lang.NoClassDefFoundError: org/...
mattsmith5's user avatar
0 votes
0 answers
86 views

Tests doesn't work properly when using @RunWith(PowerMockRunner.class) and @PowerMockRunnerDelegate(Parameterized.class)

When I run mvn test -Dtest=ClassTest it works however when I run just mvn test it fails because classes that should be mocked by PowerMock are null. Following some details: jdk 1.7 mvn 3.6.3 <...
ibrz's user avatar
  • 1

1
2 3 4 5
41