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 CharacterCodeConverterComponentImplTest02 { @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_02\\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 encodeAdsData01() { byte[] emptyBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] attributes = { 0, 0, -52, 0, 0 }; byte[] item1 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "item01", 8, false); byte[] errMsg1 = { 0 }; byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { emptyBytes, attributes, item1, attributes, errMsg1 }); assertArrayEquals(expected, target.encodeAdsData("UT01", "item01")); } @Test void encodeAdsData02() { byte[] emptyBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] attributes = { 0, 0, -52, 0, 0 }; byte[] item1 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "item01", 8, true); byte[] errMsg1 = { 0 }; byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { emptyBytes, attributes, item1, attributes, errMsg1 }); assertArrayEquals(expected, target.encodeAdsData("UT02", "item01")); } @Test void encodeAdsData03() { byte[] emptyBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] attributes = { 0, 0, -52, 0, 0 }; byte[] item1 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "item01", 8, false); byte[] item2 = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "item02", 8, true); byte[] errMsg1 = { 0 }; byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { emptyBytes, attributes, item1, attributes, item2, attributes, errMsg1 }); assertArrayEquals(expected, target.encodeAdsData("UT03", "item01|item02")); } }