Class TestHelper

java.lang.Object
de.xima.fc.testhelper.TestHelper

public final class TestHelper extends Object
Helper with static utility functions for writing tests.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static javax.mail.internet.InternetAddress[]
    addr(String... addresses)
    Parses the given strings into InternetAddress instances.
    static <T> T[]
    array(T... items)
    Shortcut for creating an array of items.
    static <T extends Comparable<T>>
    void
    assertAfter(T expected, T actual)
    Asserts that the given value is after the expected value (i.e. greater than the expected value).
    static <T extends Comparable<T>>
    void
    assertBefore(T expected, T actual)
    Asserts that the given value is before the expected value (i.e. less than the expected value).
    static <T extends Comparable<T>>
    void
    assertBetween(T expectedFrom, T expecterAfter, T actual)
    Asserts that the given value is between the expected from and expected after values (i.e. greater than the expected from value and less than the expected after value).
    static void
    Asserts that the given string is blank.
    static void
    assertContains(Iterable<?> expected, Iterable<?> actual)
    Asserts actual items contain the expected items.
    static void
    assertContains(String expectedContent, String value)
    Asserts that the given string contains the expected content.
    static void
    Asserts the given value is a map entry and that the expected map contains a key-value pair with the same key and value.
    static void
    assertContainsValuesAtKeys(Set<?> expectedKeys, Set<?> expectedValues, Object actual)
    Asserts that the given value is a Map and that it contains the expected keys and values.
    static void
    assertEmpty(Iterable<?> actual)
    Asserts that the given iterable is empty.
    static void
    Asserts that the given string is empty.
    static void
    assertEndsWith(String expectedSuffix, String actual)
    Asserts that the given string ends with the expected suffix.
    static void
    assertEqualsAsJson(Object expected, Object actual)
    Serializes both objects to JSON, then structurally compares those JSON values.
    static void
    assertEqualsAsJson(Object expected, Object actual, String message)
    Serializes both objects to JSON, then structurally compares those JSON values.
    static void
    Asserts that the actual value is equal to the expected value, ignoring the case.
    static void
    Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
    static void
    assertFullyConformingHtml(String html, de.xima.nu_validator.wrapper.bridge.api.INuValidator validator)
    Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
    static void
    assertFullyConformingHtml(String html, de.xima.nu_validator.wrapper.bridge.api.INuValidator validator, Consumer<de.xima.nu_validator.wrapper.common.api.INuValidatorOptionsBuilder> configurator)
    Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
    static void
    assertFullyConformingHtml(String html, Consumer<de.xima.nu_validator.wrapper.common.api.INuValidatorOptionsBuilder> configurator)
    Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
    static void
    assertHasLength(int expectedLength, CharSequence value)
    Asserts the given string has the expected length.
    static <T> T
    Asserts that the given iterable has exactly one item, and returns that item.
    static void
    assertHasSize(int expectedSize, Collection<?> actualCollection)
    Asserts the given collection has the expected size.
    static void
    assertInRange(com.google.common.collect.Range<Double> expected, double actual)
    Asserts that the actual numerical value is within the expected range.
    static void
    assertInRange(com.google.common.collect.Range<Float> expected, float actual)
    Asserts that the actual numerical value is within the expected range.
    static void
    assertInRange(com.google.common.collect.Range<Integer> expected, int actual)
    Asserts that the actual numerical value is within the expected range.
    static void
    assertInRange(com.google.common.collect.Range<Long> expected, long actual)
    Asserts that the actual numerical value is within the expected range.
    static <T> Class<? extends T>
    assertIsAssignableFrom(Class<T> expectedType, Class<?> actualType)
    Asserts that the actual type is assignable to the expected type.
    static <T> T
    assertIsInstance(Class<T> clazz, Object item)
    Deprecated.
    Use Assertions.assertInstanceOf(Class, Object).
    static <T extends Throwable>
    T
    assertIsOrHasCause(Class<T> expectedType, Throwable actual)
    Asserts that the given throwable is of the given type or has a throwable of that type somewhere in its chain of causes.
    static <T extends Throwable>
    T
    assertIsOrHasCause(Throwable actual, Class<T> expectedType)
    static void
    assertLengthGreaterThan(int expectedMinLength, CharSequence value)
    Asserts that the given string's length is greater than the expected minimum length.
    static void
    assertLinesEqual(String expected, String actual)
    Splits both strings into lines, trims them, and compares them line by line.
    static String
    assertMessageContains(String expectedContent, Throwable throwable)
    Asserts that the given throwable's message contains the expected content, and returns the message.
    static void
    assertNoneEquals(Iterable<?> unexpected, Object actual)
    Asserts that the actual item is not equal to any of the unexpected items.
    static void
    Asserts that the given string is blank.
    static void
    assertNotContains(Iterable<?> unexpected, Iterable<?> actual)
    Asserts that the actual items do not contain the unexpected items.
    static void
    assertNotEmpty(byte[] value)
    Asserts that the given byte array is not null and not empty.
    static void
    assertNotEmpty(byte[] value, String message)
    Asserts that the given byte array is not null and not empty.
    static void
    assertSameItems(Object expected, Object actual)
    Asserts that both given values are collections with the same items, regardless of the order.
    static void
    assertSetEquals(Iterable<?> expected, Iterable<?> actual)
    Asserts that both iterables contain the same items, regardless of the order.
    static void
    assertStartsWith(String expectedPrefix, String actual)
    Asserts that the given string starts with the expected prefix.
    static void
    assertStreamEquals(byte[] expected, InputStream actual)
    Asserts that the data from the given input stream equals the expected data.
    static void
    assertStreamEquals(InputStream expected, byte[] actual)
    Asserts that the data from the given input stream equals the expected data.
    static void
    Asserts that the data from the given input stream equals the expected data.
    static void
    assertStreamEquals(Reader expected, Reader actual)
    Asserts that the data from the given reader equals the expected data.
    static <T extends Throwable>
    T
    assertThrows(Class<T> expectedType, org.junit.jupiter.api.function.Executable executable)
    Asserts that the given executable throws a throwable of the expected type.
    static Throwable
    assertThrows(org.junit.jupiter.api.function.Executable executable)
    Asserts that the given executable throws any throwable.
    static void
    assertZipContent(String expectedContent, Map<String,byte[]> zip, String path)
    Asserts that the given zip content contains a file with the given path and that the content of that file equals the expected content.
    static byte[]
    Reads a resource from the class path as binary data.
    static String
    Reads a resource from the class path as a plain text string, using UTF-8 encoding.
    static File
    Creates a temporary directory.
    static File
    createTmpFile(byte[] content, String fileName, String extension)
    Creates a file in the temp folder with the specified content
    static File
    createTmpFile(String content, String fileName, String extension)
    Creates a file in the temp folder with the specified content
    static File
    Creates a file in the temp folder with the specified content
    static com.alibaba.fastjson.JSONObject
    getZipContentAsJson(Map<String,byte[]> exportContent, String path)
     
    static String
    getZipContentAsText(Map<String,byte[]> exportContent, String path)
     
    static <T> List<T>
    list(T... items)
    Shortcut for creating a list of items.
    static <T> List<T[]>
    listOfArrays(T[]... items)
    Creates a list of arrays from the given arrays.
    static List<de.xima.mailserver.api.IMailMessage>
    mailsSorted(de.xima.mailserver.api.IMailInbox mailbox)
    Gets all mails from the given inbox, sorted by recipient.
    static <K,V> Map<K,V>
    map(Object... items)
    Shortcut for creating a map with arbitrary key-value pairs.
    static IUser
    static <K,V> Map<K,V>
    orderedMap(Object... items)
    Same as map(Object...), but uses a LinkedHashMap implementation that preserves the order of the key-value pairs.
    static int
    Finds a random port that is not in use by the current operating system.
    readBufferedImage(byte[] data, String formatName)
    Reads a buffered image from the given byte array using the given format name.
    static <T> Set<T>
    set(T... items)
    Shortcut for creating a set of items.
    static String
    str(byte[] bytes)
    Decodes the given byte array to a string using UTF-8 encoding.
    static <K,V> Map<K,V>
    submap(Map<K,V> map, Iterable<?> keys)
    Creates a map with the data from the given map, but limited to the given keys.
    static <K,V> Map<K,V>
    submap(Map<K,V> map, K... keys)
    Creates a map with the data from the given map, but limited to the given keys.
    static Map<String,byte[]>
    unzipInMemory(byte[] zipFile)
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    unzipInMemory(byte[] zipFile, String password)
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    unzipInMemory(File zipFile, String password)
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    unzipInMemory(InputStream zipFile, String password)
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
    static Map<String,byte[]>
    unzipInMemory(Path zipFile, String password)
    Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TestHelper

      public TestHelper()
  • Method Details

    • addr

      public static javax.mail.internet.InternetAddress[] addr(String... addresses)
      Parses the given strings into InternetAddress instances. The strings may contain multiple addresses separated by commas. The addresses are sorted by their string representation.
      Parameters:
      addresses - Addresses to parse.
      Returns:
      An array of InternetAddress instances.
    • array

      @SafeVarargs public static <T> T[] array(T... items)
      Shortcut for creating an array of items.
      Type Parameters:
      T - Type of the items.
      Parameters:
      items - Items to be added to the array.
      Returns:
      An array with the items.
    • assertAfter

      public static <T extends Comparable<T>> void assertAfter(T expected, T actual)
      Asserts that the given value is after the expected value (i.e. greater than the expected value).
      Parameters:
      expected - The expected value that should be before the actual value.
      actual - The actual value that should be after the expected value.
    • assertBefore

      public static <T extends Comparable<T>> void assertBefore(T expected, T actual)
      Asserts that the given value is before the expected value (i.e. less than the expected value).
      Parameters:
      expected - The expected value that should be after the actual value.
      actual - The actual value that should be before the expected value.
    • assertBetween

      public static <T extends Comparable<T>> void assertBetween(T expectedFrom, T expecterAfter, T actual)
      Asserts that the given value is between the expected from and expected after values (i.e. greater than the expected from value and less than the expected after value).
      Parameters:
      expectedFrom - The expected value that should be before the actual value.
      expecterAfter - The expected value that should be after the actual value.
      actual - The actual value that should be between the expected from and expected after values.
    • assertBlank

      public static void assertBlank(String actual)
      Asserts that the given string is blank.
      Parameters:
      actual - The string to check.
    • assertContains

      public static void assertContains(Iterable<?> expected, Iterable<?> actual)
      Asserts actual items contain the expected items. It may contain other items as well.
      Parameters:
      expected - Expected items that should be contained in the actual items.
      actual - Actual items that should contain the expected items.
    • assertContains

      public static void assertContains(String expectedContent, String value)
      Asserts that the given string contains the expected content.
      Parameters:
      expectedContent - The expected content.
      value - The string to check.
    • assertContainsEntries

      public static void assertContainsEntries(Map<Object,Object> expected, Object actual)
      Asserts the given value is a map entry and that the expected map contains a key-value pair with the same key and value.
      Parameters:
      expected - Map with entries.
      actual - Entry to check.
    • assertContainsValuesAtKeys

      public static void assertContainsValuesAtKeys(Set<?> expectedKeys, Set<?> expectedValues, Object actual)
      Asserts that the given value is a Map and that it contains the expected keys and values.
      Parameters:
      expectedKeys - Expected keys.
      expectedValues - Expected values.
      actual - Map to check.
    • assertEmpty

      public static void assertEmpty(Iterable<?> actual)
      Asserts that the given iterable is empty.
      Parameters:
      actual - The actual value.
    • assertEmpty

      public static void assertEmpty(String actual)
      Asserts that the given string is empty.
      Parameters:
      actual - The actual value.
    • assertEndsWith

      public static void assertEndsWith(String expectedSuffix, String actual)
      Asserts that the given string ends with the expected suffix.
      Parameters:
      expectedSuffix - The expected suffix.
      actual - The actual value.
    • assertEqualsAsJson

      public static void assertEqualsAsJson(Object expected, Object actual)
      Serializes both objects to JSON, then structurally compares those JSON values. Useful when you have e.g. different map or list implementation with a bad equals implementation; or anything containing arrays (arrays do not implement equals in a way that compares their contents).

      The values can be either (a) a serialized JSON value as a String, (b) a byte[] containing a serialized JSON value, or (c) any other object that can be serialized to JSON.

      Parameters:
      expected - Expected value.
      actual - Actual value.
    • assertEqualsAsJson

      public static void assertEqualsAsJson(Object expected, Object actual, String message)
      Serializes both objects to JSON, then structurally compares those JSON values. Useful when you have e.g. different map or list implementation with a bad equals implementation; or anything containing arrays (arrays do not implement equals in a way that compares their contents).

      The values can be either (a) a serialized JSON value as a String, (b) a byte[] containing a serialized JSON value, or (c) any other object that can be serialized to JSON.

      Parameters:
      expected - Expected value.
      actual - Actual value.
      message - Message to show when the assertion fails.
    • assertEqualsIgnoreCase

      public static void assertEqualsIgnoreCase(String expected, String actual)
      Asserts that the actual value is equal to the expected value, ignoring the case.
      Parameters:
      expected - The expected value.
      actual - The actual value.
    • assertFullyConformingHtml

      public static void assertFullyConformingHtml(String html) throws de.xima.nu_validator.wrapper.bridge.api.NuValidatorException
      Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
      Parameters:
      html - The HTML to validate.
      Throws:
      de.xima.nu_validator.wrapper.bridge.api.NuValidatorException - When the HTML could not be validated.
    • assertFullyConformingHtml

      public static void assertFullyConformingHtml(String html, Consumer<de.xima.nu_validator.wrapper.common.api.INuValidatorOptionsBuilder> configurator) throws de.xima.nu_validator.wrapper.bridge.api.NuValidatorException
      Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
      Parameters:
      html - The HTML to validate.
      configurator - Configurator for the options to use for validation.
      Throws:
      de.xima.nu_validator.wrapper.bridge.api.NuValidatorException - When the HTML could not be validated.
    • assertFullyConformingHtml

      public static void assertFullyConformingHtml(String html, de.xima.nu_validator.wrapper.bridge.api.INuValidator validator) throws de.xima.nu_validator.wrapper.bridge.api.NuValidatorException
      Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
      Parameters:
      html - The HTML to validate.
      validator - Validator to use for validation.
      Throws:
      de.xima.nu_validator.wrapper.bridge.api.NuValidatorException - When the HTML could not be validated.
    • assertFullyConformingHtml

      public static void assertFullyConformingHtml(String html, de.xima.nu_validator.wrapper.bridge.api.INuValidator validator, Consumer<de.xima.nu_validator.wrapper.common.api.INuValidatorOptionsBuilder> configurator) throws de.xima.nu_validator.wrapper.bridge.api.NuValidatorException
      Asserts the given HTML is W3C conform, without any errors, warnings or fatal errors.
      Parameters:
      html - The HTML to validate.
      validator - Validator to use for validation.
      configurator - Configurator for the options to use for validation.
      Throws:
      de.xima.nu_validator.wrapper.bridge.api.NuValidatorException - When the HTML could not be validated.
    • assertHasLength

      public static void assertHasLength(int expectedLength, CharSequence value)
      Asserts the given string has the expected length.
      Parameters:
      expectedLength - Expected length.
      value - String to check.
    • assertHasOneItem

      public static <T> T assertHasOneItem(Iterable<T> actual)
      Asserts that the given iterable has exactly one item, and returns that item.
      Type Parameters:
      T - Type of the item.
      Parameters:
      actual - The actual iterable.
      Returns:
      The single item in the iterable.
    • assertHasSize

      public static void assertHasSize(int expectedSize, Collection<?> actualCollection)
      Asserts the given collection has the expected size.
      Parameters:
      expectedSize - Expected size.
      actualCollection - Actual collection.
    • assertInRange

      public static void assertInRange(com.google.common.collect.Range<Double> expected, double actual)
      Asserts that the actual numerical value is within the expected range.
      Parameters:
      expected - The expected range.
      actual - The actual value.
    • assertInRange

      public static void assertInRange(com.google.common.collect.Range<Float> expected, float actual)
      Asserts that the actual numerical value is within the expected range.
      Parameters:
      expected - The expected range.
      actual - The actual value.
    • assertInRange

      public static void assertInRange(com.google.common.collect.Range<Integer> expected, int actual)
      Asserts that the actual numerical value is within the expected range.
      Parameters:
      expected - The expected range.
      actual - The actual value.
    • assertInRange

      public static void assertInRange(com.google.common.collect.Range<Long> expected, long actual)
      Asserts that the actual numerical value is within the expected range.
      Parameters:
      expected - The expected range.
      actual - The actual value.
    • assertIsAssignableFrom

      public static <T> Class<? extends T> assertIsAssignableFrom(Class<T> expectedType, Class<?> actualType)
      Asserts that the actual type is assignable to the expected type.
      Type Parameters:
      T - Expected type.
      Parameters:
      expectedType - Expected type.
      actualType - Actual type.
      Returns:
      The actual type cast to the expected type.
    • assertIsInstance

      @Deprecated public static <T> T assertIsInstance(Class<T> clazz, Object item)
      Deprecated.
      Use Assertions.assertInstanceOf(Class, Object).
      Checks that the given value is an instance of the expected class.
      Type Parameters:
      T - Expected type.
      Parameters:
      clazz - Expected class.
      item - Instance to check.
      Returns:
      The instance cast to the expected class.
    • assertIsOrHasCause

      @Deprecated public static <T extends Throwable> T assertIsOrHasCause(Throwable actual, Class<T> expectedType)
      Asserts that the given throwable is of the given type or has a throwable of that type somewhere in its chain of causes.
      Type Parameters:
      T - Expected type.
      Parameters:
      actual - The actual throwable.
      expectedType - The expected type.
      Returns:
      The throwable of the expected type.
    • assertIsOrHasCause

      public static <T extends Throwable> T assertIsOrHasCause(Class<T> expectedType, Throwable actual)
      Asserts that the given throwable is of the given type or has a throwable of that type somewhere in its chain of causes.
      Type Parameters:
      T - Expected type.
      Parameters:
      expectedType - The expected type.
      actual - The actual throwable.
      Returns:
      The throwable of the expected type.
    • assertLengthGreaterThan

      public static void assertLengthGreaterThan(int expectedMinLength, CharSequence value)
      Asserts that the given string's length is greater than the expected minimum length.
      Parameters:
      expectedMinLength - The expected minimum length.
      value - The string to check.
    • assertLinesEqual

      public static void assertLinesEqual(String expected, String actual)
      Splits both strings into lines, trims them, and compares them line by line. Useful when you have e.g. different line endings or leading/trailing whitespace. Line terminators are line feed (LF), carriage return (CR), or carriage return followed by line feed (CRLF).
      Parameters:
      expected - Expected lines.
      actual - Actual lines.
    • assertMessageContains

      public static String assertMessageContains(String expectedContent, Throwable throwable)
      Asserts that the given throwable's message contains the expected content, and returns the message.
      Parameters:
      expectedContent - The expected content.
      throwable - The throwable to check.
      Returns:
      The message of the throwable.
    • assertNoneEquals

      public static void assertNoneEquals(Iterable<?> unexpected, Object actual)
      Asserts that the actual item is not equal to any of the unexpected items.
      Parameters:
      unexpected - Unexpected items of which none should be equal to the actual item.
      actual - Actual item that should not be equal to any of the unexpected items.
    • assertNotBlank

      public static void assertNotBlank(String actual)
      Asserts that the given string is blank.
      Parameters:
      actual - The string to check.
    • assertNotContains

      public static void assertNotContains(Iterable<?> unexpected, Iterable<?> actual)
      Asserts that the actual items do not contain the unexpected items.
      Parameters:
      unexpected - Unexpected items that should not be in the actual items.
      actual - Actual item that should not contain the unexpected items.
    • assertNotEmpty

      public static void assertNotEmpty(byte[] value)
      Asserts that the given byte array is not null and not empty.
      Parameters:
      value - The byte array to check.
    • assertNotEmpty

      public static void assertNotEmpty(byte[] value, String message)
      Asserts that the given byte array is not null and not empty.
      Parameters:
      value - The byte array to check.
    • assertSameItems

      public static void assertSameItems(Object expected, Object actual)
      Asserts that both given values are collections with the same items, regardless of the order.
      Parameters:
      expected - Expected collection.
      actual - Actual collection.
    • assertSetEquals

      public static void assertSetEquals(Iterable<?> expected, Iterable<?> actual)
      Asserts that both iterables contain the same items, regardless of the order.
      Parameters:
      expected - Expected items.
      actual - Actual items.
    • assertStartsWith

      public static void assertStartsWith(String expectedPrefix, String actual)
      Asserts that the given string starts with the expected prefix.
      Parameters:
      expectedPrefix - The expected prefix.
      actual - String to check.
    • assertStreamEquals

      public static void assertStreamEquals(byte[] expected, InputStream actual)
      Asserts that the data from the given input stream equals the expected data.
      Parameters:
      expected - Expected data.
      actual - Input stream to check.
    • assertStreamEquals

      public static void assertStreamEquals(InputStream expected, byte[] actual)
      Asserts that the data from the given input stream equals the expected data.
      Parameters:
      expected - Expected data.
      actual - Data to check.
    • assertStreamEquals

      public static void assertStreamEquals(InputStream expected, InputStream actual)
      Asserts that the data from the given input stream equals the expected data.
      Parameters:
      expected - Input stream with the expected data.
      actual - Input stream to check.
    • assertStreamEquals

      public static void assertStreamEquals(Reader expected, Reader actual)
      Asserts that the data from the given reader equals the expected data.
      Parameters:
      expected - Reader with the expected data.
      actual - Reader to check.
    • assertThrows

      public static Throwable assertThrows(org.junit.jupiter.api.function.Executable executable)
      Asserts that the given executable throws any throwable.
      Parameters:
      executable - The executable that should throw a throwable.
      Returns:
      The thrown throwable.
    • assertThrows

      public static <T extends Throwable> T assertThrows(Class<T> expectedType, org.junit.jupiter.api.function.Executable executable)
      Asserts that the given executable throws a throwable of the expected type.
      Type Parameters:
      T - The type of the expected throwable.
      Parameters:
      expectedType - The expected type of the thrown throwable.
      executable - The executable that should throw a throwable of the expected type.
      Returns:
      The thrown throwable of the expected type.
    • assertZipContent

      public static void assertZipContent(String expectedContent, Map<String,byte[]> zip, String path)
      Asserts that the given zip content contains a file with the given path and that the content of that file equals the expected content.
      Parameters:
      expectedContent - The expected content of the file in the zip.
      zip - The zip content as a map of file paths to their content as byte arrays.
      path - The path of the file in the zip to check.
    • classpathResourceBinary

      public static byte[] classpathResourceBinary(String resourcePath)
      Reads a resource from the class path as binary data.
      Parameters:
      resourcePath - Path to the resource, with or without a leading slash.
      Returns:
      The content of the resource as binary data.
    • classpathResourcePlainText

      public static String classpathResourcePlainText(String resourcePath)
      Reads a resource from the class path as a plain text string, using UTF-8 encoding.
      Parameters:
      resourcePath - Path to the resource, with or without a leading slash.
      Returns:
      The content of the resource as a string.
    • createTmpDir

      public static File createTmpDir() throws IOException
      Creates a temporary directory. Make sure to delete it once you're done with it!
      Returns:
      The temporary directory.
      Throws:
      IOException - When the directory could not be created.
    • createTmpFile

      public static File createTmpFile(byte[] content, String fileName, String extension) throws IOException
      Creates a file in the temp folder with the specified content
      Parameters:
      content - the file content
      fileName - Name of the tmp file
      extension - Extension of the tmp file.
      Returns:
      the File instance
      Throws:
      IOException - When the text file could not be created.
    • createTmpFile

      public static File createTmpFile(String content, String fileName, String extension) throws IOException
      Creates a file in the temp folder with the specified content
      Parameters:
      content - the file content
      fileName - Name of the tmp file
      extension - Extension of the tmp file.
      Returns:
      the File instance
      Throws:
      IOException - When the text file could not be created.
    • createTmpTextFile

      public static File createTmpTextFile(String content) throws IOException
      Creates a file in the temp folder with the specified content
      Parameters:
      content - the file content
      Returns:
      the File instance
      Throws:
      IOException - When the text file could not be created.
    • getZipContentAsJson

      public static com.alibaba.fastjson.JSONObject getZipContentAsJson(Map<String,byte[]> exportContent, String path)
    • getZipContentAsText

      public static String getZipContentAsText(Map<String,byte[]> exportContent, String path)
    • list

      @SafeVarargs public static <T> List<T> list(T... items)
      Shortcut for creating a list of items.
      Type Parameters:
      T - Type of the items.
      Parameters:
      items - Items to be added to the list.
      Returns:
      A list of the items.
    • listOfArrays

      @SafeVarargs public static <T> List<T[]> listOfArrays(T[]... items)
      Creates a list of arrays from the given arrays. You could also use list(Object...) but when that method is used with a single array, it will create a list of the array elements instead of a list of arrays.
      Type Parameters:
      T - Type of the array elements.
      Parameters:
      items - Arrays to be added to the list.
      Returns:
      A list of arrays.
    • mailsSorted

      public static List<de.xima.mailserver.api.IMailMessage> mailsSorted(de.xima.mailserver.api.IMailInbox mailbox) throws de.xima.mailserver.api.MailServerException
      Gets all mails from the given inbox, sorted by recipient.
      Parameters:
      mailbox - Mailbox to get the mails from.
      Returns:
      A list of all mails in the mailbox, sorted by recipient.
      Throws:
      de.xima.mailserver.api.MailServerException - When the mails could not be retrieved.
    • map

      public static <K,V> Map<K,V> map(Object... items)
      Shortcut for creating a map with arbitrary key-value pairs. The number of arguments must be even. In comparison with Map.of(), this method allows for more than 10 key-value pairs, but at the cost of giving up type safety. This usually isn't a problem in tests, but if you need type safety, you should use Map.of() instead.
      Type Parameters:
      K - Type of the keys.
      V - Type of the values.
      Parameters:
      items - Key-value pairs to be added to the map.
      Returns:
      A map with the key-value pairs.
    • mockUser

      @Deprecated public static IUser mockUser(String name)
      Parameters:
      name - Name of the user, unused.
      Returns:
      An anonymous virtual user.
    • orderedMap

      public static <K,V> Map<K,V> orderedMap(Object... items)
      Same as map(Object...), but uses a LinkedHashMap implementation that preserves the order of the key-value pairs. Creates a map with arbitrary key-value pairs. The number of arguments must be even.
      Type Parameters:
      K - Type of the keys.
      V - Type of the values.
      Parameters:
      items - Key-value pairs to be added to the map.
      Returns:
      A map with the key-value pairs.
    • randomFreePort

      public static int randomFreePort()
      Finds a random port that is not in use by the current operating system. Note that there is no guarantee that the port will still be free after this method returns, when some application binds to it in the meantime.
      Returns:
      A random free port.
    • readBufferedImage

      public static BufferedImage readBufferedImage(byte[] data, String formatName) throws IOException
      Reads a buffered image from the given byte array using the given format name.
      Parameters:
      data - Byte array with the image data.
      formatName - Format name of the image, e.g. "png" or "jpeg".
      Returns:
      The buffered image.
      Throws:
      IOException - When the image could not be read.
    • set

      @SafeVarargs public static <T> Set<T> set(T... items)
      Shortcut for creating a set of items.
      Type Parameters:
      T - Type of the items.
      Parameters:
      items - Items to be added to the set.
      Returns:
      A set with the items.
    • str

      public static String str(byte[] bytes)
      Decodes the given byte array to a string using UTF-8 encoding.
      Parameters:
      bytes - Byte array to decode.
      Returns:
      The decoded string.
    • submap

      public static <K,V> Map<K,V> submap(Map<K,V> map, Iterable<?> keys)
      Creates a map with the data from the given map, but limited to the given keys.
      Type Parameters:
      K - Type of the keys.
      V - Type of the values.
      Parameters:
      map - Map to get the data from.
      keys - Keys to include in the new map.
      Returns:
      A map with the data from the given map, but limited to the given keys.
    • submap

      @SafeVarargs public static <K,V> Map<K,V> submap(Map<K,V> map, K... keys)
      Creates a map with the data from the given map, but limited to the given keys.
      Type Parameters:
      K - Type of the keys.
      V - Type of the values.
      Parameters:
      map - Map to get the data from.
      keys - Keys to include in the new map.
      Returns:
      A map with the data from the given map, but limited to the given keys.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(File zipFile) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The zip file to unzip.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(File zipFile, String password) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The zip file to unzip.
      password - The password to use for unzipping the zip file, if it is password protected.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(byte[] zipFile) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The zip file as a byte array to unzip.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(byte[] zipFile, String password) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The zip file as a byte array to unzip.
      password - The password to use for unzipping the zip file, if it is password protected.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(Path zipFile) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The path to the zip file to unzip.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(Path zipFile, String password) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The path to the zip file to unzip.
      password - The password to use for unzipping the zip file, if it is password protected.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(InputStream zipFile) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The input stream of the zip file to unzip.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.
    • unzipInMemory

      public static Map<String,byte[]> unzipInMemory(InputStream zipFile, String password) throws IOException
      Unzips the given zip file into memory and returns a map of file paths to their content as byte arrays.
      Parameters:
      zipFile - The input stream of the zip file to unzip.
      password - The password to use for unzipping the zip file, if it is password protected.
      Returns:
      A map of file paths to their content as byte arrays.
      Throws:
      IOException - When the zip file could not be read.