Class TestSupport

java.lang.Object
io.permazen.test.TestSupport
Direct Known Subclasses:
KVTestSupport

public abstract class TestSupport extends Object
Base class for unit tests providing logging and random seed setup.
  • Field Details

    • log

      protected final Logger log
    • validator

      protected jakarta.validation.Validator validator
    • random

      protected Random random
  • Constructor Details

    • TestSupport

      public TestSupport()
  • Method Details

    • setUpValidator

      @BeforeClass public void setUpValidator()
    • seedRandom

      @BeforeClass public void seedRandom(String randomSeed)
    • createTempDirectory

      protected File createTempDirectory() throws IOException
      Throws:
      IOException
    • deleteDirectoryHierarchy

      protected void deleteDirectoryHierarchy(File root) throws IOException
      Throws:
      IOException
    • getRandom

      public static Random getRandom(String randomSeed)
    • checkValid

      protected <T> Set<jakarta.validation.ConstraintViolation<T>> checkValid(T object, boolean valid)
    • readResource

      protected String readResource(File file)
      Read some file in as a UTF-8 encoded string.
      Parameters:
      file - file to read
      Returns:
      file content
    • readResource

      protected String readResource(String path)
      Read some classpath resource in as a UTF-8 encoded string.
      Parameters:
      path - classpath resource
      Returns:
      file content
    • readResource

      protected String readResource(URL url)
      Read some URL resource in as a UTF-8 encoded string.
      Parameters:
      url - resource URL
      Returns:
      resource content
    • checkSet

      public static void checkSet(Set actual, Set expected)
    • checkMap

      public static void checkMap(Map actual, Map expected)
    • assertEquals

      public static void assertEquals(float[] a1, float[] a2, String message)
    • assertEquals

      public static void assertEquals(double[] a1, double[] a2, String message)
    • buildSet

      public static Set buildSet(Object... items)
    • buildSortedSet

      public static SortedSet buildSortedSet(Object... items)
    • buildList

      public static List buildList(Object... items)
    • buildMap

      public static Map buildMap(Object... kv)
    • buildSortedMap

      public static SortedMap buildSortedMap(Object... kv)
    • show

      protected String show(Throwable t)
    • randomBytes

      protected byte[] randomBytes(boolean allowNull)
    • randomBytes

      protected byte[] randomBytes(int minLength, int maxLength, boolean allowNull)
    • ba

      protected static byte[][] ba(String... sa)
    • b

      protected static byte[] b(String s)
    • s

      protected static String s(byte[] b)
    • assertSameOrDiff

      protected void assertSameOrDiff(String expected, String actual)
    • diff

      protected String diff(String s1, String s2)
      Run diff(1) on two strings.
      Parameters:
      s1 - first string
      s2 - second string
      Returns:
      the diff, or null if strings are the same