Class JGitTestUtil


  • public abstract class JGitTestUtil
    extends java.lang.Object
    Abstract test util class
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CLASSPATH_TO_RESOURCES
      Constant CLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private JGitTestUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertEquals​(byte[] exp, byte[] act)
      Assert byte arrays are equal
      static boolean check​(Repository db, java.lang.String name)
      Check if file exists
      private static java.lang.ClassLoader cl()  
      static byte[] concat​(byte[]... b)
      Concatenate byte arrays.
      static void copyTestResource​(java.lang.String name, java.io.File dest)
      Copy test resource.
      static void deleteTrashFile​(Repository db, java.lang.String name)
      Delete a trash file.
      static java.lang.String getName()
      Get name of current test by inspecting stack trace
      static java.io.File getTestResourceFile​(java.lang.String fileName)
      Get test resource file.
      static java.lang.String read​(java.io.File file)
      Fully read a UTF-8 file and return as a string.
      static java.lang.String read​(Repository db, java.lang.String name)
      Read a file's content
      private static java.lang.String s​(byte[] raw)  
      static void write​(java.io.File f, java.lang.String body)
      Write a string as a UTF-8 file.
      static java.nio.file.Path writeLink​(Repository db, java.lang.String link, java.lang.String target)
      Write a symbolic link
      static java.io.File writeTrashFile​(Repository db, java.lang.String name, java.lang.String data)
      Write a trash file.
      static java.io.File writeTrashFile​(Repository db, java.lang.String subdir, java.lang.String name, java.lang.String data)
      Write a trash file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CLASSPATH_TO_RESOURCES

        public static final java.lang.String CLASSPATH_TO_RESOURCES
        Constant CLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"
        See Also:
        Constant Field Values
    • Constructor Detail

      • JGitTestUtil

        private JGitTestUtil()
    • 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 value
        act - 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.IOException
        Copy 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.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:
        java.io.IOException - the file could not be written.
      • read

        public static java.lang.String read​(java.io.File file)
                                     throws java.io.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:
        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:
        true if 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 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:
        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