Skip to main content

All Questions

0 votes
0 answers
38 views

Spring Boot test: Why is my response body empty when testing a POST request?

I'm trying to test a POST endpoint in my Spring Boot application that creates a ChallengeReport. However, the response body is always empty, even though the status code is correct. I need help ...
Adrian Krafft's user avatar
0 votes
1 answer
39 views

Getting java.lang.NoClassDefFoundError Exception while using MockMvcBuilders.standaloneSetup() method in Junit 5

Below is my Test class that I have created for Controller class. My Testclass is in package src/test/java and my java classes are in folder src/main/java. public class MyControllerTest { @...
Nidhi257's user avatar
  • 919
0 votes
2 answers
36 views

MockMultipartFile is not included in MockHttpServletRequest

I wanna test what happens when the oversized image file is sent to spring boot server using MockMultipartFile. @SpringBootTest @AutoConfigureMockMvc class PostControllerTest { @Autowired ...
new mankind's user avatar
0 votes
1 answer
63 views

Mock testing a post method which returns the location of the newly added entity and a 201 status code, using ServletUriComponentsBuilder

@PostMapping(path= "/users/{username}/events") public ResponseEntity<Object> createEventsForUser(@PathVariable String username, @RequestBody @Valid EventBean event){ event....
Prathamesh Zingade's user avatar
0 votes
0 answers
136 views

ObjectMapper with and without mock

I have a controller ItemController.java in which I'm using objectmapper in logger.info objectMapper.writeValueAsString("something"); In the controller unit test, I need to use the object ...
Prajwala P's user avatar
0 votes
1 answer
214 views

How to assert FlashAttributes in Spring WebTestClient?

I want to test FlashMap assignment of a spring @Controller: @Controller public class MyServlet { @GetMapping("/test") public String get() { ServletRequestAttributes ...
membersound's user avatar
-1 votes
1 answer
2k views

A required bean can not be found during tests / No bean named 'entityManagerFactory' available

I am developing a small app just to try Spring boot on my own. It has five different modules (eclipse projects): model--contains entity classes, DTO's and mappers to switch between them data--...
Xorlita's user avatar
-1 votes
1 answer
547 views

java.lang.AssertionError: No value at JSON path "$.data.count" Caused by: java.lang.IllegalArgumentException: json can not be null or empty

Exception java.lang.AssertionError: No value at JSON path "$.data.count" at org.springframework.test.util.JsonPathExpectationsHelper.evaluateJsonPath(JsonPathExpectationsHelper.java:...
Saurabh Dhage's user avatar
0 votes
1 answer
3k views

JUnit - java.lang.NullPointerException: Cannot invoke "..." because "this.modelMapper" is null

I've been learning Java for about 4 months, so please excuse basic mistakes. I'm trying to unit test a method from my Service layer: @Override @Transactional public List<StudentDto> ...
Filippo's user avatar
  • 21
0 votes
1 answer
408 views

mocking resttemplate exchange method returning null

I am trying to write the Junit test case for exchange method but it its returning null, can anybody tell me what is mistake I am doing here My Actual Code is HttpEntity httpEntity = ...
java_tech's user avatar
0 votes
1 answer
319 views

Setting up data for Mockito

I am unit testing my spring Rest API and I have had joy mocking my create and retrieve methods using the following structure. @Test public void getAllUsersReturnsAListOfAllTheUsersInJSONFormat(...
RushTheFox's user avatar
1 vote
1 answer
3k views

Why does Mockito return null when I specify an Optional of my type

I have a method on a controller to get a list of all the punishment types for a chat room (Kick, Ban, Warn and Mute). On the first test when I mock the data it works as expected and the test passes. ...
RushTheFox's user avatar
0 votes
0 answers
30 views

Error while running Mockito Spring test class

Hi this is my Test class @RunWith(SpringRunner.class) @WebAppConfiguration @SpringBootTest(classes = com.example.Application.class) @ActiveProfiles(profiles = "localtest") @...
Sandhya's user avatar
  • 11
3 votes
3 answers
4k views

Spring not autowiring when run from JUnit

I am testing ControllerAdvice class where i have EncodeUtil is autowired, this is always resolved as Null when I run using JUnit test, no issue when run via spring boot application, what am i missing ...
softechie's user avatar
  • 133
0 votes
1 answer
1k views

Why does @WebMvcTest not load Controller-Advices into the Application-Context?

Helloin my parameterized junit5-test i get a NestedServletException until i add the @ContextConfiguration-Annotation above my test class in which i reference my custom exception handler that is ...
Nico S.'s user avatar
  • 97

15 30 50 per page
1
2 3 4 5 6