java.lang.Object
org.eclipse.jgit.junit.JGitTestUtil
Abstract test util class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstantCLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/" -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertEquals(byte[] exp, byte[] act) Assert byte arrays are equalstatic booleanCheck if file existsstatic byte[]concat(byte[]... b) Concatenate byte arrays.static voidcopyTestResource(String name, File dest) Copy test resource.static voiddeleteTrashFile(org.eclipse.jgit.lib.Repository db, String name) Delete a trash file.static StringgetName()Get name of current test by inspecting stack tracestatic FilegetTestResourceFile(String fileName) Get test resource file.static StringFully read a UTF-8 file and return as a string.static StringRead a file's contentstatic voidWrite a string as a UTF-8 file.static PathWrite a symbolic linkstatic FilewriteTrashFile(org.eclipse.jgit.lib.Repository db, String name, String data) Write a trash file.static FilewriteTrashFile(org.eclipse.jgit.lib.Repository db, String subdir, String name, String data) Write a trash file.
-
Field Details
-
CLASSPATH_TO_RESOURCES
ConstantCLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"- See Also:
-
-
Method Details
-
getName
Get name of current test by inspecting stack trace- Returns:
- the name
-
assertEquals
public static void assertEquals(byte[] exp, byte[] act) Assert byte arrays are equal- Parameters:
exp- expected valueact- actual value
-
getTestResourceFile
Get test resource file.- Parameters:
fileName- file name- Returns:
- the test resource file
-
copyTestResource
Copy test resource.- Parameters:
name- resource namedest- destination file- Throws:
IOException- if an IO error occurred
-
writeTrashFile
public static File writeTrashFile(org.eclipse.jgit.lib.Repository db, String name, String data) throws IOException Write a trash file.- Parameters:
db- the repositoryname- file namedata- file content- Returns:
- the trash file
- Throws:
IOException- if an IO error occurred
-
writeTrashFile
public static File writeTrashFile(org.eclipse.jgit.lib.Repository db, String subdir, String name, String data) throws IOException Write a trash file.- Parameters:
db- the repositorysubdir- under working treename- file namedata- file content- Returns:
- the trash file
- Throws:
IOException- if an IO error occurred
-
write
Write a string as a UTF-8 file.- Parameters:
f- file to write the string to. Caller is responsible for making sure it is in the trash directory or will otherwise be cleaned up at the end of the test. If the parent directory does not exist, the missing parent directories are automatically created.body- content to write to the file.- Throws:
IOException- the file could not be written.
-
read
Fully read a UTF-8 file and return as a string.- Parameters:
file- file to read the content of.- Returns:
- UTF-8 decoded content of the file, empty string if the file exists but has no content.
- Throws:
IOException- the file does not exist, or could not be read.
-
read
Read a file's content- Parameters:
db- the repositoryname- file name- Returns:
- the content of the file
- Throws:
IOException- if an IO error occurred
-
check
Check if file exists- Parameters:
db- the repositoryname- name of the file- Returns:
trueif the file exists
-
deleteTrashFile
public static void deleteTrashFile(org.eclipse.jgit.lib.Repository db, String name) throws IOException Delete a trash file.- Parameters:
db- the repositoryname- file name- Throws:
IOException- if an IO error occurred
-
writeLink
public static Path writeLink(org.eclipse.jgit.lib.Repository db, String link, String target) throws Exception Write a symbolic link- Parameters:
db- the repositorylink- the path of the symbolic link to createtarget- the target of the symbolic link- Returns:
- the path to the symbolic link
- Throws:
Exception- if an error occurred- Since:
- 4.2
-
concat
public static byte[] concat(byte[]... b) Concatenate byte arrays.- Parameters:
b- byte arrays to combine together.- Returns:
- a single byte array that contains all bytes copied from input byte arrays.
- Since:
- 4.9
-