generated from 2martens/template-service
Updated directory structure
This commit is contained in:
@ -0,0 +1,37 @@
|
||||
package de.twomartens.oparlservice.control;
|
||||
|
||||
import de.twomartens.oparlservice.service.GreetingService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
|
||||
@WebMvcTest(GreetingController.class)
|
||||
class GreetingControllerTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@MockBean
|
||||
private GreetingService service;
|
||||
|
||||
@Test
|
||||
void testGreetingRest() throws Exception {
|
||||
BDDMockito.given(service.createGreeting("Template"))
|
||||
.willReturn("Hello Template!");
|
||||
|
||||
mvc.perform(MockMvcRequestBuilders.get("/greeting")
|
||||
.param("name", "Template")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(1)))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.message", Matchers.is("Hello Template!")))
|
||||
.andReturn();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package de.twomartens.oparlservice.service;
|
||||
|
||||
import de.twomartens.oparlservice.configs.OParlServiceProperties;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class GreetingServiceTest {
|
||||
|
||||
private GreetingService service;
|
||||
|
||||
@Mock
|
||||
private OParlServiceProperties properties;
|
||||
|
||||
@Mock
|
||||
private OParlServiceProperties.Template template;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
given(template.getGreeting()).willReturn("Hello %s");
|
||||
given(properties.getTemplate()).willReturn(template);
|
||||
service = new GreetingService(new SimpleMeterRegistry(), properties);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGreeting() {
|
||||
String result = service.createGreeting("Test");
|
||||
Assertions.assertThat(result).isEqualTo("Hello Test");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user