13,896 questions
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 ...
0
votes
1
answer
54
views
Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK
I get this warning while testing in Spring Boot:
Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an ...
0
votes
1
answer
32
views
Unit testing a stream being retried
I've written a stream that calls the foobarMethod, potentially triggering the mono of a SocketTimeoutException. I want this method to retry 2 times. Manually, this code works but in the junit test I ...
0
votes
0
answers
19
views
How to fix NoSuchMethodError while using MockMVC.perform?
I have the following structure in my integeration tests using Mockito's mockMVC -
@Autowired
MockMvc mockMvc;
MvcResult response = mockMvc.perform(get("/v1/routes/prices")
.param(&...
0
votes
1
answer
42
views
How to create a test case for a JDBC update method in Spring Boot? [closed]
@Override
public void update(Long id, Author author) {
author.setName("ASD");
jdbcTemplate.update(
"UPDATE authors SET id=?, name=?, age=? WHERE id=?",
...
-1
votes
0
answers
29
views
unable to debug unit test cases in intellij
I am trying to debug the test cases in intellij, when I put a breakpoint and try to run the case in debug mode. I am just getting a build output and error saying
Process 'Gradle Test Executor 42' ...
1
vote
1
answer
58
views
How to deal with protected methods while writing unit tests with JUnit
I am new to writing unit tests and having a difficult time understanding a lot of the concepts involved.
I have a method in a class that I am trying to write a unit test for. See below:
public class ...
0
votes
1
answer
34
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 ...
8
votes
1
answer
3k
views
What ist the replacement for deprecated @MockBeans in SpringBoot 3.4.0?
We defined an annotation for our tests to avoid to declare Mockito Mocks for all the test classes.
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@MockBeans({
...
5
votes
1
answer
127
views
Why is the default return value of mocked Comparable object 1, not 0?
I have a class that implements Comparable interface
public class MyClass implements java.lang.Comparable<MyClass>{
@Override
public int compareTo(MyClass o) {
return 2;
}
}
I wrote a ...
1
vote
1
answer
48
views
Junit test cases for a method in Abstract Class which calls a method of its non-abstract Super class
I have a Parent Class Parent
class Parent{
public String calculate(String input){
// does lots of external system calls and complex calculations
}
}
Then I have an ...
0
votes
1
answer
25
views
I'm stub a DAO's method which is wrapped by Mybatis PageHelper Plugin,however it dosen't work
I'm testing some old code,which used Mybatis PageHelper Plugin, with Mockito.
The class to be tested:
import com.github.pagehelper.ISelect;
import com.github.pagehelper.PageHelper;
import com.github....
0
votes
1
answer
18
views
With ArgumentCaptor on a function with 2 different-typed params, is there an elegant way to ignore one of those params?
Every example of ArgumentCaptor I can find focuses on these two cases:
function has 1 param
function has 2+ params of the same type
But what if the function has two params of two different types?
I ...
0
votes
2
answers
36
views
Testing ExecutorService with Mockito
There are smiliar questions to this but they don't quite cover the answer I need, so could anyone help a real noob to Java and Mockito? I have code as part of a larger method in a class like so:
...
0
votes
0
answers
38
views
How to resolve Mockito can only mock non-private & non-final classes in android test
I am trying to test a ViewModel that uses LiveData and i'm really hating android right now.
This is the most recent error that I'm getting,
Mockito cannot mock this class: class com.example....
0
votes
0
answers
34
views
Wanted but not invoked: vidaria.services.SerieService#0 bean.getSeriesById(1L );
My unit test getSerieByIdSimplifiedTest in Spring boot with J unit 5 doesn't work, my controller and service are perfectly implemented, if I delete the verify from my test everything works fine... I ...
1
vote
0
answers
21
views
How to unit test a QuerydslBinderCustomizer with Mockito in Spring Data JPA?
I'm trying to write a unit test for a QuerydslBinderCustomizer method in a Spring Data JPA repository. Here's the code I'm working with:
@Override
default void customize(QuerydslBindings ...
0
votes
0
answers
80
views
Junit test cases failing for static method with java.lang.NoSuchFieldError: PASCAL_CASE_TO_CAMEL_CASE error
creating the sqs object to publish message to sqs queue.
public final class ClientFactory {
private SqsClientFactory() {
throw new ConstructorCallForbiddenException();
}
...
0
votes
0
answers
41
views
test case throwing error - TypeError: Cannot read properties of undefined (reading 'subscribe')
I am getting error "TypeError: Cannot read properties of undefined (reading 'subscribe')".
Below is the report.service.ts code
saveReport(reportData: any, reportType: string, reportId: ...
0
votes
1
answer
17
views
MockedStatic: Wanted but not invoked Actually, there were zero interactions with this mock
I'm running into some trouble with Mockito's MockedStatic where despite my static method getting called (verified by putting debug print statements) with correct arguments, Mockito is still ...
-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=...
0
votes
0
answers
22
views
Mockito test for a method with modelandview parameter
I need to write junit cases for a method like below.
protected void redirectToHomePage(String storeId, String langId, String catalogId, ModelAndView modelAndView, String topCategoryId, ...
1
vote
1
answer
52
views
Mockito fails to verify that a method is never called
I have a Spring Boot application and the following JUnit 5 test where I want to ensure that applicationEventPublisher.publishEvent(any()) is never called. However, the test passed even if the method ...
0
votes
0
answers
20
views
Mocking Cache Config class failing
I haven't mocked the configuration class for cache config properties. Can someone help me with possible unit tests for this cacheable layer ?
CacheConfig.java
import com.github.benmanes.caffeine.cache....
0
votes
1
answer
26
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/...
0
votes
0
answers
61
views
Mockito Not returning the mock response
Method In Test:
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
...
0
votes
1
answer
29
views
How to test a private method that creates a directory using a mocked File object?
I'm trying to test a private method that creates a directory using the File class. However, when I attempt to mock a File object to simulate its behavior, the mock is not used because the method ...
1
vote
1
answer
19
views
Mockito blocks micronaut property injection
Basic problem:
When using @Mock and @InjectMocks in a test, you have to use @Spy on all the beans you still want to inject normally. Problem is that this does not work with @Property you can't use @...
1
vote
2
answers
77
views
Cannot resolve symbol 'anyListOf'
In latest version of Mockito org.mockito.ArgumentMatchers.anyListOf is missing.
Do you know, for Junit 5, how to replace it?
-1
votes
2
answers
105
views
Unsatisfied Dependency Error: Missing TestService1 Bean in EmployeeController
I'm encountering the following error while running my EmployeeControllerTest class. I've been instructed not to modify the controller class. Could anyone please help me resolve this issue?
org....
0
votes
0
answers
28
views
Spring Boot WebSocket Test: HTTP 400 Error on WebSocket Upgrade Request
Title:
Spring Boot WebSocket Test: HTTP 400 Error on WebSocket Upgrade Request
Question:
I'm trying to test a WebSocket endpoint in a Spring Boot application, but I keep getting an HTTP 400 error when ...
0
votes
0
answers
38
views
io.mock.verify does watch wrong queue name
I am sending a msg into my own program by sending it into the incoming sqs queue and then I am trying to check with a verify if my program made a call to a given outgoing queue at the end of it by ...
-3
votes
1
answer
60
views
Mocked method inside lambda expression is not working
I am using the mockito but connection.prepareStatement is not getting matched and I am getting null as PreparedStatement. I have checked connection is getting mocked properly
void myMethod(){
...
0
votes
0
answers
55
views
JUnit 5 + Mockito tests are significantly slower compared to JUnit 4 – how to optimize?
I'm migrating our tests from JUnit 4 to JUnit 5, and I'm noticing a substantial increase in execution time for tests using Mockito. Specifically, empty tests take almost 100 times longer with JUnit 5.
...
1
vote
0
answers
50
views
Mockito Exception for mocking interface HttpServletRequest
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface javax.servlet.http.HttpServletRequest.
Mockito can only mock non-private & non-final classes.
If you're not ...
1
vote
1
answer
52
views
How can I test the 'catch' portion of code in a try-catch, using Mockito, when the 'try' is 'Thread.Sleep()? [duplicate]
I'm using mockito to write test, but I'm really struggling with how to test this specific bit of code:
public void myMethod() {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
throw new ...
0
votes
1
answer
37
views
Cannot mock method beavior on invocation inside configuration class
In my Spring Boot project I have a configuration class like this:
@Configuration
@RequiredArgsConstructor // ... using Lombok
public class MyConfigClass {
private final MyService myService;
...
0
votes
1
answer
104
views
How to mock LocalDateTime.now(ZoneId.of(“America/New_York”)) with mockito4.5.1?
When I unit test for LocalDateTime with jdk 17, follow exception occurred.
java.time.zone.ZoneRulesException: Invalid binary time-zone data: TZDB:America/New_York, version: 2024a
here is my code:
...
0
votes
0
answers
55
views
Quarkus with Panache Reactive - Test Unit with mockito
you developed a service in quarkus with reactive panache.
When I run testUnit I get a connection error to the database, despite using Mockito. I would appreciate your support to solve this error. I ...
1
vote
1
answer
39
views
Test for Email Sending Failure returns HTTP 200 instead of 500
I'm writing a test case to verify that an EmailSendingException results in an HTTP 500 response. However, when the exception is thrown, my test still returns a status of 200 instead of the expected ...
1
vote
1
answer
99
views
Quarkus Reactive Panache Test: "No current Vertx context found" error in Panache.withTransaction()
I am working on a Quarkus project where I'm using Hibernate Reactive with Panache for non-blocking database operations. My service method creates a user inside a transaction using Panache....
0
votes
1
answer
44
views
@Spy with @InjectMocks in Mockito
I am trying to write unit test for my ProjectsService class. the calss depends on ProjectsRepository. So I annoatetd the repository with @Mock to avoid calling real database and annotate the ...
0
votes
0
answers
59
views
Error generating Mocks with @GenerateNiceMocks annotation flutter dart
I am trying to Mock a class with @GenerateNiceMocks, when I setup @GenerateNiceMocks and tried to build the generated files I encountered following problem.
Invalid @GenerateMocks annotation: Mockito ...
1
vote
1
answer
28
views
Trying to test Driver Manager throwing SQLException using Mockito
The constructor I am testing is here:
public Query(String sql, Object... parameters) throws SQLException {
try {
this.conn = DriverManager.getConnection(Credential.URL, ...
-1
votes
2
answers
60
views
Are Mockito @Mock variables references to variables of class under test?
I'm trying to understand how mocks in Mockito work. Here is a simple example.
My questions are:
Do the private variable set of the class Container and the private variable set of the class ...
0
votes
0
answers
32
views
MissingDummyValueError: Either<Failure, User>
import 'package:flutter_bloc_master/core/common/entities/user.dart';
import 'package:flutter_bloc_master/core/error/failures.dart';
import 'package:flutter_bloc_master/features/auth/domain/repository/...
1
vote
2
answers
119
views
Mocking TimeUnit.MILLISECONDS.sleep() with Mockito
I want to test a method in Java 17 (springboot 3.x, Mockito 5.x) and i'm currently using mockito.
This method looks like this :
public int test(){
try {
var test = TimeUnit.MILLISECONDS;
...
2
votes
1
answer
94
views
Java Mocking Issue When Using Parallel Streams
I have the following ImageService:
public class ImageService {
public ImageService() {
}
public List<BufferedImage> getBufferedImages(List<byte[]> imageBytesArrays) {
return ...
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....
1
vote
2
answers
207
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 ...