### Question:
SlackService { public void updateImage(final byte[] image) throws InterruptedException { checkArgument(ArrayUtils.isNotEmpty(image), "`image` should not be empty."); for (var workspace : slackProperties.getWorkspaces()) { slack.setUserPhoto(workspace.getToken(), image); log.info("Updated Slack user photo. [workspace.id={}]", workspace.getId()); } }  void updateImage(final byte[] image);  }### Answer:
@Test @SneakyThrows public void updateImageTest() { final byte[] imageBytes = {0x00, 0x01, 0x02}; final List<SlackProperties.Workspace> workspaces = List.of( new SlackProperties.Workspace("workspace1", "token1"), new SlackProperties.Workspace("workspace2", "token2"), new SlackProperties.Workspace("workspace3", "token3") ); when(slackProperties.getWorkspaces()).thenReturn(workspaces); doNothing().when(slack).setUserPhoto("token1", imageBytes); doNothing().when(slack).setUserPhoto("token2", imageBytes); doNothing().when(slack).setUserPhoto("token3", imageBytes); slackService.updateImage(imageBytes); verify(slackProperties, times(1)).getWorkspaces(); verify(slack, times(1)).setUserPhoto("token1", imageBytes); verify(slack, times(1)).setUserPhoto("token2", imageBytes); verify(slack, times(1)).setUserPhoto("token3", imageBytes); verify(slack, times(3)).setUserPhoto(anyString(), any()); }
@Test @SneakyThrows public void updateImageNullImageTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("`image` should not be empty."); when(slackProperties.getWorkspaces()).thenReturn(Collections.emptyList()); doNothing().when(slack).setUserPhoto(anyString(), any()); slackService.updateImage(null); verify(slackProperties, never()).getWorkspaces(); verify(slack, never()).setUserPhoto(anyString(), any()); }
@Test @SneakyThrows public void updateImageEmptyImageTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("`image` should not be empty."); when(slackProperties.getWorkspaces()).thenReturn(Collections.emptyList()); doNothing().when(slack).setUserPhoto(anyString(), any()); slackService.updateImage(new byte[]{}); verify(slackProperties, never()).getWorkspaces(); verify(slack, never()).setUserPhoto(anyString(), any()); }