Skip to main content
The 2024 Developer Survey results are live! See the results

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.

0 votes
0 answers
6 views

Spring Boot - Mokito - Argument matchers for exact match - not working

I have a simple spring boot app with controller (example) @RestController @RequestMapping("/person") public class PersonController { @Autowired PersonService personService; @...
Kris Swat's user avatar
  • 910
-1 votes
0 answers
9 views

WebClient static mock is not working the second time is called in a test

I have the next static mock: try (MockedStatic<WebClient> webClientStatic = Mockito.mockStatic(WebClient.class)) { webClientStatic.when(WebClient::builder).thenReturn(...
rasilvap's user avatar
  • 1,989
-1 votes
1 answer
25 views

Mocking a vendor class that is not initialized by my code in Mockito [closed]

I have a very unique challenge with respect to unit testing a scenario. There is a vendor application provided by a jar file. I have to write code on top of it. Internal to vendor application the ...
Jainam MJ's user avatar
  • 318
0 votes
1 answer
23 views

Getting Data from a Jacksonised Object duing unit test

I'm trying to mock out RestServer calls, but It's not generating parseable JSON: A Simple Class like so: @SuperBuilder @Data @Setter @Jacksonized @JsonIgnoreProperties(ignoreUnknown = true) Public ...
gilbo's user avatar
  • 1
-1 votes
2 answers
38 views

Mockito inject some mock objects and some real objects

I'm testing a function like this: public class CsvUtilsTest { @Mock private S3Client s3Client; @Mock private S3BucketWrapper s3Buckets; @Mock CsvMapper csvMapper; @...
Joe C.'s user avatar
  • 440
0 votes
0 answers
40 views

Why are tests running successfully when running as Junit test but when building the pom file, there are test failures and build failure?

I dont have any error and tests run successfully when its run as Junit. But on Building that project's pom, the following error is coming and the build is being failed because of these test failure. ...
DropKick's user avatar
0 votes
0 answers
36 views

Spring Boot STOMP Client: Mock Object Verification Fails

I am developing an API for a real-time multiplayer game and aim to create integration tests for my STOMP API. While using mocks in integration tests is unconventional, I want to verify that the ...
Kenuff's user avatar
  • 1
0 votes
1 answer
37 views

Mockito: mockStatic.when().thenThrow() behavior

I'm writing a test for a method that throws various exception. This test case is to throw SQLException and I noticed these behavior. @Test public void testGetPreparedStatement_throwsSQLException() ...
Sither Tsering's user avatar
0 votes
0 answers
26 views

How to write verify for static methods that have been called [in Mockito Core] [duplicate]

Without using PowerMockito and using Mockito-Core (the version of Mockito doesn't support PowerMockito and I cannot change the Mockito version), How can I verify that a call to a static method has ...
DropKick's user avatar
-1 votes
0 answers
28 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() {...
Hindol Dey's user avatar
1 vote
0 answers
27 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
32 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
31 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
27 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
2 answers
39 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

15 30 50 per page
1
2 3 4 5
924