### Question:
AzurePhotoFetcher { String getPhotoForUserId(String auth, UUID userId) throws AzureUserFetchException { try { URL url = new URL("https: InputStream inputStream = azureApiCaller.callApi(auth, url); BufferedImage photo = getPhotoAsImage(inputStream); photo = resizeImage(photo, 240, 240); return convertImageToBase64(photo); } catch (IOException e) { throw new AzureUserFetchException(e.getMessage()); } catch (IllegalStateException e) { return null; } } @Autowired  AzurePhotoFetcher(AzureApiCaller azureApiCaller);   }### Answer:
@Test public void getPhotoForUserId_shouldResizeAndConvertImageCorrectly() throws IOException, AzureUserFetchException { when(azureApiCaller.callApi(anyString(), any())) .thenReturn(new ByteArrayInputStream(Base64.getDecoder().decode(src))); String photoForUserId = azurePhotoFetcher.getPhotoForUserId(anyString(), stubForUuid()); BufferedImage actualImage = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(photoForUserId))); assertEquals(actualImage.getWidth(), 240); assertEquals(actualImage.getHeight(), 240); }
@Test public void getPhotoForUserId_shouldReturnNullForEmptyResponse() throws IOException, AzureUserFetchException { when(azureApiCaller.callApi(anyString(), any())).thenThrow(IllegalStateException.class); String photoForUserId = azurePhotoFetcher.getPhotoForUserId(anyString(), stubForUuid()); assertNull(photoForUserId); }