### Question:
RepositoryDocError implements ApiOperation { @Override public List<GenericJson> execute(IndexingService service) throws IOException, InterruptedException { PushItem item = new PushItem() .setType("REPOSITORY_ERROR") .setRepositoryError(repositoryDocException.getRepositoryError()); try { return Collections.singletonList(service.push(itemId, item).get()); } catch (ExecutionException e) { throw new IOException("Error pushing repository error", e.getCause()); } } RepositoryDocError(String itemId, RepositoryException exception); @Override List<GenericJson> execute(IndexingService service); String getId(); RepositoryException getException(); @Override String toString();  }### Answer:
@Test public void execute() throws IOException, InterruptedException { when(mockIndexingService.push(any(), any())) .thenReturn(Futures.immediateFuture(new Item())); RepositoryDocError subject = new RepositoryDocError("foo", new RepositoryException.Builder().build()); subject.execute(mockIndexingService); ArgumentCaptor<PushItem> pushItemCaptor = ArgumentCaptor.forClass(PushItem.class); verify(mockIndexingService) .push(eq("foo"), pushItemCaptor.capture()); PushItem pushItem = pushItemCaptor.getValue(); assertThat(pushItem.getType(), equalTo("REPOSITORY_ERROR")); assertThat(pushItem.getRepositoryError(), equalTo(new RepositoryError())); }
@Test public void execute_pushThrowsException_throwsException() throws IOException, InterruptedException { SettableFuture<Item> pushFuture = SettableFuture.create(); pushFuture.setException(new RuntimeException("expected exception")); when(mockIndexingService.push(any(), any())) .thenReturn(pushFuture); RepositoryDocError subject = new RepositoryDocError("foo", new RepositoryException.Builder().build()); thrown.expect(IOException.class); thrown.expectCause(isA(RuntimeException.class)); subject.execute(mockIndexingService); }