Class GoldenFileAssertions

java.lang.Object
org.assertj.core.api.AbstractAssert<GoldenFileAssertions,Path>
org.sdase.commons.server.testing.GoldenFileAssertions
All Implemented Interfaces:
org.assertj.core.api.Assert<GoldenFileAssertions,Path>, org.assertj.core.api.Descriptable<GoldenFileAssertions>, org.assertj.core.api.ExtensionPoints<GoldenFileAssertions,Path>

public class GoldenFileAssertions extends org.assertj.core.api.AbstractAssert<GoldenFileAssertions,Path>
Special assertions for Path objects to check if a file matches the expected contents and updates them if needed.

These assertions are helpful to check if certain files are stored in the repository (like OpenAPI or AsyncApi).

  • Field Summary

    Fields inherited from class org.assertj.core.api.AbstractAssert

    actual, info, myself, objects, throwUnsupportedExceptionOnEquals
  • Method Summary

    Modifier and Type
    Method
    Description
    assertThat(Path actual)
    Creates a new instance of GoldenFileAssertions that asserts the content as text.
    Verifies that the text content of the actual Path is exactly equal to the given one.
    Verifies that the text content of the actual Path equals the semantic of the given YAML content.

    Methods inherited from class org.assertj.core.api.AbstractAssert

    areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.assertj.core.api.Descriptable

    as, as, as, describedAs, describedAs
  • Method Details

    • assertThat

      public static GoldenFileAssertions assertThat(Path actual)
      Creates a new instance of GoldenFileAssertions that asserts the content as text.
      Parameters:
      actual - the path to test
      Returns:
      the created assertion object
    • hasContentAndUpdateGolden

      public GoldenFileAssertions hasContentAndUpdateGolden(String expected) throws IOException
      Verifies that the text content of the actual Path is exactly equal to the given one. If not, an AssertionError is thrown, but in contrast to AbstractPathAssert.hasContent(String) the file is updated with the expected value so the next assert succeeds.

      Use this assertion if you want to conveniently store the latest copy of a file in your repository, and let the CI fail if an update has not been committed.

      Please note that we will not update the golden version if we run in a CI pipeline such as Github Actions or Jenkins.

      Examples:

      
       Path xFile = Paths.get("openapi.yaml");
      
       String expected = ...; // call the service / start the generator
      
       GoldenFileAssertions.assertThat(xFile).hasContentAndUpdateGolden(expected);
       
      Parameters:
      expected - the expected text content to compare the actual Path's content to.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given content is null.
      UncheckedIOException - if an I/O error occurs.
      AssertionError - if the actual Path is null.
      AssertionError - if the actual Path is not a readable file.
      AssertionError - if the content of the actual Path is not equal to the given content.
      IOException
    • hasYamlContentAndUpdateGolden

      public GoldenFileAssertions hasYamlContentAndUpdateGolden(String expected) throws IOException
      Verifies that the text content of the actual Path equals the semantic of the given YAML content. If not, an AssertionError is thrown, but in contrast to AbstractPathAssert.hasContent(String) the file is updated with the expected value so the next assert succeeds.

      Use this assertion if you want to conveniently store the latest copy of a file in your repository, and let the CI fail if an update has not been committed.

      Examples:

      
       Path xFile = Paths.get("openapi.yaml");
      
       String expected = ...; // call the service / start the generator
      
       GoldenFileAssertions.assertThat(xFile).hasYamlContentAndUpdateGolden(expected);
       
      Parameters:
      expected - the expected text content to compare the actual Path's content to.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given content is null.
      UncheckedIOException - if an I/O error occurs.
      AssertionError - if the actual Path is null.
      AssertionError - if the actual Path is not a readable file.
      AssertionError - if the content of the actual Path is not equal to the given content.
      IOException