Package org.sdase.commons.server.testing
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 TypeMethodDescriptionstatic GoldenFileAssertions
assertThat
(Path actual) Creates a new instance ofGoldenFileAssertions
that asserts the content as text.hasContentAndUpdateGolden
(String expected) Verifies that the text content of the actualPath
is exactly equal to the given one.hasYamlContentAndUpdateGolden
(String expected) Verifies that the text content of the actualPath
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
Creates a new instance ofGoldenFileAssertions
that asserts the content as text.- Parameters:
actual
- the path to test- Returns:
- the created assertion object
-
hasContentAndUpdateGolden
Verifies that the text content of the actualPath
is exactly equal to the given one. If not, anAssertionError
is thrown, but in contrast toAbstractPathAssert.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 actualPath
's content to.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given content isnull
.UncheckedIOException
- if an I/O error occurs.AssertionError
- if the actualPath
isnull
.AssertionError
- if the actualPath
is not areadable
file.AssertionError
- if the content of the actualPath
is not equal to the given content.IOException
-
hasYamlContentAndUpdateGolden
Verifies that the text content of the actualPath
equals the semantic of the given YAML content. If not, anAssertionError
is thrown, but in contrast toAbstractPathAssert.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 actualPath
's content to.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given content isnull
.UncheckedIOException
- if an I/O error occurs.AssertionError
- if the actualPath
isnull
.AssertionError
- if the actualPath
is not areadable
file.AssertionError
- if the content of the actualPath
is not equal to the given content.IOException
-