package com.pgf.mqspring.service.impl; import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; 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.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.ReflectionTestUtils; import com.pgf.mqspring.component.MqSpringMessageSourceComponent; import com.pgf.mqspring.component.TelegramInfoComponent; import com.pgf.mqspring.constant.MqSpringMessageId; import com.pgf.mqspring.exception.MqSpringException; import com.pgf.mqspring.model.TelegramInfoModel; @ExtendWith(SpringExtension.class) class MqSendServiceImplTest02 { @Mock TelegramInfoComponent telegramInfoComponent; @Mock MqSpringMessageSourceComponent messageSource; @InjectMocks MqSendServiceImpl mqSendService; @BeforeEach public void beforeEacn() { MockitoAnnotations.openMocks(this); Map> telegramInfoMap = new HashMap<>(); List telInfoByDispCodeList = new ArrayList(); TelegramInfoModel model = new TelegramInfoModel(); model.setDispCode("GE02"); model.setFieldNo("1"); model.setItemName("MENUID"); model.setItemLength("8"); model.setCharDiv("0"); model.setRepeatNum("0"); model.setGroupNum("0"); model.setInsDate("2003-11-13"); telInfoByDispCodeList.add(model); telegramInfoMap.put("GE02", telInfoByDispCodeList); Mockito.when(telegramInfoComponent.getTelegramInfoMap()).thenReturn(telegramInfoMap); } @Test void checkDisplayCode01() { ReflectionTestUtils.invokeMethod(mqSendService, "checkDisplayCode", "GE02"); assertTrue(true); } @Test void checkDisplayCode02() { Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("画面コード未入力エラー。"); try { ReflectionTestUtils.invokeMethod(mqSendService, "checkDisplayCode", ""); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7027E, e.getMessageId()); } } @Test void checkDisplayCode03() { Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("電文定義マスタファイルがありません。"); try { ReflectionTestUtils.invokeMethod(mqSendService, "checkDisplayCode", "Test"); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7063E, e.getMessageId()); } } @Test void checkDisplayCode04() { Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("画面コード未入力エラー。"); try { ReflectionTestUtils.invokeMethod(mqSendService, "checkDisplayCode", (Object)null); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7027E, e.getMessageId()); } } }