@Test
@PrepareForTest({CloneGit.class, FetchResult.class, RevCommit.class})

public void testExecute() throws Exception {
  final byte[] fileContent = randomUUID().toString().getBytes();
  final InMemoryRepository repository = mock(InMemoryRepository.class);
  final Git git = mock(Git.class);
  final RemoteAddCommand remoteAddCommand = mock(RemoteAddCommand.class);
  final FetchCommand fetchCommand = mock(FetchCommand.class);
  final FetchResult fetchResult = mock(FetchResult.class);
  final Ref headRef = mock(Ref.class);
  final ObjectId headId = mock(ObjectId.class);
  final RevWalk revWalk = mock(RevWalk.class);
  final RevCommit revCommit = mock(RevCommit.class);
  final RevTree revTree = mock(RevTree.class);
  final TreeWalk treeWalk = mock(TreeWalk.class);
  final ObjectId fileId = mock(ObjectId.class);
  final ObjectLoader objectLoader = mock(ObjectLoader.class);
  whenNew(InMemoryRepository.class).withAnyArguments().thenReturn(repository);
  whenNew(Git.class).withAnyArguments().thenReturn(git);
  when(git.remoteAdd()).thenReturn(remoteAddCommand);
  when(remoteAddCommand.setName(anyString())).thenReturn(remoteAddCommand);
  when(remoteAddCommand.setUri(any(URIish.class))).thenReturn(remoteAddCommand);
  when(git.fetch()).thenReturn(fetchCommand);
  when(fetchCommand.setRemote(anyString())).thenReturn(fetchCommand);
  when(fetchCommand.setRefSpecs(anyString())).thenReturn(fetchCommand);
  when(fetchCommand.call()).thenReturn(fetchResult);
  when(fetchResult.getAdvertisedRef(eq(HEAD))).thenReturn(headRef);
  when(headRef.getObjectId()).thenReturn(headId);
  whenNew(RevWalk.class).withAnyArguments().thenReturn(revWalk);
  when(revWalk.parseCommit(any(AnyObjectId.class))).thenReturn(revCommit);
  when(revCommit.getTree()).thenReturn(revTree);
  whenNew(TreeWalk.class).withAnyArguments().thenReturn(treeWalk);
  final AtomicInteger visitCounter = new AtomicInteger(0);
  when(treeWalk.next()).then(invocation -> 0 == visitCounter.getAndIncrement());
  when(treeWalk.getObjectId(0)).thenReturn(fileId);
  when(treeWalk.getPathString()).thenReturn(randomUUID().toString());
  when(repository.open(fileId)).thenReturn(objectLoader);
  doAnswer(invocation -> {
    try {
      ((OutputStream) invocation.getArgument(0)).write(fileContent);
    } catch (final IOException ex) {
      fail("Unexpected exception");
    }
    return null;
  }).when(objectLoader).copyTo(any(OutputStream.class));
  final String packageName = randomUUID().toString();
  final CloneGit cloneGit = new CloneGit();
  cloneGit.setArguments(asList(packageName));
  cloneGit.execute();
  cloneGit.stream().forEach(file -> {
    try {
      assertArrayEquals(fileContent, from(file.open()));
    } catch (final IOException e) {
      e.printStackTrace();
      fail();
    }
  });
}