### Question:
ContentUploadServiceImpl extends BaseApiService<CloudSearch> implements ContentUploadService { @Override public ListenableFuture<Void> uploadContent( String resourceName, AbstractInputStreamContent content) throws IOException { checkArgument(!Strings.isNullOrEmpty(resourceName), "resource name can not be empty"); checkNotNull(content, "content can not be null"); checkState(isRunning(), "upload service not running to accept upload requests"); Upload upload = service.media().upload(resourceName, new Media().setResourceName(resourceName), content); mediaUploader.enableMediaUploader(upload); return executorService.submit( () -> { upload.executeUnparsed(); return null; }); } private  ContentUploadServiceImpl(Builder builder); @Override ListenableFuture<Void> uploadContent(
      String resourceName, AbstractInputStreamContent content); static final Set<String> API_SCOPES; }### Answer:
@Test public void testUploadWithNotStarted() throws IOException, GeneralSecurityException { ContentUploadService contentUpload = new ContentUploadServiceImpl.Builder().setCredentialFactory(credentialFactory).build(); assertFalse(contentUpload.isRunning()); thrown.expect(IllegalStateException.class); contentUpload.uploadContent("resource", content); }
@Test public void testUploadAfterStarted() throws IOException, GeneralSecurityException, InterruptedException, ExecutionException { ContentUploadService contentUpload = new ContentUploadServiceImpl.Builder() .setService(service) .setCredentialFactory(credentialFactory) .setMediaUploader(mediaUploader) .build(); contentUpload.startAsync().awaitRunning(); assertTrue(contentUpload.isRunning()); when(service.media()).thenReturn(serviceMedia); when(serviceMedia.upload( "resource", new com.google.api.services.cloudsearch.v1.model.Media().setResourceName("resource"), content)) .thenReturn(uploadRequest); ListenableFuture<Void> uploadResult = contentUpload.uploadContent("resource", content); uploadResult.get(); contentUpload.stopAsync().awaitTerminated(); assertFalse(contentUpload.isRunning()); verify(mediaUploader).enableMediaUploader(uploadRequest); }
@Test public void testUploadAfterStop() throws IOException, GeneralSecurityException { ContentUploadService contentUpload = new ContentUploadServiceImpl.Builder().setCredentialFactory(credentialFactory).build(); contentUpload.startAsync().awaitRunning(); assertTrue(contentUpload.isRunning()); contentUpload.stopAsync().awaitTerminated(); assertFalse(contentUpload.isRunning()); thrown.expect(IllegalStateException.class); contentUpload.uploadContent("resource", content); }