package com.pgf.mqspring.component.impl; import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.test.util.ReflectionTestUtils; import com.pgf.mqspring.component.MqSpringMessageSourceComponent; import com.pgf.mqspring.component.TelegramInfoComponent; class CharacterCodeConverterComponentImplTest07 { @Mock MqSpringMessageSourceComponent messageSource; @InjectMocks CharacterCodeConverterComponentImpl target; @BeforeEach void beforeEacn() throws IOException { MockitoAnnotations.openMocks(this); String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\CharacterCodeConverterComponentImplTest_07\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); TelegramInfoComponent telegramInfoComponent = new TelegramInfoComponentImpl(messageSource, "", ""); ReflectionTestUtils.setField(target, "telegramInfoComponent", telegramInfoComponent); } } @Test void decodeAdsData01() { byte[] emptyBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] attributes = { 0, 0, -52, 0, 0 }; byte[] item01 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "item01", 8, false); byte[] errMsg01 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "errMsg01", 8, false); byte[] adsData = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { emptyBytes, attributes, item01, attributes, errMsg01 }); String[] ret = target.decodeAdsData("UT01", adsData); assertEquals("item01 |errMsg01", ret[0]); assertEquals(ret[1], ret[1]); } @Test void decodeAdsData02() { byte[] emptyBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] attributes = { 0, 0, -52, 0, 0 }; byte[] item01 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "アイテム", 8, true); byte[] errMsg01 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "errMsg01", 8, false); byte[] adsData = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { emptyBytes, attributes, item01, attributes, errMsg01 }); String[] ret = target.decodeAdsData("UT02", adsData); assertEquals("アイテム|errMsg01", ret[0]); } @Test void decodeAdsData03() { byte[] emptyBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] attributes = { 0, 0, -52, 0, 0 }; byte[] item01 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "item01", 8, false); byte[] item02 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "アイテム", 8, true); byte[] errMsg01 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "errMsg01", 8, false); byte[] adsData = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { emptyBytes, attributes, item01, attributes, item02, attributes, errMsg01 }); String[] ret = target.decodeAdsData("UT03", adsData); assertEquals("item01 |アイテム|errMsg01", ret[0]); } }