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

All Questions

Tagged with
0 votes
0 answers
9 views

JUnit test failing Status expected:<201> but was:<404>

I've spent a lot of time trying to figure out this issue, but when I'm running my tests on my UserControllerTest class I'm getting Status expected:<201> but was:<404>. Here's my ...
dom's user avatar
  • 28
1 vote
1 answer
36 views

I cant init my webclient in a test with mockito

I'm working on a project with java spring boot 2.x and java 1.8. In my pom i got the dependencies of junit 4.13.2 and mockito 3.12.4. When i try to run my test i got the problem that my setup function ...
Juan Federico Di Leo's user avatar
0 votes
0 answers
40 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
42 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
  • 925
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
1 vote
0 answers
77 views

Face an issue about HttpStatusCode when I upgrade spring 3.1

guys I face a strange issue when I upgrade the sping 2.65 to 3.1.0. This is the code: import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus.OK import org....
tao wei's user avatar
  • 11
0 votes
1 answer
64 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
1 answer
222 views

How to do an OR condition on result, when using Spring MockMVC?

Currently I have below - .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("$.message", org.hamcrest.Matchers.equalTo("...
CodeBot's user avatar
  • 115
1 vote
1 answer
1k views

How to simulate the downloading of a file during java unit testing?

I can't figure out how to simulate downloading from a file path in spring with Map<Long, String> I've implemented this method: @Test void testDownloadFile() throws Exception { ...
Siva's user avatar
  • 31
0 votes
0 answers
34 views

how to mock RestTemplate to mock it's methods

I'm trying write unit tests for the class which has a restTemplate.getForObject( Url, Response.class); I've mocked the RestTemplate in the test class still when I run test case, request hit's server ...
Deepak Mandlik's user avatar
1 vote
1 answer
289 views

Bean serialization issue while running test case

when hit the endpoint from the browser it is working fine but test case failing. please find the code below: Controller class: @RestController public class EmployeeController { @Autowired ...
ts009's user avatar
  • 13
0 votes
0 answers
186 views

Upgrading spring application from 4.3.2.RELEASE to 5.2.20.RELEASE

I'm upgrading my spring multi module project from 4.3.2.RELEASE to 5.2.20.RELEASE. After changing version in the dependency application works fine. but when I ran the application with test throwing an ...
Manohar Nr's user avatar
0 votes
0 answers
137 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
1 vote
1 answer
398 views

How to write unit test for Spring Boot Controller if it required user name which was got from Security Context Holder?

I want to write a unit to allow users to change their personal Information. However, I don't know how to include the Security Context Holder mock into Unit Test. Especially, it is required to extract ...
Monach's user avatar
  • 43
0 votes
1 answer
217 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
  • 85.1k

15 30 50 per page
1
2 3 4 5
36