13,916 questions
0
votes
0
answers
45
views
Mockito MockStatic behavior leaking to other junit tests
I am using Mockito 5.20.0 to mock a static method, but the mock is not correctly closing / the mocked behavior is leaking outside of the tests it is intended to apply to. This is only a problem if ...
1
vote
1
answer
102
views
Does adding opens configuration in maven surefire plugin effect anything outside the test scope?
I'm working on a user-related service that handles personal information. While writing unit tests with Mockito, I ran into dependency issues with Byte Buddy, which prevented me from using the latest ...
0
votes
1
answer
93
views
Executing lambda functions inside transactionExecutor threads for unit tests
i have few methods that need to be iterated in new transactions but facing errors when i try to write unit tests for them
@Inject
private SchedulerUtil schedulerUtil;
@Inject
private ...
2
votes
1
answer
146
views
Mockito, Java not producing reliable results
I have a Java test class setup with Mockito and get some strange behavior. My class looks as follows:
@ExtendWith(MockitoExtension.class)
public class FrameworkTest {
@Mock private OrderService ...
-2
votes
1
answer
63
views
Mock constructor of FileWriter
Trying to mock a constructor of FileWriter so that I can test the catch block. Here is my sample code:
public void write01() throws IOException {
BufferedWriter bufferedWriter = null;
try {
...
0
votes
1
answer
37
views
Unable to mock a static method that takes a Supplier as an input
I have a parent class which has a snippet like follows:
var saasManagerApi = RemoteApis.saasSubscriptionApi(saasRegistryServiceUrl, cisLocalBindingToken);
var results = Jsons.parser(RemoteApis.call(...
1
vote
1
answer
127
views
Why does verify(() => mockObject.someGetter) throw 'Used on a non-mockito object' even though the object is a Mock?
I'm currently writing unit tests for a Flutter app using mockito, and I'm running into an issue with verifying a getter call using the latest version of mockito (v5.x).
Here's my test setup:
@...
0
votes
0
answers
101
views
Unable to mock internal method calling third-party API
I have a REST API built with Spring boot, which internally calls a third-party API via a method inside one of my component class. For integration testing, I want to mock this internal method so that ...
1
vote
2
answers
182
views
Simplify mocking dependencies with @InjectMocks
In my Spring Boot app, I have some tests that look like this
@ExtendWith(MockitoExtension.class)
class InviteServiceTests {
@Mock
private UserService userService;
@Mock
private ...
-1
votes
1
answer
109
views
Tests fail only in Jenkins but not locally after change of Mockito library
We have a repository with a mockito library "org.mockito:mockito-inline:4.11.0" defined in build.gradle. I changed it to "org.mockito:mockito-core:5.14.2".
I ran the unit tests ...
0
votes
1
answer
38
views
Is there a way to test CriteriaBuilder.isFalse() from Spring JPA?
I have a method that creates a Specification (Spring JPA) from my custom object to check if its attribute is False with the method. Using Mockito, I tried do the unit test below.
void ...
0
votes
1
answer
56
views
Can't verify that in anonymous inner class method throw exception
Given:
Java 8
Mockito 4.3
Junit 4.11
Here my java code:
public interface ClientListener {
void addClientStatusListener(StatusListener statusListener);
}
@FunctionalInterface
public interface ...
0
votes
0
answers
176
views
How to mock a final class with mockito-core > 5.2.0 and without mockito-inline?
I have been searching the internet for this one for quite sometimes, and I can't find a definite answer. Mockito-inline is now deprecated, so I am trying to run my tests with only mockito-core > 5....
-2
votes
1
answer
255
views
HV000030: No validator could be found for constraint 'jakarta.validation.constraints.NotBlank' [closed]
I have upgraded the Spring version to 3.4.4 and Java to 17.
And updated the javax.validation api to jakartha.validation .
The Mockito testcases are failing with the following errors:
jakarta.servlet....
0
votes
1
answer
54
views
Calling a method on the object returned by CrudRepository save() method
I am trying to write a JUnit test for a relatively basic class that is responsible for persisting an object with a Spring Data CrudRepository, then extracting the generated ID from the object and ...
0
votes
1
answer
92
views
verify with mockito to verify log thrwoing error
I have a very simple aop class
// imports
@Component
@Aspect
@Slf4j
class aopClass {
pubic void log(Joinpoint jp) {
log.info("hi {} and {}", jp.getsignature(), jp....
0
votes
2
answers
75
views
Mockito -> type 'Null' is not a subtype of type 'Future<String>'
I am getting the type 'Null' is not a subtype of type Future<String> error when I try to Unit test with Mockito. I tried all the methods and fixes found in stackoverflow and even in the mockito ...
0
votes
2
answers
47
views
Trying to add stubs in a loop and getting a Mockito exception: Incorrect use of API detected here
I'm using Mockito to creating unit tests for Java however I encountered a weird issue
Say I have an ObjectUnderTest with a mainMethod, and a dependency Dependency mocked, with a method mockedMethod:
...
0
votes
0
answers
114
views
Problem with Mockito and Junit when fulfilling coverage in Jacoco
Good afternoon, I'm testing a microservice with Junit and Mockito in Quarkus (a Java framework). I'm also using Jacobo for Covegare. However, the EventRepositoryImplTest class, which simulates ...
0
votes
1
answer
180
views
Test failing with java.lang.NullPointerException: Cannot invoke "org.springframework.http.ResponseEntity.getBody()" because "response" is null
I have this method:
@Override
public EntityModel<TokenResponse> getToken() throws JsonProcessingException {
UriComponentsBuilder url =
UriComponentsBuilder.fromHttpUrl(oauthUrl);
...
0
votes
0
answers
59
views
Cannot invoke "" because "" is null mockito /quarkus/grpc
Good afternoon, I'm currently developing a microservice with Quarkus and Grpc. I'm implementing Mockito for testing and I get the following error:
[INFO] Running com.tmve.customer.service....
0
votes
0
answers
34
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 ...
0
votes
1
answer
77
views
How to use anyString() inside a Map for Mockito verification?
I'm writing a unit test in a Spring Boot application using Mockito and JUnit 5, and I'm trying to verify a method call where one of the parameters is a Map<String, String>.
Here's the method ...
0
votes
1
answer
78
views
Issue with @SpringBootTest with @KafkaListener and @MockitoSpyBean
My setup is as follow.
I have a Kafka Consumer:
@KafkaListener(topics = "${pmp.kafka.import-catalog-processing.topic}", concurrency = "1", groupId = "${pmp.kafka.group-id}&...
1
vote
1
answer
132
views
How to solve 'Cannot subclass final class java.lang.reflect.Method'?
I have this Junit 5 test code:
@InjectMocks
ReportAssembler reportAssembler;
private ReportingReturnResponse reportingReturnResponse;
private ReturnReport returnReport;
private StaticPathLinkBuilder ...