1,313 questions
0 votes
1 answer
283 views
Mock spark.read().format().options().load() but not spark.table()
I have the following function which I need to test - private HashMap<String, Dataset<Row>> getDataSources(SparkSession spark) { HashMap<String, Dataset<Row>> ds = new ...
0 votes
1 answer
36 views
How to mock for such scenario(getValue1 call getValue2/.../getValue5)
I have following simple code to illustrate what I want to ask: I have a class MyClass, it has 5 methods, getValue1 ... getValue5. In the implementation, calling getValue1 will call getValue2/getValue3/...
1 vote
2 answers
218 views
Junit test case is not working as expected
tried almost everything still getting null in the response Below is the test case @Test public void testValidateMemberData_Success() throws Exception { MemberValidationRequest memberRequest = new ...
0 votes
0 answers
48 views
Mockito Test Method Transport.send inside completable future
So I'm struggling with writing a mockito test method for a method having this piece of code Future<?> future = executor.submit(() -> { try { ...
0 votes
1 answer
192 views
Mock new Date or System.currentTimeMillis
I am setting up tests using Groovy and the Spock framework. My tests depend on the passage of time, and the services in question use new Date() for some rules. Because of this, I would like to modify ...
1 vote
0 answers
57 views
How to mock Files.walk(Paths.get(dropLocation))) using mockito?
How can we mock the below method using mockito? public static List<File> getFilesPath(String dropLocation) throws IOException{ try(Stream<Path> streamPath = Files.walk(Paths.get(...
0 votes
1 answer
76 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....
0 votes
0 answers
65 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&...
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
46 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 ...
0 votes
1 answer
52 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 + ...
0 votes
1 answer
805 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
160 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(...
2 votes
1 answer
924 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 ...
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 ...