Class GoldenFileAssertions

  • All Implemented Interfaces:
    org.assertj.core.api.Assert<GoldenFileAssertions,​java.nio.file.Path>, org.assertj.core.api.Descriptable<GoldenFileAssertions>, org.assertj.core.api.ExtensionPoints<GoldenFileAssertions,​java.nio.file.Path>

    public class GoldenFileAssertions
    extends org.assertj.core.api.AbstractAssert<GoldenFileAssertions,​java.nio.file.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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static GoldenFileAssertions assertThat​(java.nio.file.Path actual)
      Creates a new instance of GoldenFileAssertions that asserts the content as text.
      GoldenFileAssertions hasContentAndUpdateGolden​(java.lang.String expected)
      Verifies that the text content of the actual Path is exactly equal to the given one.
      GoldenFileAssertions hasYamlContentAndUpdateGolden​(java.lang.String expected)
      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, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, 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
    • Method Detail

      • assertThat

        public static GoldenFileAssertions assertThat​(java.nio.file.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​(java.lang.String expected)
                                                       throws java.io.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.

        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:
        java.lang.NullPointerException - if the given content is null.
        java.io.UncheckedIOException - if an I/O error occurs.
        java.lang.AssertionError - if the actual Path is null.
        java.lang.AssertionError - if the actual Path is not a readable file.
        java.lang.AssertionError - if the content of the actual Path is not equal to the given content.
        java.io.IOException
      • hasYamlContentAndUpdateGolden

        public GoldenFileAssertions hasYamlContentAndUpdateGolden​(java.lang.String expected)
                                                           throws java.io.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:
        java.lang.NullPointerException - if the given content is null.
        java.io.UncheckedIOException - if an I/O error occurs.
        java.lang.AssertionError - if the actual Path is null.
        java.lang.AssertionError - if the actual Path is not a readable file.
        java.lang.AssertionError - if the content of the actual Path is not equal to the given content.
        java.io.IOException