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

All Questions

Tagged with
0 votes
0 answers
63 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.3k
1 vote
0 answers
89 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
  • 13
0 votes
0 answers
14 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
  • 141
0 votes
0 answers
35 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
  • 87
0 votes
0 answers
24 views

How to return different values with the same method call in the same class in a loop?

I am looping over a list table names to do the following Call describe table to check if the table exists If the table doesn't exist, throw ResourceNotFoundException. Call createTable method to ...
Mojo jojo's user avatar
0 votes
0 answers
52 views

mock an executor service with power mock

I have made my function async with executor service but while executing test cases are not executing the executor service method. The update code similar to: void method1(Status status) { ...
Techi's user avatar
  • 23
3 votes
1 answer
7k 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
946 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
74 views

JUnit powermock throw exception IllegalAccessError:cannot clear JavaAgentClassRegister

In java,use powermock to test.There are 3 projects in my workspace. Two of them has been run without any problem.But last one throw Exception java.lang.IllegalStateException: Cannot clear ...
user22520757's user avatar
0 votes
0 answers
18 views

Unable to mock a constructor using PowerMock

I have the following class definitions : A.java public final class A { public A(){} public int testB() { B newB = new B(); return newB.getNumber(); } } B.java public class B { ...
Thejdeep's user avatar
0 votes
1 answer
113 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
0 votes
1 answer
109 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
1 answer
350 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
1 answer
198 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
  • 851
0 votes
0 answers
167 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

15 30 50 per page
1
2 3 4 5
50