Package org.eclipse.jgit.junit
Class JGitTestUtil
- java.lang.Object
-
- org.eclipse.jgit.junit.JGitTestUtil
-
public abstract class JGitTestUtil extends java.lang.ObjectAbstract test util class
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classJGitTestUtil.GatherStackTrace
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASSPATH_TO_RESOURCESConstantCLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"
-
Constructor Summary
Constructors Modifier Constructor Description privateJGitTestUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertEquals(byte[] exp, byte[] act)Assert byte arrays are equalstatic booleancheck(Repository db, java.lang.String name)Check if file existsprivate static java.lang.ClassLoadercl()static byte[]concat(byte[]... b)Concatenate byte arrays.static voidcopyTestResource(java.lang.String name, java.io.File dest)Copy test resource.static voiddeleteTrashFile(Repository db, java.lang.String name)Delete a trash file.static java.lang.StringgetName()Get name of current test by inspecting stack tracestatic java.io.FilegetTestResourceFile(java.lang.String fileName)Get test resource file.static java.lang.Stringread(java.io.File file)Fully read a UTF-8 file and return as a string.static java.lang.Stringread(Repository db, java.lang.String name)Read a file's contentprivate static java.lang.Strings(byte[] raw)static voidwrite(java.io.File f, java.lang.String body)Write a string as a UTF-8 file.static java.nio.file.PathwriteLink(Repository db, java.lang.String link, java.lang.String target)Write a symbolic linkstatic java.io.FilewriteTrashFile(Repository db, java.lang.String name, java.lang.String data)Write a trash file.static java.io.FilewriteTrashFile(Repository db, java.lang.String subdir, java.lang.String name, java.lang.String data)Write a trash file.
-
-
-
Field Detail
-
CLASSPATH_TO_RESOURCES
public static final java.lang.String CLASSPATH_TO_RESOURCES
ConstantCLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public static java.lang.String 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
-
s
private static java.lang.String s(byte[] raw)
-
getTestResourceFile
public static java.io.File getTestResourceFile(java.lang.String fileName)
Get test resource file.- Parameters:
fileName-- Returns:
- the test resource file
-
copyTestResource
public static void copyTestResource(java.lang.String name, java.io.File dest) throws java.io.IOExceptionCopy test resource.- Parameters:
name-dest-- Throws:
java.io.IOException
-
cl
private static java.lang.ClassLoader cl()
-
writeTrashFile
public static java.io.File writeTrashFile(Repository db, java.lang.String name, java.lang.String data) throws java.io.IOException
Write a trash file.- Parameters:
db-name-data-- Returns:
- the trash file
- Throws:
java.io.IOException
-
writeTrashFile
public static java.io.File writeTrashFile(Repository db, java.lang.String subdir, java.lang.String name, java.lang.String data) throws java.io.IOException
Write a trash file.- Parameters:
db-subdir-name-data-- Returns:
- the trash file
- Throws:
java.io.IOException
-
write
public static void write(java.io.File f, java.lang.String body) throws java.io.IOExceptionWrite 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:
java.io.IOException- the file could not be written.
-
read
public static java.lang.String read(java.io.File file) throws java.io.IOExceptionFully 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:
java.io.IOException- the file does not exist, or could not be read.
-
read
public static java.lang.String read(Repository db, java.lang.String name) throws java.io.IOException
Read a file's content- Parameters:
db-name-- Returns:
- the content of the file
- Throws:
java.io.IOException
-
check
public static boolean check(Repository db, java.lang.String name)
Check if file exists- Parameters:
db-name- name of the file- Returns:
trueif the file exists
-
deleteTrashFile
public static void deleteTrashFile(Repository db, java.lang.String name) throws java.io.IOException
Delete a trash file.- Parameters:
db-name-- Throws:
java.io.IOException
-
writeLink
public static java.nio.file.Path writeLink(Repository db, java.lang.String link, java.lang.String target) throws java.lang.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:
java.lang.Exception- 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
-
-