From 7ae9f5f80a17ba5af6657d00633f00f58085a773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=9E=E7=AD=B1?= <105542329+a-little-fool@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:21:03 +0800 Subject: [PATCH] Alert tests fix (#1501) Signed-off-by: tomsun28 Co-authored-by: yqxxgh <1135131038@qq.com> Co-authored-by: yqxxgh <42080876+yqxxgh@users.noreply.github.com> Co-authored-by: tomsun28 --- .../alert/service/AlertDefineServiceTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/alerter/src/test/java/org/dromara/hertzbeat/alert/service/AlertDefineServiceTest.java b/alerter/src/test/java/org/dromara/hertzbeat/alert/service/AlertDefineServiceTest.java index 62fe088d482..82b66a8d863 100644 --- a/alerter/src/test/java/org/dromara/hertzbeat/alert/service/AlertDefineServiceTest.java +++ b/alerter/src/test/java/org/dromara/hertzbeat/alert/service/AlertDefineServiceTest.java @@ -13,12 +13,12 @@ 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.*; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; +import org.springframework.test.util.ReflectionTestUtils; import javax.persistence.criteria.CriteriaBuilder; import java.util.*; @@ -42,11 +42,17 @@ class AlertDefineServiceTest { @Mock private AlertDefineBindDao alertDefineBindDao; + @Mock + private List alertDefineImExportServiceList; + @InjectMocks private AlertDefineServiceImpl alertDefineService = new AlertDefineServiceImpl(Collections.emptyList()); @BeforeEach void setUp() { + ReflectionTestUtils.setField(this.alertDefineService, "alertDefineDao", alertDefineDao); + ReflectionTestUtils.setField(this.alertDefineService, "alertDefineBindDao", alertDefineBindDao); + this.alertDefine = AlertDefine.builder() .id(1L) .app("app") @@ -162,7 +168,7 @@ void getAlertDefines() { @Test void getBindAlertDefineMonitors() { - Long id = 1L; + long id = 1L; when(alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(id)).thenReturn(alertDefineMonitorBinds); assertDoesNotThrow(() -> alertDefineService.getBindAlertDefineMonitors(id)); }