Class JGitTestUtil

java.lang.Object
org.eclipse.jgit.junit.JGitTestUtil

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

    • CLASSPATH_TO_RESOURCES

      public static final String CLASSPATH_TO_RESOURCES
      Constant CLASSPATH_TO_RESOURCES="org/eclipse/jgit/test/resources/"
      See Also:
  • Constructor Details

    • JGitTestUtil

      private JGitTestUtil()
  • Method Details

    • 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
    • s

      private static String s(byte[] raw)
    • 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
    • cl

      private static ClassLoader cl()
    • 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 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