package com.pgf.mqspring.component.impl; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.core.io.ClassPathResource; import org.springframework.test.util.ReflectionTestUtils; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.S3Object; import com.pgf.mqspring.component.MqSpringMessageSourceComponent; import com.pgf.mqspring.component.TelegramInfoComponent; class CharacterCodeConverterComponentImplTest07 { @Mock AmazonS3 s3Client; @Mock MqSpringMessageSourceComponent messageSource; @InjectMocks CharacterCodeConverterComponentImpl target; @BeforeEach void beforeEacn() throws IOException { MockitoAnnotations.openMocks(this); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/CharacterCodeConverterComponentImplTest_07/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); 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]); } }