import static java.lang.Boolean.valueOf;
+/**
+ * Assertion class
+ */
public class Assert {
+ /**
+ * Assert booleans are equal
+ *
+ * @param expect
+ * expected value
+ * @param actual
+ * actual value
+ */
public static void assertEquals(boolean expect, boolean actual) {
org.junit.Assert.assertEquals(valueOf(expect), valueOf(actual));
}
+ /**
+ * Assert booleans are equal
+ *
+ * @param message
+ * message
+ * @param expect
+ * expected value
+ * @param actual
+ * actual value
+ */
public static void assertEquals(String message, boolean expect,
boolean actual) {
org.junit.Assert
import org.junit.Assert;
import org.junit.Test;
+/**
+ * Abstract test util class
+ */
public abstract class JGitTestUtil {
+ /** Constant <code>CLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"</code> */
public static final String CLASSPATH_TO_RESOURCES = "org/eclipse/jgit/test/resources/";
private JGitTestUtil() {
throw new UnsupportedOperationException();
}
+ /**
+ * Get name of current test by inspecting stack trace
+ *
+ * @return the name
+ */
public static String getName() {
GatherStackTrace stack;
try {
// Thrown above to collect the stack frame.
}
+ /**
+ * Assert byte arrays are equal
+ *
+ * @param exp
+ * expected value
+ * @param act
+ * actual value
+ */
public static void assertEquals(byte[] exp, byte[] act) {
Assert.assertEquals(s(exp), s(act));
}
return RawParseUtils.decode(raw);
}
+ /**
+ * Get test resource file.
+ *
+ * @param fileName
+ * @return the test resource file
+ */
public static File getTestResourceFile(final String fileName) {
if (fileName == null || fileName.length() <= 0) {
return null;
}
}
+ /**
+ * Copy test resource.
+ *
+ * @param name
+ * @param dest
+ * @throws IOException
+ */
public static void copyTestResource(String name, File dest)
throws IOException {
URL url = cl().getResource(CLASSPATH_TO_RESOURCES + name);
return JGitTestUtil.class.getClassLoader();
}
+ /**
+ * Write a trash file.
+ *
+ * @param db
+ * @param name
+ * @param data
+ * @return the trash file
+ * @throws IOException
+ */
public static File writeTrashFile(final Repository db,
final String name, final String data) throws IOException {
File path = new File(db.getWorkTree(), name);
return path;
}
+ /**
+ * Write a trash file.
+ *
+ * @param db
+ * @param subdir
+ * @param name
+ * @param data
+ * @return the trash file
+ * @throws IOException
+ */
public static File writeTrashFile(final Repository db,
final String subdir,
final String name, final String data) throws IOException {
return new String(body, 0, body.length, "UTF-8");
}
+ /**
+ * Read a file's content
+ *
+ * @param db
+ * @param name
+ * @return the content of the file
+ * @throws IOException
+ */
public static String read(final Repository db, final String name)
throws IOException {
File file = new File(db.getWorkTree(), name);
return read(file);
}
+ /**
+ * Check if file exists
+ *
+ * @param db
+ * @param name
+ * name of the file
+ * @return {@code true} if the file exists
+ */
public static boolean check(final Repository db, final String name) {
File file = new File(db.getWorkTree(), name);
return file.exists();
}
+ /**
+ * Delete a trash file.
+ *
+ * @param db
+ * @param name
+ * @throws IOException
+ */
public static void deleteTrashFile(final Repository db,
final String name) throws IOException {
File path = new File(db.getWorkTree(), name);
}
/**
+ * Write a symbolic link
+ *
* @param db
* the repository
* @param link
* A temporary directory is created for each test, allowing each test to use a
* fresh environment. The temporary directory is cleaned up after the test ends.
* <p>
- * Callers should not use {@link RepositoryCache} from within these tests as it
- * may wedge file descriptors open past the end of the test.
+ * Callers should not use {@link org.eclipse.jgit.lib.RepositoryCache} from
+ * within these tests as it may wedge file descriptors open past the end of the
+ * test.
* <p>
* A system property {@code jgit.junit.usemmap} defines whether memory mapping
* is used. Memory mapping has an effect on the file system, in that memory
private final Set<Repository> toClose = new HashSet<>();
private File tmp;
+ /**
+ * Setup test
+ *
+ * @throws Exception
+ */
@Before
public void setUp() throws Exception {
tmp = File.createTempFile("jgit_test_", "_tmp");
c.install();
}
+ /**
+ * Get temporary directory.
+ *
+ * @return the temporary directory
+ */
protected File getTemporaryDirectory() {
return tmp.getAbsoluteFile();
}
+ /**
+ * Get list of ceiling directories
+ *
+ * @return list of ceiling directories
+ */
protected List<File> getCeilings() {
return Collections.singletonList(getTemporaryDirectory());
}
return stringBuilder.toString();
}
+ /**
+ * Tear down the test
+ *
+ * @throws Exception
+ */
@After
public void tearDown() throws Exception {
RepositoryCache.clear();
SystemReader.setInstance(null);
}
- /** Increment the {@link #author} and {@link #committer} times. */
+ /**
+ * Increment the {@link #author} and {@link #committer} times.
+ */
protected void tick() {
mockSystemReader.tick(5 * 60);
final long now = mockSystemReader.getCurrentTime();
System.err.println(msg);
}
+ /** Constant <code>MOD_TIME=1</code> */
public static final int MOD_TIME = 1;
+ /** Constant <code>SMUDGE=2</code> */
public static final int SMUDGE = 2;
+ /** Constant <code>LENGTH=4</code> */
public static final int LENGTH = 4;
+ /** Constant <code>CONTENT_ID=8</code> */
public static final int CONTENT_ID = 8;
+ /** Constant <code>CONTENT=16</code> */
public static final int CONTENT = 16;
+ /** Constant <code>ASSUME_UNCHANGED=32</code> */
public static final int ASSUME_UNCHANGED = 32;
/**
*
* @param repo
* the repository the index state should be determined for
- *
* @param includedOptions
* a bitmask constructed out of the constants {@link #MOD_TIME},
* {@link #SMUDGE}, {@link #LENGTH}, {@link #CONTENT_ID} and
JGitTestUtil.write(f, body);
}
+ /**
+ * Read a file's content
+ *
+ * @param f
+ * the file
+ * @return the content of the file
+ * @throws IOException
+ */
protected String read(final File f) throws IOException {
return JGitTestUtil.read(f);
}
import org.eclipse.jgit.util.time.ProposedTimestamp;
/**
- * Mock {@link SystemReader} for tests.
+ * Mock {@link org.eclipse.jgit.util.SystemReader} for tests.
*/
public class MockSystemReader extends SystemReader {
private final class MockConfig extends FileBasedConfig {
FileBasedConfig systemGitConfig;
+ /**
+ * Constructor for <code>MockSystemReader</code>
+ */
public MockSystemReader() {
init(Constants.OS_USER_NAME_KEY);
init(Constants.GIT_AUTHOR_NAME_KEY);
setProperty(n, n);
}
+ /**
+ * Clear properties
+ */
public void clearProperties() {
values.clear();
}
+ /**
+ * Set a property
+ *
+ * @param key
+ * @param value
+ */
public void setProperty(String key, String value) {
values.put(key, value);
}
+ /** {@inheritDoc} */
@Override
public String getenv(String variable) {
return values.get(variable);
}
+ /** {@inheritDoc} */
@Override
public String getProperty(String key) {
return values.get(key);
}
+ /** {@inheritDoc} */
@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
assert parent == null || parent == systemGitConfig;
return userGitConfig;
}
+ /** {@inheritDoc} */
@Override
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
assert parent == null;
return systemGitConfig;
}
+ /** {@inheritDoc} */
@Override
public String getHostname() {
return "fake.host.example.com";
}
+ /** {@inheritDoc} */
@Override
public long getCurrentTime() {
return now;
}
+ /** {@inheritDoc} */
@Override
public MonotonicClock getClock() {
return new MonotonicClock() {
now += secDelta * 1000L;
}
+ /** {@inheritDoc} */
@Override
public int getTimezone(long when) {
return getTimeZone().getOffset(when) / (60 * 1000);
}
+ /** {@inheritDoc} */
@Override
public TimeZone getTimeZone() {
return TimeZone.getTimeZone("GMT-03:30");
}
+ /** {@inheritDoc} */
@Override
public Locale getLocale() {
return Locale.US;
}
+ /** {@inheritDoc} */
@Override
public SimpleDateFormat getSimpleDateFormat(String pattern) {
return new SimpleDateFormat(pattern, getLocale());
}
+ /** {@inheritDoc} */
@Override
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle) {
return DateFormat
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * Interface enabling to run tests repeatedly
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target({ java.lang.annotation.ElementType.METHOD })
public @interface Repeat {
+ /**
+ * Number of repetitions
+ */
public abstract int n();
}
import org.junit.runners.model.Statement;
/**
- * {@link TestRule} which enables to run the same JUnit test repeatedly. Add
- * this rule to the test class
+ * {@link org.junit.rules.TestRule} which enables to run the same JUnit test
+ * repeatedly. Add this rule to the test class
*
* <pre>
* public class MyTest {
}
}
+ /** {@inheritDoc} */
@Override
public Statement apply(Statement statement, Description description) {
Statement result = statement;
* repositories and destroying them when the tests are finished.
*/
public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
+ /**
+ * Copy a file
+ *
+ * @param src
+ * @param dst
+ * @throws IOException
+ */
protected static void copyFile(final File src, final File dst)
throws IOException {
final FileInputStream fis = new FileInputStream(src);
}
}
+ /**
+ * Write a trash file
+ *
+ * @param name
+ * @param data
+ * @return the trash file
+ * @throws IOException
+ */
protected File writeTrashFile(final String name, final String data)
throws IOException {
return JGitTestUtil.writeTrashFile(db, name, data);
return JGitTestUtil.writeLink(db, link, target);
}
+ /**
+ * Write a trash file
+ *
+ * @param subdir
+ * @param name
+ * @param data
+ * @return the trash file
+ * @throws IOException
+ */
protected File writeTrashFile(final String subdir, final String name,
final String data)
throws IOException {
return JGitTestUtil.writeTrashFile(db, subdir, name, data);
}
+ /**
+ * Read content of a file
+ *
+ * @param name
+ * @return the file's content
+ * @throws IOException
+ */
protected String read(final String name) throws IOException {
return JGitTestUtil.read(db, name);
}
+ /**
+ * Check if file exists
+ *
+ * @param name
+ * file name
+ * @return if the file exists
+ */
protected boolean check(final String name) {
return JGitTestUtil.check(db, name);
}
+ /**
+ * Delete a trash file
+ *
+ * @param name
+ * file name
+ * @throws IOException
+ */
protected void deleteTrashFile(final String name) throws IOException {
JGitTestUtil.deleteTrashFile(db, name);
}
+ /**
+ * Check content of a file.
+ *
+ * @param f
+ * @param checkData
+ * expected content
+ * @throws IOException
+ */
protected static void checkFile(File f, final String checkData)
throws IOException {
Reader r = new InputStreamReader(new FileInputStream(f), "UTF-8");
/** Working directory of {@link #db}. */
protected File trash;
+ /** {@inheritDoc} */
@Override
@Before
public void setUp() throws Exception {
* have an index which matches their prepared content.
*
* @param treeItr
- * a {@link FileTreeIterator} which determines which files should
- * go into the new index
+ * a {@link org.eclipse.jgit.treewalk.FileTreeIterator} which
+ * determines which files should go into the new index
* @throws FileNotFoundException
* @throws IOException
*/
*
* @param l
* the object to lookup
+ * @param lookupTable
+ * a table storing object-name mappings.
* @param nameTemplate
* the name for that object. Can contain "%n" which will be
* replaced by a running number before used as a name. If the
* lookup table already contains the object this parameter will
* be ignored
- * @param lookupTable
- * a table storing object-name mappings.
* @return a name of that object. Is not guaranteed to be unique. Use
* nameTemplates containing "%n" to always have unique names
*/
* @param str
* the string in which backslashes should be replaced
* @return the resulting string with slashes
- * @since 4.2
+ * @since 4.2
*/
public static String slashify(String str) {
str = str.replace('\\', '/');
}
}
+ /**
+ * Create a branch
+ *
+ * @param objectId
+ * @param branchName
+ * @throws IOException
+ */
protected void createBranch(ObjectId objectId, String branchName)
throws IOException {
RefUpdate updateRef = db.updateRef(branchName);
updateRef.update();
}
+ /**
+ * Checkout a branch
+ *
+ * @param branchName
+ * @throws IllegalStateException
+ * @throws IOException
+ */
protected void checkoutBranch(String branchName)
throws IllegalStateException, IOException {
try (RevWalk walk = new RevWalk(db)) {
}
}
+ /**
+ * Create <code>DirCacheEntry</code>
+ *
+ * @param path
+ * @param mode
+ * @return the DirCacheEntry
+ */
protected DirCacheEntry createEntry(final String path, final FileMode mode) {
return createEntry(path, mode, DirCacheEntry.STAGE_0, path);
}
+ /**
+ * Create <code>DirCacheEntry</code>
+ *
+ * @param path
+ * @param mode
+ * @param content
+ * @return the DirCacheEntry
+ */
protected DirCacheEntry createEntry(final String path, final FileMode mode,
final String content) {
return createEntry(path, mode, DirCacheEntry.STAGE_0, content);
}
+ /**
+ * Create <code>DirCacheEntry</code>
+ *
+ * @param path
+ * @param mode
+ * @param stage
+ * @param content
+ * @return the DirCacheEntry
+ */
protected DirCacheEntry createEntry(final String path, final FileMode mode,
final int stage, final String content) {
final DirCacheEntry entry = new DirCacheEntry(path, stage);
return entry;
}
+ /**
+ * Assert files are equal
+ *
+ * @param expected
+ * @param actual
+ * @throws IOException
+ */
public static void assertEqualsFile(File expected, File actual)
throws IOException {
assertEquals(expected.getCanonicalFile(), actual.getCanonicalFile());
import org.eclipse.jgit.lib.ProgressMonitor;
+/**
+ * Strict work monitor
+ */
public final class StrictWorkMonitor implements ProgressMonitor {
private int lastWork, totalWork;
+ /** {@inheritDoc} */
@Override
public void start(int totalTasks) {
// empty
}
+ /** {@inheritDoc} */
@Override
public void beginTask(String title, int total) {
this.totalWork = total;
lastWork = 0;
}
+ /** {@inheritDoc} */
@Override
public void update(int completed) {
lastWork += completed;
}
+ /** {@inheritDoc} */
@Override
public void endTask() {
assertEquals("Units of work recorded", totalWork, lastWork);
}
+ /** {@inheritDoc} */
@Override
public boolean isCancelled() {
return false;
*/
public class TestRepository<R extends Repository> {
+ /** Constant <code>AUTHOR="J. Author"</code> */
public static final String AUTHOR = "J. Author";
+ /** Constant <code>AUTHOR_EMAIL="jauthor@example.com"</code> */
public static final String AUTHOR_EMAIL = "jauthor@example.com";
+ /** Constant <code>COMMITTER="J. Committer"</code> */
public static final String COMMITTER = "J. Committer";
+ /** Constant <code>COMMITTER_EMAIL="jcommitter@example.com"</code> */
public static final String COMMITTER_EMAIL = "jcommitter@example.com";
private final PersonIdent defaultAuthor;
defaultCommitter = new PersonIdent(COMMITTER, COMMITTER_EMAIL, now, tz);
}
- /** @return the repository this helper class operates against. */
+ /**
+ * Get repository
+ *
+ * @return the repository this helper class operates against.
+ */
public R getRepository() {
return db;
}
- /** @return get the RevWalk pool all objects are allocated through. */
+ /**
+ * Get RevWalk
+ *
+ * @return get the RevWalk pool all objects are allocated through.
+ */
public RevWalk getRevWalk() {
return pool;
}
/**
+ * Return Git API wrapper
+ *
* @return an API wrapper for the underlying repository. This wrapper does
- * not allocate any new resources and need not be closed (but closing
- * it is harmless). */
+ * not allocate any new resources and need not be closed (but
+ * closing it is harmless).
+ */
public Git git() {
return git;
}
/**
+ * Get date
+ *
* @return current date.
* @since 4.2
*/
return new Date(mockSystemReader.getCurrentTime());
}
- /** @return timezone used for default identities. */
+ /**
+ * Get timezone
+ *
+ * @return timezone used for default identities.
+ */
public TimeZone getTimeZone() {
return mockSystemReader.getTimeZone();
}
return pool.lookupCommit(id);
}
- /** @return a new commit builder. */
+ /**
+ * Create commit builder
+ *
+ * @return a new commit builder.
+ */
public CommitBuilder commit() {
return new CommitBuilder();
}
/**
* Soft-reset HEAD to a detached state.
- * <p>
+ *
* @param id
* ID of detached head.
* @throws Exception
* Ensure the body of the given object has been parsed.
*
* @param <T>
- * type of object, e.g. {@link RevTag} or {@link RevCommit}.
+ * type of object, e.g. {@link org.eclipse.jgit.revwalk.RevTag}
+ * or {@link org.eclipse.jgit.revwalk.RevCommit}.
* @param object
* reference to the (possibly unparsed) object to force body
* parsing of.
package org.eclipse.jgit.junit;
-/** Toy RNG to ensure we get predictable numbers during unit tests. */
+/**
+ * Toy RNG to ensure we get predictable numbers during unit tests.
+ */
public class TestRng {
private int next;
}
/**
+ * Next int
+ *
* @return the next random integer.
*/
public int nextInt() {
import org.eclipse.jgit.util.time.ProposedTimestamp;
/**
- * Fake {@link MonotonicClock} for testing code that uses Clock.
+ * Fake {@link org.eclipse.jgit.util.time.MonotonicClock} for testing code that
+ * uses Clock.
*
* @since 4.6
*/
now += unit.toMillis(add);
}
+ /** {@inheritDoc} */
@Override
public ProposedTimestamp propose() {
long t = now++;