@Test
public void testGetAndSaveJobResults() throws Exception {

  service.activate(cc);
  InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PULLED_TRANSCRIPTION_FILE);
  database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.InProgress.name(), TRACK_DURATION, DATE_EXPECTED, PROVIDER);
  Capture<String> capturedCollection = Capture.newInstance();
  Capture<String> capturedFileName = Capture.newInstance();
  EasyMock.expect(workspace.putInCollection(EasyMock.capture(capturedCollection), EasyMock.capture(capturedFileName),
          EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://anything"));
  EasyMock.replay(workspace);
  HttpEntity httpEntity = EasyMock.createNiceMock(HttpEntity.class);
  EasyMock.expect(httpEntity.getContent()).andReturn(stream);
  CloseableHttpResponse response = EasyMock.createNiceMock(CloseableHttpResponse.class);
  StatusLine status = EasyMock.createNiceMock(StatusLine.class);
  EasyMock.expect(response.getStatusLine()).andReturn(status).anyTimes();
  EasyMock.expect(response.getEntity()).andReturn(httpEntity).anyTimes();
  EasyMock.expect(status.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
  EasyMock.replay(httpEntity, response, status);
  Capture<HttpGet> capturedGet = Capture.newInstance();
  EasyMock.expect(httpClient.execute(EasyMock.capture(capturedGet))).andReturn(response).anyTimes();
  EasyMock.replay(httpClient);
  long before = System.currentTimeMillis();
  service.getAndSaveJobResults(JOB_ID);
  long after = System.currentTimeMillis();
  // Check if correct url was invoked
  Assert.assertEquals(WATSON_URL + "/v1/recognitions/" + JOB_ID,
          capturedGet.getValue().getURI().toString());
  // Check if status and date in db was updated
  TranscriptionJobControl job = database.findByJob(JOB_ID);
  Assert.assertNotNull(job);
  Assert.assertEquals(TranscriptionJobControl.Status.TranscriptionComplete.name(), job.getStatus());
  Assert.assertNotNull(job.getDateCompleted());
  Assert.assertTrue(before <= job.getDateCompleted().getTime() && job.getDateCompleted().getTime() <= after);
  // Check if results were saved into a collection
  Assert.assertEquals(IBMWatsonTranscriptionService.TRANSCRIPT_COLLECTION, capturedCollection.getValue());
  Assert.assertEquals(JOB_ID + ".json", capturedFileName.getValue());
}