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 CharacterCodeConverterComponentImplTest02 { @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_02/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); 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")); } }