forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eugenp#8851 from albanoj2/BAEL-3871
BAEL-3871: Added tests for duplicate HTTP controller methods
- Loading branch information
Showing
2 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...-http/src/test/java/com/baeldung/requestmapping/FooMappingExamplesControllerUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.baeldung.requestmapping; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@RunWith(SpringRunner.class) | ||
@WebMvcTest(FooMappingExamplesController.class) | ||
public class FooMappingExamplesControllerUnitTest { | ||
|
||
@Autowired | ||
private MockMvc mvc; | ||
|
||
@Test | ||
public void givenAcceptsJson_whenGetDuplicate_thenJsonResponseReturned() throws Exception { | ||
mvc.perform(get("/ex/foos/duplicate") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("{\"message\":\"Duplicate\"}")); | ||
} | ||
|
||
@Test | ||
public void givenAcceptsXml_whenGetDuplicate_thenXmlResponseReturned() throws Exception { | ||
mvc.perform(get("/ex/foos/duplicate") | ||
.accept(MediaType.APPLICATION_XML)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("<message>Duplicate</message>")); | ||
} | ||
} |