Questions tagged [mockito]
Mockito is a mocking framework for Java. It is inspired by EasyMock but aims to simplify mock stubbing, verification and tooling even further.
mockito
13,850
questions
-1
votes
0
answers
18
views
Nested Mockito tests failing after version update
I have a test that worked fine till Spring Boot 2.7. The test goes like this.
@MockitoSettings
abstract CommonStepTest {
@Mock private CommonDependency commonDependency;
@BeforeEach
void setUp() {...
1
vote
0
answers
4
views
JerseyTest and Mockito - problem with mocking an object
My aim is to learn a little bit about mocking objects in the context of Jersey Test.
I have 3 classes:
ServiceController
package com.vogella.jersey.first;
import javax.ws.rs.*;
import javax.ws.rs.ext....
1
vote
2
answers
23
views
TDD, Unit Test and mocks injection: What about the Single Responsability principle?
I'm writing a Unit Test for a Class (CustomHttpClient) that internally uses a library (java.net.http.HttpClient) to make an external HTTP call.
Being it a Unit Test, I would mock the internal ...
0
votes
1
answer
26
views
Using MockBean to mock SessionFactory
I have a DAO impl class that I'm trying to write a unit test for using testng. My class has a SessionFactory autowired into it which is why I'm using the MockBean annotation in my test class. In my ...
-4
votes
0
answers
23
views
@Mock is not working after migrated to java 17 [closed]
We was having code with java 11 and powermickito. We have migrated it to java 17. SO @Mock is giving null everywhere.
I need to use Mockito instead of powermockito. We are using internal framework for ...
0
votes
2
answers
36
views
Title: TypeError in Flutter Test: Null is not a subtype of Future<String>
I'm writing a Flutter test where I'm trying to mock a method that calculates the BMI. Despite using when(...).thenReturn(...) to return a future value, I'm encountering the following error:
══╡ ...
0
votes
0
answers
14
views
Mockito not able to mock Room Dao Class?
I have the following code to try and test my AppRepository class:
@RunWith(AndroidJUnit4::class)
@MediumTest
class AppRepositoryTest {
@Mock private lateinit var counterDao: CounterDao
@Mock ...
0
votes
1
answer
32
views
Mockito and Spring RestTemplate issue
I want to test this class :
public class TokenIntrospector {
private RestTemplate restTemplate;
private String userInfoUri = "http://localhost";
public TokenIntrospector(...
0
votes
0
answers
39
views
How to write test cases where the mocked objects are not giving anything back
How to write assert or verify for these. I cannot change the code in any way. Only Junit can be written by me.
public void Calculator(booker, product) {
Matcher matcher = buildCriteria(product);
...
-1
votes
0
answers
49
views
Unit test for a method that does a map lookup [closed]
I am new to Kotlin and I am writing unit test for a method that tries to load a value from a map defined at class level (kind of like a local cache) and returns if the value is found otherwise a ...
0
votes
1
answer
81
views
Struggling to inject my mocked Runnable into my service call
For context, I'm using Resilience4j to handle exceptions and invoke retries. This is done through RetryService.
In this function, callRunnableWithRetry() there are two params. 1st is a string, the 2nd ...
-1
votes
0
answers
38
views
doAnswer Mockito: Behaving strange and not verifying the mocked listener [closed]
I am trying to test the API call method, since this API is final I can not extend and create Test Doubles, so I have used Mockito to stub the functionality after initializing this API, I created Test ...
0
votes
1
answer
39
views
Stubbing error while mocking WebClient using Mockito
Based on answers to previous questions like these, I am trying to mock WebClient in a unit test. Please note that I don't wish to use WireMock or MockWebserver.
source method:
public class ...
1
vote
0
answers
26
views
Is there any out-of-the-box solution to make Mockito Capture keep parameter values, not references [closed]
This issue is about Mockito mock call capturing multiple arguments in a succession. Consider following code:
public void performService(ServiceRequest request) {
ServiceTask serviceTask = new ...
-2
votes
0
answers
40
views
1 matchers expected, 2 recorded: [closed]
I have a test with this line:
when(interlocutorsP2PService.creationIsAllowed(any(BigInteger.class), any(BigInteger.class))).thenReturn(true);
And I recibe this error
org.mockito.exceptions.misusing....