diff --git a/manager/src/test/java/com/usthe/manager/service/MailServiceTest.java b/manager/src/test/java/com/usthe/manager/service/MailServiceTest.java index 85247453fd7..e6fd856c9d6 100644 --- a/manager/src/test/java/com/usthe/manager/service/MailServiceTest.java +++ b/manager/src/test/java/com/usthe/manager/service/MailServiceTest.java @@ -1,21 +1,56 @@ package com.usthe.manager.service; -import com.usthe.manager.controller.NoticeConfigController; +import com.usthe.alert.AlerterProperties; +import com.usthe.common.entity.alerter.Alert; +import com.usthe.manager.service.impl.MailServiceImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; -import static org.junit.jupiter.api.Assertions.*; +import java.util.ResourceBundle; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; /** * Test case for {@link MailService} */ +@ExtendWith(MockitoExtension.class) class MailServiceTest { + @Spy + @InjectMocks + private MailServiceImpl mailService; + + @Mock + private TemplateEngine templateEngine; + + @Mock + private AlerterProperties alerterProperties; + + @Mock + private ResourceBundle bundle; + + @Mock + private Alert alert; + @BeforeEach void setUp() { + lenient().when(templateEngine.process(eq("mailAlarm"), any(Context.class))).thenReturn("result"); } @Test void buildAlertHtmlTemplate() { + assertEquals("result", mailService.buildAlertHtmlTemplate(alert)); + assertNotNull(mailService.buildAlertHtmlTemplate(alert)); } } \ No newline at end of file diff --git a/manager/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/manager/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 00000000000..ca6ee9cea8e --- /dev/null +++ b/manager/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file