All Questions
637
questions
-1
votes
2
answers
59
views
How to write a unit test with a controller method that has protected code in it [duplicate]
I am trying to write a unit test for the following controller:
@RestController
@RequestMapping(value = ENDPOINT_URL)
public class MainController extends RestControllerBase {
MainService ...
0
votes
1
answer
48
views
How to use class member variables inside Junit-Mockito tests
class MyClass {
MyErrorServiceList myErrorServiceList; // myErrorServiceList is initialized by some complex method calls
public boolean processErrorServiceList() {
if (...
0
votes
0
answers
33
views
I created a test case method named 'testRegisterCustomerSuccess,' but it encountered issues related to JPA queries
I have a method named registerCustomer in a service implementation class. I created a test case named testRegisterCustomerSuccess for this method in a class named UserServiceImplTest, where I mock ...
0
votes
0
answers
32
views
Mock WebClient webflux bean with Qualifier
I have the following scenario:
A config class with two WebClient beans with different names
public class WebClientConfig {
@Bean("bean_1)
public WebClient getWebClient1(WebClient.Builder ...
0
votes
1
answer
71
views
Unable to pass multipart file through mockMvc
I am writing junit test for my request method. Im using mockMvc to trigger the rest request.
When I run my test I get the error
java.lang.NullPointerException: Cannot invoke "org.springframework....
0
votes
0
answers
31
views
Junit for GCS files reading in spring boot
I have an application in spring boot where I am fetching multiple files from GCS and then iterate to read file content. I am able to mock gcs storage but not able to mock the file content. I want to ...
0
votes
2
answers
56
views
Junit local object mock with arguments
I want to use mockito for mocking the constructor call when a specific argument is passed.
Lets say this is my class -
public class MyTestClass {
private final String argument;
public ...
0
votes
1
answer
49
views
How can I make a multiple level of mock object
Here is my example of object
@Service
public class UserSshKeyService {
private final RecordEventService eventService;
private final UserSshKeyRepository repository;
public ...
0
votes
1
answer
81
views
Mockito Test Fails with 'Wanted but not Invoked; Actually, there were zero interactions' Error
I'm facing issues with a unit test in a Spring Boot application where a specific repository method isn't being called as expected during the test of a service method. Despite setting up the test with ...
3
votes
1
answer
34
views
Test Coverage for DB call java code after couchbase 7.2 upgrade
We have recently upgraded Couchbase DB from 6.x to 7.2 . Which introduced collection and scope along with bucket. That means this
GetResult serviceInventoryJsonDocument = this.bucket....
1
vote
0
answers
89
views
How to mock constructors using mockito? [duplicate]
I am testing a method some class which has a new constructor call of BuildingBlockDbHandler.class. I was earlier using powermock to mock constructors like this way -
BuildingBlockDbHandler ...
1
vote
0
answers
42
views
Inject JobLauncherTestUtils without using the @Autowired in unit test and spring batch
I'm new with Spring Batch and I'm trying to create an unit test for my job without using spring Boot and spring Batch annotations, only the mockito, however when i mock the JobLauncherTestUtils my ...
0
votes
2
answers
40
views
Mockito service dependency null pointer exception
So, let me show my problem. I have Service class:
@Service
@Transactional
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final ...
-1
votes
1
answer
34
views
How to mock dependency in service class from Junit
I am trying to write the test cases of one of my service method. I am packing error like cannot invoke
Cannot invoke "com.company.app.models.Product.getId()" because "product" is ...
0
votes
1
answer
47
views
Autowire class's dependencies in jUnit without manual construction
My Service class has several autowired objects (Stored Procedures, SPs). Rather than a MockBean when/then, one test actually requires me to autowire the SP dependency objects in full, to see which ...