Skip to content

Commit

Permalink
Merge pull request #432 from csyshu unit#356
Browse files Browse the repository at this point in the history
[#356][manager] unit test case of manager service MailServiceTest.java
  • Loading branch information
haibo-duan authored Nov 11, 2022
2 parents d9ebdda + 03bcb6f commit dd2ab5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline

0 comments on commit dd2ab5d

Please sign in to comment.