Skip to main content

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.

1 vote
0 answers
3 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....
lewap02's user avatar
  • 11
1 vote
2 answers
17 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 ...
javacomelava's user avatar
0 votes
1 answer
24 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 ...
Stormy's user avatar
  • 1
-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 ...
Jyoti's user avatar
  • 1
0 votes
1 answer
32 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: ══╡ ...
pekran123 pekranian's user avatar
0 votes
0 answers
13 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 ...
JamieRhys's user avatar
  • 306
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(...
AntonBoarf's user avatar
  • 1,273
0 votes
0 answers
38 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); ...
DropKick's user avatar
-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 ...
Waqas Haider's user avatar
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 ...
frlzjosh's user avatar
  • 448
-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 ...
Nadin Martini's user avatar
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 ...
Kaliyug Antagonist's user avatar
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 ...
Alexander's user avatar
  • 803
-2 votes
0 answers
39 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....
Ulises 2010's user avatar
1 vote
1 answer
32 views

I cant init my webclient in a test with mockito

I'm working on a project with java spring boot 2.x and java 1.8. In my pom i got the dependencies of junit 4.13.2 and mockito 3.12.4. When i try to run my test i got the problem that my setup function ...
Juan Federico Di Leo's user avatar

15 30 50 per page
1
2 3 4 5
924