Skip to main content

All 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 ...
aCarella's user avatar
  • 2,474
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....
akshat rathore's user avatar
0 votes
0 answers
43 views

The application.properties values are not read in java tests

I have the following service, where I use the properties of my application.properties file: @Service public class TesoSunSystemsServiceImpl implements TesoSunSystemsService { @Value(&...
BRUNO's user avatar
  • 23
1 vote
2 answers
122 views

How to enable DEBUG level for unit tests in Springboot 3.1.10?

I need to enable debug mode globally, so output from the application classes is logged in both application and unit tests. I enabled DEBUG mode in src\main\resources\application.properties and it ...
tim bits's user avatar
0 votes
0 answers
40 views

Actual response is returning null in unit test using JUnit 4.12

So, i'm trying to create a unit test since its my first time doing this and here is the code: package com.convergeict.shoppingcartservice.controller; import com.convergeict.shoppingcartservice.model....
drealmikaelson's user avatar
0 votes
1 answer
54 views

Nested mapping only for test create NullPointerException Junit 5

Class by class I explain why it doesn't start, thanks for your help In debug i see the list of employees until the method for-each java.lang.NullPointerException: Cannot invoke "com.fincons....
Lorenzo Gaetani's user avatar
0 votes
0 answers
23 views

Does @DataJpaTest configures correctly "updatable = false" in tests when using H2 database?

I'm asking this because even using the @Column notation over the attribute with the value "updatable = false", it still passing in the test I update it. @Column(length = 100, nullable = ...
Bicho Papão's user avatar
-1 votes
1 answer
136 views

Test case for my controller in the spring boot reactive web application gives errors

package com.example.demo4.controller; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test....
chan's user avatar
  • 3
1 vote
1 answer
48 views

UnitTest final UUID changes within the test if @BeforeEach#repository.save() is executed

I have an OrderRepositoryTest code below where I am trying to get the valid order by Uuid OrderRepositoryTest @DataJpaTest @ExtendWith(SpringExtension.class) @AutoConfigureTestDatabase(connection = ...
Mr. Kenneth's user avatar
  • 1,186
0 votes
0 answers
43 views

Repository is not autowired, it is null

I have upgraded the spring boot version to 2.7.8. After that when I try to build my project I'm getting errors in unit tests. Repository is not getting autowired. It is null. because of that I'm ...
Tharindu Rangana's user avatar
0 votes
0 answers
31 views

How to mock TopicManagementResposne in my test class

I am creating a topic from the server itself (Using Firebase cloud messaging), and it is working fine. Now when I try to unit test this class, I get a null pointer exception stating that the object of ...
Faiz's user avatar
  • 3
0 votes
0 answers
54 views

Is this the right way to unit test using JUnit and mockito?

Is this the correct way to do a unit test my controller class? Since my method to check if a given param is null or not is in my service class and I cannot call my service call from the controller in ...
Faiz's user avatar
  • 3
0 votes
0 answers
39 views

SpringBoot Repository Test Authenticate Error

I implemented Authentication system to my Product backend side. It has been working since I had built it. Then I added Refresh token and Role system to project and they also worked perfectly but When ...
Hakan's user avatar
  • 23
0 votes
0 answers
49 views

Principal Cast to JwtAuthenticationToken (cas Exception)

I have a Spring Boot controller class where one of the methods, establishConnection, takes a Principal as a parameter. Inside this method, I'm trying to access some JWT claims from the principal using ...
Mohamméd Mazroui's user avatar
0 votes
3 answers
2k views

Java Unit Testing - Make return value of a method called by enclosing method to Empty

I have this method and implementation is done. However, when I look at Jacoco report, it says that the else {} and catch() part is not being covered by Unit Test Code Coverage. public class ...
heisenberg's user avatar
  • 1,924

15 30 50 per page
1
2 3 4 5
20