Class JGitTestUtil


  • public abstract class JGitTestUtil
    extends Object
    Abstract test util class
    • Field Detail

      • CLASSPATH_TO_RESOURCES

        public static final String CLASSPATH_TO_RESOURCES
        Constant CLASSPATH_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 value
        act - 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
      • 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.
      • 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
      • writeLink

        public static Path writeLink​(Repository db,
                                     String link,
                                     String target)
                              throws Exception
        Write a symbolic link
        Parameters:
        db - the repository
        link - the path of the symbolic link to create
        target - 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