added unit test for mercurial outgoing command

This commit is contained in:
Sebastian Sdorra
2013-05-10 13:17:01 +02:00
parent fb59c5cd56
commit 31bdb3093b
2 changed files with 183 additions and 2 deletions

View File

@@ -33,16 +33,20 @@ package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.aragost.javahg.commands.ExecutionException;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.spi.javahg.HgOutgoingChangesetCommand;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.util.Collections;
import java.util.List;
/**
@@ -53,6 +57,11 @@ public class HgOutgoingCommand extends AbstractCommand
implements OutgoingCommand
{
/** Field description */
private static final int NO_OUTGOING_CHANGESETS = 1;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
@@ -77,10 +86,13 @@ public class HgOutgoingCommand extends AbstractCommand
* @param request
*
* @return
*
* @throws RepositoryException
*/
@Override
public ChangesetPagingResult getOutgoingChangesets(
OutgoingCommandRequest request)
throws RepositoryException
{
File remoteRepository = handler.getDirectory(request.getRemoteRepository());
@@ -88,8 +100,23 @@ public class HgOutgoingCommand extends AbstractCommand
// TODO implement paging
List<Changeset> changesets =
on(repository).execute(remoteRepository.getAbsolutePath());
List<Changeset> changesets;
try
{
changesets = on(repository).execute(remoteRepository.getAbsolutePath());
}
catch (ExecutionException ex)
{
if (ex.getCommand().getReturnCode() == NO_OUTGOING_CHANGESETS)
{
changesets = Collections.EMPTY_LIST;
}
else
{
throw new RepositoryException("could not execute outgoing command", ex);
}
}
return new ChangesetPagingResult(changesets.size(), changesets);
}