Fix javadoc in org.eclipse.jgit.junit
Change-Id: I1107e6a82849ac329361baabb5c481d86ea6dc9e Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
0b131b7312
commit
a90b75b47a
|
@ -44,12 +44,33 @@
|
||||||
|
|
||||||
import static java.lang.Boolean.valueOf;
|
import static java.lang.Boolean.valueOf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assertion class
|
||||||
|
*/
|
||||||
public class Assert {
|
public class Assert {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert booleans are equal
|
||||||
|
*
|
||||||
|
* @param expect
|
||||||
|
* expected value
|
||||||
|
* @param actual
|
||||||
|
* actual value
|
||||||
|
*/
|
||||||
public static void assertEquals(boolean expect, boolean actual) {
|
public static void assertEquals(boolean expect, boolean actual) {
|
||||||
org.junit.Assert.assertEquals(valueOf(expect), valueOf(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,
|
public static void assertEquals(String message, boolean expect,
|
||||||
boolean actual) {
|
boolean actual) {
|
||||||
org.junit.Assert
|
org.junit.Assert
|
||||||
|
|
|
@ -64,13 +64,22 @@
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract test util class
|
||||||
|
*/
|
||||||
public abstract class JGitTestUtil {
|
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/";
|
public static final String CLASSPATH_TO_RESOURCES = "org/eclipse/jgit/test/resources/";
|
||||||
|
|
||||||
private JGitTestUtil() {
|
private JGitTestUtil() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name of current test by inspecting stack trace
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public static String getName() {
|
public static String getName() {
|
||||||
GatherStackTrace stack;
|
GatherStackTrace stack;
|
||||||
try {
|
try {
|
||||||
|
@ -109,6 +118,14 @@ private static class GatherStackTrace extends Exception {
|
||||||
// Thrown above to collect the stack frame.
|
// 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) {
|
public static void assertEquals(byte[] exp, byte[] act) {
|
||||||
Assert.assertEquals(s(exp), s(act));
|
Assert.assertEquals(s(exp), s(act));
|
||||||
}
|
}
|
||||||
|
@ -117,6 +134,12 @@ private static String s(byte[] raw) {
|
||||||
return RawParseUtils.decode(raw);
|
return RawParseUtils.decode(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get test resource file.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* @return the test resource file
|
||||||
|
*/
|
||||||
public static File getTestResourceFile(final String fileName) {
|
public static File getTestResourceFile(final String fileName) {
|
||||||
if (fileName == null || fileName.length() <= 0) {
|
if (fileName == null || fileName.length() <= 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -145,6 +168,13 @@ public static File getTestResourceFile(final String fileName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy test resource.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param dest
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
public static void copyTestResource(String name, File dest)
|
public static void copyTestResource(String name, File dest)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
URL url = cl().getResource(CLASSPATH_TO_RESOURCES + name);
|
URL url = cl().getResource(CLASSPATH_TO_RESOURCES + name);
|
||||||
|
@ -169,6 +199,15 @@ private static ClassLoader cl() {
|
||||||
return JGitTestUtil.class.getClassLoader();
|
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,
|
public static File writeTrashFile(final Repository db,
|
||||||
final String name, final String data) throws IOException {
|
final String name, final String data) throws IOException {
|
||||||
File path = new File(db.getWorkTree(), name);
|
File path = new File(db.getWorkTree(), name);
|
||||||
|
@ -176,6 +215,16 @@ public static File writeTrashFile(final Repository db,
|
||||||
return path;
|
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,
|
public static File writeTrashFile(final Repository db,
|
||||||
final String subdir,
|
final String subdir,
|
||||||
final String name, final String data) throws IOException {
|
final String name, final String data) throws IOException {
|
||||||
|
@ -224,17 +273,40 @@ public static String read(final File file) throws IOException {
|
||||||
return new String(body, 0, body.length, "UTF-8");
|
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)
|
public static String read(final Repository db, final String name)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
File file = new File(db.getWorkTree(), name);
|
File file = new File(db.getWorkTree(), name);
|
||||||
return read(file);
|
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) {
|
public static boolean check(final Repository db, final String name) {
|
||||||
File file = new File(db.getWorkTree(), name);
|
File file = new File(db.getWorkTree(), name);
|
||||||
return file.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a trash file.
|
||||||
|
*
|
||||||
|
* @param db
|
||||||
|
* @param name
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
public static void deleteTrashFile(final Repository db,
|
public static void deleteTrashFile(final Repository db,
|
||||||
final String name) throws IOException {
|
final String name) throws IOException {
|
||||||
File path = new File(db.getWorkTree(), name);
|
File path = new File(db.getWorkTree(), name);
|
||||||
|
@ -242,6 +314,8 @@ public static void deleteTrashFile(final Repository db,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Write a symbolic link
|
||||||
|
*
|
||||||
* @param db
|
* @param db
|
||||||
* the repository
|
* the repository
|
||||||
* @param link
|
* @param link
|
||||||
|
|
|
@ -82,8 +82,9 @@
|
||||||
* A temporary directory is created for each test, allowing each test to use a
|
* 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.
|
* fresh environment. The temporary directory is cleaned up after the test ends.
|
||||||
* <p>
|
* <p>
|
||||||
* Callers should not use {@link RepositoryCache} from within these tests as it
|
* Callers should not use {@link org.eclipse.jgit.lib.RepositoryCache} from
|
||||||
* may wedge file descriptors open past the end of the test.
|
* within these tests as it may wedge file descriptors open past the end of the
|
||||||
|
* test.
|
||||||
* <p>
|
* <p>
|
||||||
* A system property {@code jgit.junit.usemmap} defines whether memory mapping
|
* 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
|
* is used. Memory mapping has an effect on the file system, in that memory
|
||||||
|
@ -112,6 +113,11 @@ public abstract class LocalDiskRepositoryTestCase {
|
||||||
private final Set<Repository> toClose = new HashSet<>();
|
private final Set<Repository> toClose = new HashSet<>();
|
||||||
private File tmp;
|
private File tmp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
tmp = File.createTempFile("jgit_test_", "_tmp");
|
tmp = File.createTempFile("jgit_test_", "_tmp");
|
||||||
|
@ -142,10 +148,20 @@ public void setUp() throws Exception {
|
||||||
c.install();
|
c.install();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get temporary directory.
|
||||||
|
*
|
||||||
|
* @return the temporary directory
|
||||||
|
*/
|
||||||
protected File getTemporaryDirectory() {
|
protected File getTemporaryDirectory() {
|
||||||
return tmp.getAbsoluteFile();
|
return tmp.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of ceiling directories
|
||||||
|
*
|
||||||
|
* @return list of ceiling directories
|
||||||
|
*/
|
||||||
protected List<File> getCeilings() {
|
protected List<File> getCeilings() {
|
||||||
return Collections.singletonList(getTemporaryDirectory());
|
return Collections.singletonList(getTemporaryDirectory());
|
||||||
}
|
}
|
||||||
|
@ -164,6 +180,11 @@ private static String makePath(List<?> objects) {
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tear down the test
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
RepositoryCache.clear();
|
RepositoryCache.clear();
|
||||||
|
@ -185,7 +206,9 @@ public void tearDown() throws Exception {
|
||||||
SystemReader.setInstance(null);
|
SystemReader.setInstance(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Increment the {@link #author} and {@link #committer} times. */
|
/**
|
||||||
|
* Increment the {@link #author} and {@link #committer} times.
|
||||||
|
*/
|
||||||
protected void tick() {
|
protected void tick() {
|
||||||
mockSystemReader.tick(5 * 60);
|
mockSystemReader.tick(5 * 60);
|
||||||
final long now = mockSystemReader.getCurrentTime();
|
final long now = mockSystemReader.getCurrentTime();
|
||||||
|
@ -239,16 +262,22 @@ private static void reportDeleteFailure(boolean failOnError, File e) {
|
||||||
System.err.println(msg);
|
System.err.println(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Constant <code>MOD_TIME=1</code> */
|
||||||
public static final int MOD_TIME = 1;
|
public static final int MOD_TIME = 1;
|
||||||
|
|
||||||
|
/** Constant <code>SMUDGE=2</code> */
|
||||||
public static final int SMUDGE = 2;
|
public static final int SMUDGE = 2;
|
||||||
|
|
||||||
|
/** Constant <code>LENGTH=4</code> */
|
||||||
public static final int LENGTH = 4;
|
public static final int LENGTH = 4;
|
||||||
|
|
||||||
|
/** Constant <code>CONTENT_ID=8</code> */
|
||||||
public static final int CONTENT_ID = 8;
|
public static final int CONTENT_ID = 8;
|
||||||
|
|
||||||
|
/** Constant <code>CONTENT=16</code> */
|
||||||
public static final int CONTENT = 16;
|
public static final int CONTENT = 16;
|
||||||
|
|
||||||
|
/** Constant <code>ASSUME_UNCHANGED=32</code> */
|
||||||
public static final int ASSUME_UNCHANGED = 32;
|
public static final int ASSUME_UNCHANGED = 32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,7 +308,6 @@ private static void reportDeleteFailure(boolean failOnError, File e) {
|
||||||
*
|
*
|
||||||
* @param repo
|
* @param repo
|
||||||
* the repository the index state should be determined for
|
* the repository the index state should be determined for
|
||||||
*
|
|
||||||
* @param includedOptions
|
* @param includedOptions
|
||||||
* a bitmask constructed out of the constants {@link #MOD_TIME},
|
* a bitmask constructed out of the constants {@link #MOD_TIME},
|
||||||
* {@link #SMUDGE}, {@link #LENGTH}, {@link #CONTENT_ID} and
|
* {@link #SMUDGE}, {@link #LENGTH}, {@link #CONTENT_ID} and
|
||||||
|
@ -546,6 +574,14 @@ protected void write(final File f, final String body) throws IOException {
|
||||||
JGitTestUtil.write(f, body);
|
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 {
|
protected String read(final File f) throws IOException {
|
||||||
return JGitTestUtil.read(f);
|
return JGitTestUtil.read(f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
import org.eclipse.jgit.util.time.ProposedTimestamp;
|
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 {
|
public class MockSystemReader extends SystemReader {
|
||||||
private final class MockConfig extends FileBasedConfig {
|
private final class MockConfig extends FileBasedConfig {
|
||||||
|
@ -94,6 +94,9 @@ public boolean isOutdated() {
|
||||||
|
|
||||||
FileBasedConfig systemGitConfig;
|
FileBasedConfig systemGitConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for <code>MockSystemReader</code>
|
||||||
|
*/
|
||||||
public MockSystemReader() {
|
public MockSystemReader() {
|
||||||
init(Constants.OS_USER_NAME_KEY);
|
init(Constants.OS_USER_NAME_KEY);
|
||||||
init(Constants.GIT_AUTHOR_NAME_KEY);
|
init(Constants.GIT_AUTHOR_NAME_KEY);
|
||||||
|
@ -110,46 +113,62 @@ private void init(final String n) {
|
||||||
setProperty(n, n);
|
setProperty(n, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear properties
|
||||||
|
*/
|
||||||
public void clearProperties() {
|
public void clearProperties() {
|
||||||
values.clear();
|
values.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a property
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
public void setProperty(String key, String value) {
|
public void setProperty(String key, String value) {
|
||||||
values.put(key, value);
|
values.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public String getenv(String variable) {
|
public String getenv(String variable) {
|
||||||
return values.get(variable);
|
return values.get(variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public String getProperty(String key) {
|
public String getProperty(String key) {
|
||||||
return values.get(key);
|
return values.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public FileBasedConfig openUserConfig(Config parent, FS fs) {
|
public FileBasedConfig openUserConfig(Config parent, FS fs) {
|
||||||
assert parent == null || parent == systemGitConfig;
|
assert parent == null || parent == systemGitConfig;
|
||||||
return userGitConfig;
|
return userGitConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
|
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
|
||||||
assert parent == null;
|
assert parent == null;
|
||||||
return systemGitConfig;
|
return systemGitConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return "fake.host.example.com";
|
return "fake.host.example.com";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentTime() {
|
public long getCurrentTime() {
|
||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public MonotonicClock getClock() {
|
public MonotonicClock getClock() {
|
||||||
return new MonotonicClock() {
|
return new MonotonicClock() {
|
||||||
|
@ -182,26 +201,31 @@ public void tick(final int secDelta) {
|
||||||
now += secDelta * 1000L;
|
now += secDelta * 1000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public int getTimezone(long when) {
|
public int getTimezone(long when) {
|
||||||
return getTimeZone().getOffset(when) / (60 * 1000);
|
return getTimeZone().getOffset(when) / (60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
return TimeZone.getTimeZone("GMT-03:30");
|
return TimeZone.getTimeZone("GMT-03:30");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return Locale.US;
|
return Locale.US;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public SimpleDateFormat getSimpleDateFormat(String pattern) {
|
public SimpleDateFormat getSimpleDateFormat(String pattern) {
|
||||||
return new SimpleDateFormat(pattern, getLocale());
|
return new SimpleDateFormat(pattern, getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle) {
|
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle) {
|
||||||
return DateFormat
|
return DateFormat
|
||||||
|
|
|
@ -46,8 +46,14 @@
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface enabling to run tests repeatedly
|
||||||
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ java.lang.annotation.ElementType.METHOD })
|
@Target({ java.lang.annotation.ElementType.METHOD })
|
||||||
public @interface Repeat {
|
public @interface Repeat {
|
||||||
|
/**
|
||||||
|
* Number of repetitions
|
||||||
|
*/
|
||||||
public abstract int n();
|
public abstract int n();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,8 @@
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link TestRule} which enables to run the same JUnit test repeatedly. Add
|
* {@link org.junit.rules.TestRule} which enables to run the same JUnit test
|
||||||
* this rule to the test class
|
* repeatedly. Add this rule to the test class
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* public class MyTest {
|
* public class MyTest {
|
||||||
|
@ -118,6 +118,7 @@ public void evaluate() throws Throwable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public Statement apply(Statement statement, Description description) {
|
public Statement apply(Statement statement, Description description) {
|
||||||
Statement result = statement;
|
Statement result = statement;
|
||||||
|
|
|
@ -84,6 +84,13 @@
|
||||||
* repositories and destroying them when the tests are finished.
|
* repositories and destroying them when the tests are finished.
|
||||||
*/
|
*/
|
||||||
public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
|
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)
|
protected static void copyFile(final File src, final File dst)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final FileInputStream fis = new FileInputStream(src);
|
final FileInputStream fis = new FileInputStream(src);
|
||||||
|
@ -103,6 +110,14 @@ protected static void copyFile(final File src, final File dst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a trash file
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param data
|
||||||
|
* @return the trash file
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
protected File writeTrashFile(final String name, final String data)
|
protected File writeTrashFile(final String name, final String data)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return JGitTestUtil.writeTrashFile(db, name, data);
|
return JGitTestUtil.writeTrashFile(db, name, data);
|
||||||
|
@ -124,24 +139,62 @@ protected Path writeLink(final String link, final String target)
|
||||||
return JGitTestUtil.writeLink(db, link, target);
|
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,
|
protected File writeTrashFile(final String subdir, final String name,
|
||||||
final String data)
|
final String data)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return JGitTestUtil.writeTrashFile(db, subdir, name, data);
|
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 {
|
protected String read(final String name) throws IOException {
|
||||||
return JGitTestUtil.read(db, name);
|
return JGitTestUtil.read(db, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if file exists
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* file name
|
||||||
|
* @return if the file exists
|
||||||
|
*/
|
||||||
protected boolean check(final String name) {
|
protected boolean check(final String name) {
|
||||||
return JGitTestUtil.check(db, name);
|
return JGitTestUtil.check(db, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a trash file
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* file name
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
protected void deleteTrashFile(final String name) throws IOException {
|
protected void deleteTrashFile(final String name) throws IOException {
|
||||||
JGitTestUtil.deleteTrashFile(db, name);
|
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)
|
protected static void checkFile(File f, final String checkData)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Reader r = new InputStreamReader(new FileInputStream(f), "UTF-8");
|
Reader r = new InputStreamReader(new FileInputStream(f), "UTF-8");
|
||||||
|
@ -161,6 +214,7 @@ protected static void checkFile(File f, final String checkData)
|
||||||
/** Working directory of {@link #db}. */
|
/** Working directory of {@link #db}. */
|
||||||
protected File trash;
|
protected File trash;
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -220,8 +274,8 @@ public String indexState(int includedOptions)
|
||||||
* have an index which matches their prepared content.
|
* have an index which matches their prepared content.
|
||||||
*
|
*
|
||||||
* @param treeItr
|
* @param treeItr
|
||||||
* a {@link FileTreeIterator} which determines which files should
|
* a {@link org.eclipse.jgit.treewalk.FileTreeIterator} which
|
||||||
* go into the new index
|
* determines which files should go into the new index
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@ -261,13 +315,13 @@ protected void resetIndex(FileTreeIterator treeItr)
|
||||||
*
|
*
|
||||||
* @param l
|
* @param l
|
||||||
* the object to lookup
|
* the object to lookup
|
||||||
|
* @param lookupTable
|
||||||
|
* a table storing object-name mappings.
|
||||||
* @param nameTemplate
|
* @param nameTemplate
|
||||||
* the name for that object. Can contain "%n" which will be
|
* the name for that object. Can contain "%n" which will be
|
||||||
* replaced by a running number before used as a name. If the
|
* replaced by a running number before used as a name. If the
|
||||||
* lookup table already contains the object this parameter will
|
* lookup table already contains the object this parameter will
|
||||||
* be ignored
|
* be ignored
|
||||||
* @param lookupTable
|
|
||||||
* a table storing object-name mappings.
|
|
||||||
* @return a name of that object. Is not guaranteed to be unique. Use
|
* @return a name of that object. Is not guaranteed to be unique. Use
|
||||||
* nameTemplates containing "%n" to always have unique names
|
* nameTemplates containing "%n" to always have unique names
|
||||||
*/
|
*/
|
||||||
|
@ -288,7 +342,7 @@ public static String lookup(Object l, String nameTemplate,
|
||||||
* @param str
|
* @param str
|
||||||
* the string in which backslashes should be replaced
|
* the string in which backslashes should be replaced
|
||||||
* @return the resulting string with slashes
|
* @return the resulting string with slashes
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
*/
|
*/
|
||||||
public static String slashify(String str) {
|
public static String slashify(String str) {
|
||||||
str = str.replace('\\', '/');
|
str = str.replace('\\', '/');
|
||||||
|
@ -335,6 +389,13 @@ public static long fsTick(File lastFile) throws InterruptedException,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a branch
|
||||||
|
*
|
||||||
|
* @param objectId
|
||||||
|
* @param branchName
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
protected void createBranch(ObjectId objectId, String branchName)
|
protected void createBranch(ObjectId objectId, String branchName)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
RefUpdate updateRef = db.updateRef(branchName);
|
RefUpdate updateRef = db.updateRef(branchName);
|
||||||
|
@ -342,6 +403,13 @@ protected void createBranch(ObjectId objectId, String branchName)
|
||||||
updateRef.update();
|
updateRef.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checkout a branch
|
||||||
|
*
|
||||||
|
* @param branchName
|
||||||
|
* @throws IllegalStateException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
protected void checkoutBranch(String branchName)
|
protected void checkoutBranch(String branchName)
|
||||||
throws IllegalStateException, IOException {
|
throws IllegalStateException, IOException {
|
||||||
try (RevWalk walk = new RevWalk(db)) {
|
try (RevWalk walk = new RevWalk(db)) {
|
||||||
|
@ -429,15 +497,39 @@ else if (empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create <code>DirCacheEntry</code>
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* @param mode
|
||||||
|
* @return the DirCacheEntry
|
||||||
|
*/
|
||||||
protected DirCacheEntry createEntry(final String path, final FileMode mode) {
|
protected DirCacheEntry createEntry(final String path, final FileMode mode) {
|
||||||
return createEntry(path, mode, DirCacheEntry.STAGE_0, path);
|
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,
|
protected DirCacheEntry createEntry(final String path, final FileMode mode,
|
||||||
final String content) {
|
final String content) {
|
||||||
return createEntry(path, mode, DirCacheEntry.STAGE_0, 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,
|
protected DirCacheEntry createEntry(final String path, final FileMode mode,
|
||||||
final int stage, final String content) {
|
final int stage, final String content) {
|
||||||
final DirCacheEntry entry = new DirCacheEntry(path, stage);
|
final DirCacheEntry entry = new DirCacheEntry(path, stage);
|
||||||
|
@ -449,6 +541,13 @@ protected DirCacheEntry createEntry(final String path, final FileMode mode,
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert files are equal
|
||||||
|
*
|
||||||
|
* @param expected
|
||||||
|
* @param actual
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
public static void assertEqualsFile(File expected, File actual)
|
public static void assertEqualsFile(File expected, File actual)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
assertEquals(expected.getCanonicalFile(), actual.getCanonicalFile());
|
assertEquals(expected.getCanonicalFile(), actual.getCanonicalFile());
|
||||||
|
|
|
@ -47,30 +47,38 @@
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.ProgressMonitor;
|
import org.eclipse.jgit.lib.ProgressMonitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strict work monitor
|
||||||
|
*/
|
||||||
public final class StrictWorkMonitor implements ProgressMonitor {
|
public final class StrictWorkMonitor implements ProgressMonitor {
|
||||||
private int lastWork, totalWork;
|
private int lastWork, totalWork;
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void start(int totalTasks) {
|
public void start(int totalTasks) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void beginTask(String title, int total) {
|
public void beginTask(String title, int total) {
|
||||||
this.totalWork = total;
|
this.totalWork = total;
|
||||||
lastWork = 0;
|
lastWork = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void update(int completed) {
|
public void update(int completed) {
|
||||||
lastWork += completed;
|
lastWork += completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void endTask() {
|
public void endTask() {
|
||||||
assertEquals("Units of work recorded", totalWork, lastWork);
|
assertEquals("Units of work recorded", totalWork, lastWork);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -114,12 +114,16 @@
|
||||||
*/
|
*/
|
||||||
public class TestRepository<R extends Repository> {
|
public class TestRepository<R extends Repository> {
|
||||||
|
|
||||||
|
/** Constant <code>AUTHOR="J. Author"</code> */
|
||||||
public static final String AUTHOR = "J. Author";
|
public static final String AUTHOR = "J. Author";
|
||||||
|
|
||||||
|
/** Constant <code>AUTHOR_EMAIL="jauthor@example.com"</code> */
|
||||||
public static final String AUTHOR_EMAIL = "jauthor@example.com";
|
public static final String AUTHOR_EMAIL = "jauthor@example.com";
|
||||||
|
|
||||||
|
/** Constant <code>COMMITTER="J. Committer"</code> */
|
||||||
public static final String COMMITTER = "J. Committer";
|
public static final String COMMITTER = "J. Committer";
|
||||||
|
|
||||||
|
/** Constant <code>COMMITTER_EMAIL="jcommitter@example.com"</code> */
|
||||||
public static final String COMMITTER_EMAIL = "jcommitter@example.com";
|
public static final String COMMITTER_EMAIL = "jcommitter@example.com";
|
||||||
|
|
||||||
private final PersonIdent defaultAuthor;
|
private final PersonIdent defaultAuthor;
|
||||||
|
@ -186,25 +190,38 @@ public TestRepository(R db, RevWalk rw, MockSystemReader reader)
|
||||||
defaultCommitter = new PersonIdent(COMMITTER, COMMITTER_EMAIL, now, tz);
|
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() {
|
public R getRepository() {
|
||||||
return db;
|
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() {
|
public RevWalk getRevWalk() {
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return Git API wrapper
|
||||||
|
*
|
||||||
* @return an API wrapper for the underlying repository. This wrapper does
|
* @return an API wrapper for the underlying repository. This wrapper does
|
||||||
* not allocate any new resources and need not be closed (but closing
|
* not allocate any new resources and need not be closed (but
|
||||||
* it is harmless). */
|
* closing it is harmless).
|
||||||
|
*/
|
||||||
public Git git() {
|
public Git git() {
|
||||||
return git;
|
return git;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get date
|
||||||
|
*
|
||||||
* @return current date.
|
* @return current date.
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
*/
|
*/
|
||||||
|
@ -212,7 +229,11 @@ public Date getDate() {
|
||||||
return new Date(mockSystemReader.getCurrentTime());
|
return new Date(mockSystemReader.getCurrentTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return timezone used for default identities. */
|
/**
|
||||||
|
* Get timezone
|
||||||
|
*
|
||||||
|
* @return timezone used for default identities.
|
||||||
|
*/
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
return mockSystemReader.getTimeZone();
|
return mockSystemReader.getTimeZone();
|
||||||
}
|
}
|
||||||
|
@ -424,7 +445,11 @@ public RevCommit commit(final int secDelta, final RevTree tree,
|
||||||
return pool.lookupCommit(id);
|
return pool.lookupCommit(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return a new commit builder. */
|
/**
|
||||||
|
* Create commit builder
|
||||||
|
*
|
||||||
|
* @return a new commit builder.
|
||||||
|
*/
|
||||||
public CommitBuilder commit() {
|
public CommitBuilder commit() {
|
||||||
return new CommitBuilder();
|
return new CommitBuilder();
|
||||||
}
|
}
|
||||||
|
@ -618,7 +643,7 @@ private static String normalizeRef(String ref) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Soft-reset HEAD to a detached state.
|
* Soft-reset HEAD to a detached state.
|
||||||
* <p>
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* ID of detached head.
|
* ID of detached head.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -758,7 +783,8 @@ protected void writeFile(final String name, final byte[] bin)
|
||||||
* Ensure the body of the given object has been parsed.
|
* Ensure the body of the given object has been parsed.
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @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
|
* @param object
|
||||||
* reference to the (possibly unparsed) object to force body
|
* reference to the (possibly unparsed) object to force body
|
||||||
* parsing of.
|
* parsing of.
|
||||||
|
|
|
@ -43,7 +43,9 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.junit;
|
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 {
|
public class TestRng {
|
||||||
private int next;
|
private int next;
|
||||||
|
|
||||||
|
@ -74,6 +76,8 @@ public byte[] nextBytes(final int cnt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Next int
|
||||||
|
*
|
||||||
* @return the next random integer.
|
* @return the next random integer.
|
||||||
*/
|
*/
|
||||||
public int nextInt() {
|
public int nextInt() {
|
||||||
|
|
|
@ -50,7 +50,8 @@
|
||||||
import org.eclipse.jgit.util.time.ProposedTimestamp;
|
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
|
* @since 4.6
|
||||||
*/
|
*/
|
||||||
|
@ -72,6 +73,7 @@ public void tick(long add, TimeUnit unit) {
|
||||||
now += unit.toMillis(add);
|
now += unit.toMillis(add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public ProposedTimestamp propose() {
|
public ProposedTimestamp propose() {
|
||||||
long t = now++;
|
long t = now++;
|
||||||
|
|
Loading…
Reference in New Issue