13,916 questions
1
vote
0
answers
41
views
Spring test - how to access a mockbean that was configured in a seperate file?
The test file is:
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = BeanTestConfig.class)
class TestWithSeparateBeanConfig {
@MockBean
BeanOne beanOne;
@Autowired
...
1
vote
1
answer
403
views
I don't know how to mock Riverpod's Provider with mockito
I am writing a test in Flutter using mockito, I want to mock Riverpod's Provider, but I get an error and can't solve it.
The various versions are as follows
# pubspec.yaml
environment:
sdk: ^3.5.2
...
0
votes
1
answer
49
views
Stubbing properly with postForEntity (returning ResponseEntity<DTO>) using Mockito
I am currently facing an odd behavior during my test,
The goal was to test the following registration method :
@RestController
@RequiredArgsConstructor
public class RegisterController {
...
...
0
votes
0
answers
141
views
Can't get Mockito 5 Inject to work with Junit 4 after upgrade from Mockito 4
I have the following
@RequestMapping
public interface ExcludesOverriddenController {
@RequestMapping(value = "excludes/overridden", method = RequestMethod.GET)
@ResponseStatus(value = ...
1
vote
0
answers
262
views
Static mocking is already registered - even with try-with-resources
I have an utility class ConverterUtil with a method convertJsonToFileBytes and two test classes(WorkflowExportServiceTest,WorkflowExportControllerTest). If I run the test classes individually ...
0
votes
1
answer
46
views
Testing disposal of custom dialog
I am testing disposal of a JDialog extension. However, even though I am certain the dialog has no error in that regard, I can't yet get my test to pass. It seems dispose() is invoked, but not on my ...
0
votes
0
answers
48
views
Mockito Test Method Transport.send inside completable future
So I'm struggling with writing a mockito test method for a method having this piece of code
Future<?> future = executor.submit(() -> {
try {
...
-1
votes
1
answer
46
views
Mockito mock not invoked
I have some java base class that has inside 1 method:
public class SB {
@SneakyThrows
public Document downloadHtml(String url) {
return Jsoup.connect(url)
.userAgent(&...
0
votes
1
answer
191
views
Mock new Date or System.currentTimeMillis
I am setting up tests using Groovy and the Spock framework. My tests depend on the passage of time, and the services in question use new Date() for some rules. Because of this, I would like to modify ...
0
votes
0
answers
121
views
Rewrite JMockit Mockup to Mockito: Interception of method calls of dependency api
Rewrite JMockit Mockup to Mockito: Interception of method calls of dependency api
I try to rewrite JMockit code (new Mockup) to Mockito.
In my JUnit test a method (initializeEntityManagerInterception) ...
0
votes
2
answers
727
views
Duplicate mock definition error when using @MockBean to override bean in multiple Spring Boot test classes
I have multiple Spring Boot tests where I need to override a bean that is loaded in the test context using the @SpringBootTest annotation. In one of my test classes, I successfully used the @MockBean ...
-1
votes
1
answer
76
views
Unit test for Lambda expression
I am trying to write a unit test (using Mockito) for my Spring Security config class and it has this code
@Bean
public GrantedAuthoritiesMapper authoritiesMapper() {
return (authorities) -> {
...
-1
votes
1
answer
55
views
How do you mock a static method (not void) to have different behavior on two different invocations?
I need to mock a static method, so that it throws an exception the first time it is called, and returns some value, the second time it is called. I know how to mock it so that it throws an exception ...
0
votes
1
answer
56
views
Maven run test error for all classes but working fine for a class
I have a test class which I want to test for JPA query.
@SpringBootTest
@DirtiesContext
class JPAUnitTest {
@Autowired
private OrganizationRepository organizationRepository;
@Autowired
...
0
votes
3
answers
117
views
InvalidUseOfMatchersException when stubbing
I'm getting mockito exception when doing the stubbing:
@Mock
RetryTemplate retryTemplate;
@Test
public void testSubmitCreditTransaction() {
when(retryTemplate.execute(any())).thenAnswer(...
0
votes
1
answer
148
views
@MockBean Not Injecting Dependencies Correctly in Spring Boot Unit Test
I am working on a unit test for a Spring Boot application. I have a MetricsLogger DI that work fine in the service code, but failed to pass the unit test as it's null in the test. Despite using @...
0
votes
1
answer
649
views
After Spring upgrade 3.0.2->3.3.2, Mockito's Mockito.any(Object.class) not mocking Object... (varargs) argument
We have code that executes RestTemplate.exchange() to execute an HTTP request, and a Unit Test that tests it. The expected params (5) are
@Override
public <T> ResponseEntity<T> exchange(...
0
votes
1
answer
61
views
Spring Boot - Mockito - 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;
@...
-1
votes
2
answers
272
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;
@...
0
votes
1
answer
342
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() ...
1
vote
2
answers
88
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
2
answers
66
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
50
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);
...
0
votes
1
answer
267
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
votes
1
answer
53
views
Intermittent null return in Mockito unit tests for Spring service methods
I am encountering an intermittent issue with my unit tests for a Spring service where the method under test occasionally returns null. This issue is random and affects different methods during the act ...