### Question:
ImageService { public String preProcessAndEncodeInString64(byte[] bytes) throws ImageProcessException { Validate.notNull(bytes, "Incoming byte array cannot be null"); BufferedImage image = imageConverter.convertByteArrayToImage(bytes); if (image == null) { throw new ImageProcessException(); } byte[] outputImage = imageConverter.preprocessImage(image); return base64Wrapper.encodeB64Bytes(outputImage); } ImageService(
            ImageConverter imageConverter,
            Base64Wrapper base64Wrapper,
            String defaultImagePath,
            JCommuneProperty imageSizeProperty); byte[] getDefaultImage(); String preProcessAndEncodeInString64(byte[] bytes); void validateImageFormat(MultipartFile file); void validateImageFormat(byte[] bytes); void validateImageSize(byte[] bytes); String getHtmlSrcImagePrefix(); static final String ICO_TYPE; }### Answer:
@Test(dataProvider = "validImageBytesValues") public void convertBytesToBase64StringShouldNormalConvertAvatar( byte[] originalImageBytes, BufferedImage inputImage, byte[] processedImageBytes, String expectedBase64String) throws ImageProcessException { when(imageConverter.convertByteArrayToImage(originalImageBytes)).thenReturn(inputImage); when(imageConverter.preprocessImage(inputImage)).thenReturn(processedImageBytes); when(base64Wrapper.encodeB64Bytes(processedImageBytes)).thenReturn(expectedBase64String); String resultBase64String = imageService.preProcessAndEncodeInString64(originalImageBytes); verify(imageConverter).convertByteArrayToImage(originalImageBytes); verify(imageConverter).preprocessImage(inputImage); verify(base64Wrapper).encodeB64Bytes(processedImageBytes); assertEquals(resultBase64String, expectedBase64String); }
@Test(expectedExceptions = ImageProcessException.class) public void convertBytesToBase64StringShouldNotContinueWhenPassedImageByteArrayIsIncorrect() throws ImageProcessException { byte[] imageBytes = {8, 2}; when(imageConverter.convertByteArrayToImage(imageBytes)).thenReturn(null); imageService.preProcessAndEncodeInString64(imageBytes); verify(imageConverter).convertByteArrayToImage(imageBytes); }
@Test(expectedExceptions = {IllegalArgumentException.class}) public void convertBytesToBase64StringShouldNotWorkWithPassedNull() throws ImageProcessException { imageService.preProcessAndEncodeInString64(null); }