added unit test for GitGcTask

This commit is contained in:
Sebastian Sdorra
2016-05-31 09:39:42 +02:00
parent 6c62716119
commit 0ef064c1fb
2 changed files with 144 additions and 1 deletions

View File

@@ -31,6 +31,7 @@
package sonia.scm.repository;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
import com.google.inject.Inject;
import java.io.File;
@@ -123,7 +124,7 @@ public class GitGcTask implements Runnable {
File file = repositoryHandler.getDirectory(repository);
Git git = null;
try {
git = Git.open(file);
git = open(file);
GarbageCollectCommand gcc = git.gc();
// print statistics before execution, because it looks like
// jgit returns the statistics after gc has finished
@@ -145,5 +146,19 @@ public class GitGcTask implements Runnable {
}
}
}
/**
* Opens the git repository. This method is only visible for testing purposes.
*
* @param file repository directory
*
* @return git for repository
*
* @throws IOException
*/
@VisibleForTesting
protected Git open(File file) throws IOException {
return Git.open(file);
}
}