### Question:
Uploader { void execute(UploadRequest uploadRequest) throws IOException, InterruptedException { String sourceId = uploadRequest.sourceId; contentUploadService.startAsync().awaitRunning(); for (UploadRequest.AbstractRequest request : uploadRequest.requests) { GenericJson response = request.accept(getVisitor(sourceId)); System.out.println(response.toPrettyString()); } contentUploadService.stopAsync().awaitTerminated(); } Uploader(Builder builder); static void main(String[] args);  }### Answer:
@Test public void testUpdateSchemaEmpty() throws Exception { Uploader uploader = new Uploader.Builder() .setServiceAccountKeyFilePath(SERVICE_ACCOUNT_FILE_PATH) .setUploaderHelper(uploaderHelper) .setBaseUri(tempFolder.getRoot().toURI()) .build(); UploadRequest uploadRequest = new UploadRequest(); uploadRequest.sourceId = "ds1"; UploadRequest.UpdateSchemaRequest updateRequest = new UploadRequest.UpdateSchemaRequest(); updateRequest.schemaJsonFile = null; uploadRequest.requests = Collections.singletonList(updateRequest); thrown.expect(IOException.class); uploader.execute(uploadRequest); }
@Test public void testUpdateSchemaMissing() throws Exception { Uploader uploader = new Uploader.Builder() .setServiceAccountKeyFilePath(SERVICE_ACCOUNT_FILE_PATH) .setUploaderHelper(uploaderHelper) .setBaseUri(tempFolder.getRoot().toURI()) .build(); UploadRequest uploadRequest = new UploadRequest(); uploadRequest.sourceId = "ds1"; UploadRequest.UpdateSchemaRequest updateRequest = new UploadRequest.UpdateSchemaRequest(); updateRequest.schemaJsonFile = "no-such-file.json"; uploadRequest.requests = Collections.singletonList(updateRequest); thrown.expect(IOException.class); uploader.execute(uploadRequest); }
@Test public void testIndexItemAndContentNullContent() throws Exception { when(uploaderHelper.createTransport()) .thenReturn( new MockHttpTransport() { @Override public MockLowLevelHttpRequest buildRequest(String method, String url) throws IOException { assertEquals("POST", method); String expectedUrl = "https: + "datasources/ds1/items/item1:index"; assertThat(url, startsWith(expectedUrl)); return buildApiRequest(200, new Operation()); } }); Uploader uploader = new Uploader.Builder() .setServiceAccountKeyFilePath(SERVICE_ACCOUNT_FILE_PATH) .setUploaderHelper(uploaderHelper) .build(); UploadRequest uploadRequest = new UploadRequest(); uploadRequest.sourceId = "ds1"; UploadRequest.IndexItemAndContentRequest indexRequest = new UploadRequest.IndexItemAndContentRequest(); indexRequest.item = new Item().setName("item1").setVersion("1"); indexRequest.isIncremental = true; uploadRequest.requests = Collections.singletonList(indexRequest); uploader.execute(uploadRequest); }
@Test public void testIndexItemAndContentMissingContent() throws Exception { Uploader uploader = new Uploader.Builder() .setServiceAccountKeyFilePath(SERVICE_ACCOUNT_FILE_PATH) .setUploaderHelper(uploaderHelper) .build(); UploadRequest uploadRequest = new UploadRequest(); uploadRequest.sourceId = "ds1"; UploadRequest.IndexItemAndContentRequest indexRequest = new UploadRequest.IndexItemAndContentRequest(); indexRequest.item = new Item().setName("item1"); indexRequest.isIncremental = true; indexRequest.mediaContent = new UploadRequest.MediaContent(); indexRequest.mediaContent.contentType = "text/plain"; uploadRequest.requests = Collections.singletonList(indexRequest); thrown.expect(IOException.class); uploader.execute(uploadRequest); }