Created
March 3, 2020 18:07
-
-
Save danvega/85620769586a5ced3894cd22e7acf668 to your computer and use it in GitHub Desktop.
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
package dev.danvega.quickstart.controller; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.extension.ExtendWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | |
import org.springframework.test.context.junit.jupiter.SpringExtension; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.MvcResult; | |
import org.springframework.test.web.servlet.RequestBuilder; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
@ExtendWith(SpringExtension.class) | |
@WebMvcTest(HelloController.class) | |
public class HelloControllerIntTest { | |
@Autowired | |
private MockMvc mvc; | |
@Test | |
public void testHelloEndpointWithDefaultName() throws Exception { | |
RequestBuilder request = get("/hello"); | |
MvcResult result = mvc.perform(request).andReturn(); | |
assertEquals("Hello, World", result.getResponse().getContentAsString()); | |
} | |
@Test | |
public void testHelloWithName() throws Exception { | |
mvc.perform(get("/hello?name=Dan")) | |
.andExpect(status().isOk()) | |
.andExpect(content().string("Hello, Dan")) | |
.andReturn(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment