Package org.sdase.commons.server.testing
Class GoldenFileAssertions
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<GoldenFileAssertions,java.nio.file.Path>
-
- org.sdase.commons.server.testing.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 forPath
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).
-
-
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 ofGoldenFileAssertions
that asserts the content as text.GoldenFileAssertions
hasContentAndUpdateGolden(java.lang.String expected)
Verifies that the text content of the actualPath
is exactly equal to the given one.GoldenFileAssertions
hasYamlContentAndUpdateGolden(java.lang.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, 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
-
-
-
-
Method Detail
-
assertThat
public static GoldenFileAssertions assertThat(java.nio.file.Path actual)
Creates a new instance ofGoldenFileAssertions
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 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:
java.lang.NullPointerException
- if the given content isnull
.java.io.UncheckedIOException
- if an I/O error occurs.java.lang.AssertionError
- if the actualPath
isnull
.java.lang.AssertionError
- if the actualPath
is not areadable
file.java.lang.AssertionError
- if the content of the actualPath
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 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:
java.lang.NullPointerException
- if the given content isnull
.java.io.UncheckedIOException
- if an I/O error occurs.java.lang.AssertionError
- if the actualPath
isnull
.java.lang.AssertionError
- if the actualPath
is not areadable
file.java.lang.AssertionError
- if the content of the actualPath
is not equal to the given content.java.io.IOException
-
-