ExternalPayloadStorageUtils { @VisibleForTesting String uploadHelper(byte[] payloadBytes, long payloadSize, ExternalPayloadStorage.PayloadType payloadType) { ExternalStorageLocation location = externalPayloadStorage.getLocation(ExternalPayloadStorage.Operation.WRITE, payloadType, ""); externalPayloadStorage.upload(location.getPath(), new ByteArrayInputStream(payloadBytes), payloadSize); return location.getPath(); } @Inject  ExternalPayloadStorageUtils(ExternalPayloadStorage externalPayloadStorage,
                                       Configuration configuration,
                                       ObjectMapper objectMapper); @SuppressWarnings("unchecked") Map<String, Object> downloadPayload(String path); void verifyAndUpload(T entity, PayloadType payloadType);  }
@Test public void testUploadHelper() { AtomicInteger uploadCount = new AtomicInteger(0); String path = "some/test/path.json"; ExternalStorageLocation location = new ExternalStorageLocation(); location.setPath(path); when(externalPayloadStorage.getLocation(any(), any(), any())).thenReturn(location); doAnswer(invocation -> { uploadCount.incrementAndGet(); return null; }).when(externalPayloadStorage).upload(anyString(), any(), anyLong()); assertEquals(path, externalPayloadStorageUtils.uploadHelper(new byte[]{}, 10L, ExternalPayloadStorage.PayloadType.TASK_OUTPUT)); assertEquals(1, uploadCount.get()); }