From 6632f03689996b364486647c70db07c077c99a3a Mon Sep 17 00:00:00 2001 From: Dominika Zemanovicova <xzemanov@fi.muni.cz> Date: Sun, 26 Mar 2023 21:10:31 +0200 Subject: [PATCH] Send mail mock --- .../fuseri/modulemail/service/MailControllerTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application/module-mail/src/test/java/org/fuseri/modulemail/service/MailControllerTest.java b/application/module-mail/src/test/java/org/fuseri/modulemail/service/MailControllerTest.java index 4105485f..8ec50ec9 100644 --- a/application/module-mail/src/test/java/org/fuseri/modulemail/service/MailControllerTest.java +++ b/application/module-mail/src/test/java/org/fuseri/modulemail/service/MailControllerTest.java @@ -7,10 +7,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -35,10 +36,12 @@ class MailControllerTest { @Test void sendMail() throws Exception { - // TODO use mocks + var mailDto = new MailDto("user@example.com", "Hello"); + MailController mailController = mock(MailController.class); + when(mailController.sendMail(mailDto)).thenReturn("Success, you have sent: " + mailDto.getContent()); mockMvc.perform(post("/mail") - .content(asJsonString(new MailDto("12marting02@gmail.com", "Hello"))) + .content(asJsonString(mailDto)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } -- GitLab