Package org.eclipse.jgit.junit
Class JGitTestUtil
- java.lang.Object
-
- org.eclipse.jgit.junit.JGitTestUtil
-
public abstract class JGitTestUtil extends Object
Abstract test util class
-
-
Field Summary
Fields Modifier and Type Field Description static String
CLASSPATH_TO_RESOURCES
ConstantCLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertEquals(byte[] exp, byte[] act)
Assert byte arrays are equalstatic boolean
check(Repository db, String name)
Check if file existsstatic byte[]
concat(byte[]... b)
Concatenate byte arrays.static void
copyTestResource(String name, File dest)
Copy test resource.static void
deleteTrashFile(Repository db, String name)
Delete a trash file.static String
getName()
Get name of current test by inspecting stack tracestatic File
getTestResourceFile(String fileName)
Get test resource file.static String
read(File file)
Fully read a UTF-8 file and return as a string.static String
read(Repository db, String name)
Read a file's contentstatic void
write(File f, String body)
Write a string as a UTF-8 file.static Path
writeLink(Repository db, String link, String target)
Write a symbolic linkstatic File
writeTrashFile(Repository db, String name, String data)
Write a trash file.static File
writeTrashFile(Repository db, String subdir, String name, String data)
Write a trash file.
-
-
-
Field Detail
-
CLASSPATH_TO_RESOURCES
public static final String CLASSPATH_TO_RESOURCES
ConstantCLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public static 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
-
getTestResourceFile
public static File getTestResourceFile(String fileName)
Get test resource file.- Parameters:
fileName
-- Returns:
- the test resource file
-
copyTestResource
public static void copyTestResource(String name, File dest) throws IOException
Copy test resource.- Parameters:
name
-dest
-- Throws:
IOException
-
writeTrashFile
public static File writeTrashFile(Repository db, String name, String data) throws IOException
Write a trash file.- Parameters:
db
-name
-data
-- Returns:
- the trash file
- Throws:
IOException
-
writeTrashFile
public static File writeTrashFile(Repository db, String subdir, String name, String data) throws IOException
Write a trash file.- Parameters:
db
-subdir
-name
-data
-- Returns:
- the trash file
- Throws:
IOException
-
write
public static void write(File f, String body) throws IOException
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
public static String read(File file) throws IOException
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
public static String read(Repository db, String name) throws IOException
Read a file's content- Parameters:
db
-name
-- Returns:
- the content of the file
- Throws:
IOException
-
check
public static boolean check(Repository db, String name)
Check if file exists- Parameters:
db
-name
- name of the file- Returns:
true
if the file exists
-
deleteTrashFile
public static void deleteTrashFile(Repository db, String name) throws IOException
Delete a trash file.- Parameters:
db
-name
-- Throws:
IOException
-
writeLink
public static Path writeLink(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
- 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
-
-