-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #432 from csyshu unit#356
[#356][manager] unit test case of manager service MailServiceTest.java
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 37 additions & 2 deletions
39
manager/src/test/java/com/usthe/manager/service/MailServiceTest.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 |
---|---|---|
@@ -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)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
manager/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
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 @@ | ||
mock-maker-inline |