Class AbstractInputStreamAssert<SELF extends AbstractInputStreamAssert<SELF,ACTUAL>,ACTUAL extends java.io.InputStream>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
-
- org.assertj.core.api.AbstractInputStreamAssert<SELF,ACTUAL>
-
- Type Parameters:
SELF- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.ACTUAL- the type of the "actual" value.
- All Implemented Interfaces:
Assert<SELF,ACTUAL>,Descriptable<SELF>,ExtensionPoints<SELF,ACTUAL>
- Direct Known Subclasses:
InputStreamAssert
public abstract class AbstractInputStreamAssert<SELF extends AbstractInputStreamAssert<SELF,ACTUAL>,ACTUAL extends java.io.InputStream> extends AbstractAssert<SELF,ACTUAL>
Base class for all implementations of assertions forInputStreams.
-
-
Field Summary
Fields Modifier and Type Field Description private BinaryDiffbinaryDiffprivate Diffdiff-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, assertionErrorCreator, conditions, customRepresentation, info, myself, objects, printAssertionsDescription, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractInputStreamAssert(ACTUAL actual, java.lang.Class<?> selfType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidassertHasBinaryContent(byte[] expected)private voidassertHasContent(java.lang.String expected)private voidassertHasDigest(java.lang.String algorithm, byte[] digest)private voidassertHasDigest(java.lang.String algorithm, java.lang.String digest)private voidassertHasDigest(java.security.MessageDigest algorithm, byte[] digest)private voidassertHasSameContentAs(java.io.InputStream expected)private voidassertIsEmpty()private voidassertIsNotEmpty()private java.lang.StringasString(java.io.InputStream actual, java.nio.charset.Charset charset)AbstractStringAssert<?>asString(java.nio.charset.Charset charset)Converts the content of the actualInputStreamto aStringby decoding its bytes using the given charset and returns assertions for the computed String allowing String specific assertions from this call.SELFhasBinaryContent(byte[] expected)Verifies that the binary content of the actualInputStreamis exactly equal to the given one.SELFhasContent(java.lang.String expected)Verifies that the content of the actualInputStreamis equal to the givenStringexcept for newlines wich are ignored.SELFhasContentEqualTo(java.io.InputStream expected)Deprecated.usehasSameContentAs(InputStream)insteadSELFhasDigest(java.lang.String algorithm, byte[] expected)Verifies that the testedInputStreamdigest (calculated with the specified algorithm) is equal to the given one.SELFhasDigest(java.lang.String algorithm, java.lang.String digest)Verifies that the testedInputStreamdigest (calculated with the specified algorithm) is equal to the given one.SELFhasDigest(java.security.MessageDigest algorithm, byte[] expected)Verifies that the testedInputStreamdigest (calculated with the specifiedMessageDigest) is equal to the given one.SELFhasDigest(java.security.MessageDigest algorithm, java.lang.String digest)Verifies that the testedInputStreamdigest (calculated with the specifiedMessageDigest) is equal to the given one.SELFhasSameContentAs(java.io.InputStream expected)Verifies that the content of the actualInputStreamis equal to the content of the given one.SELFisEmpty()Verifies that the content of the actualInputStreamis empty.SELFisNotEmpty()Verifies that the content of the actualInputStreamis not empty.private static byte[]readAllBytes(java.io.InputStream is)private static voidwrapWithMarkAndReset(java.io.InputStream inputStream, java.lang.Runnable runnable)private static <T> TwrapWithMarkAndReset(java.io.InputStream inputStream, java.util.function.Supplier<T> callable)-
Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, 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, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withAssertionState, 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
-
-
-
-
Field Detail
-
diff
private final Diff diff
-
binaryDiff
private final BinaryDiff binaryDiff
-
-
Constructor Detail
-
AbstractInputStreamAssert
protected AbstractInputStreamAssert(ACTUAL actual, java.lang.Class<?> selfType)
-
-
Method Detail
-
asString
public AbstractStringAssert<?> asString(java.nio.charset.Charset charset)
Converts the content of the actualInputStreamto aStringby decoding its bytes using the given charset and returns assertions for the computed String allowing String specific assertions from this call.Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Example :
InputStream abcInputStream = new ByteArrayInputStream("abc".getBytes()); // assertion succeeds assertThat(abcInputStream).asString(UTF_8) .startsWith("a"); // assertion fails assertThat(abcInputStream).asString(UTF_8) .startsWith("e");- Parameters:
charset- theCharsetto interpret theInputStream's content to a String- Returns:
- a string assertion object.
- Throws:
java.lang.NullPointerException- if the givenCharsetisnull.java.lang.AssertionError- if the actualInputStreamisnull.java.io.UncheckedIOException- if an I/O error occurs.- Since:
- 3.20.0
-
asString
private java.lang.String asString(java.io.InputStream actual, java.nio.charset.Charset charset)
-
readAllBytes
private static byte[] readAllBytes(java.io.InputStream is)
-
hasContentEqualTo
@Deprecated public SELF hasContentEqualTo(java.io.InputStream expected)
Deprecated.usehasSameContentAs(InputStream)insteadVerifies that the content of the actualInputStreamis equal to the content of the given one.- Parameters:
expected- the givenInputStreamto compare the actualInputStreamto.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the givenInputStreamisnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the content of the actualInputStreamis not equal to the content of the given one.java.io.UncheckedIOException- if an I/O error occurs.
-
hasSameContentAs
public SELF hasSameContentAs(java.io.InputStream expected)
Verifies that the content of the actualInputStreamis equal to the content of the given one.Warning: this will consume the whole input streams in case the underlying implementations do not support
marking.Example:
// assertion will pass assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa})); // assertions will fail assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {})); assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa, 0xc, 0xd}));- Parameters:
expected- the givenInputStreamto compare the actualInputStreamto.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the givenInputStreamisnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the content of the actualInputStreamis not equal to the content of the given one.java.io.UncheckedIOException- if an I/O error occurs.
-
assertHasSameContentAs
private void assertHasSameContentAs(java.io.InputStream expected)
-
isEmpty
public SELF isEmpty()
Verifies that the content of the actualInputStreamis empty.Warning: this will consume the first byte of the input stream in case the underlying implementation does not support
marking.Example:
// assertion will pass assertThat(new ByteArrayInputStream(new byte[] {})).isEmpty()); // assertions will fail assertThat(new ByteArrayInputStream(new byte[] {0xa})).isEmpty();- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the givenInputStreamisnull.java.lang.AssertionError- if the content of the actualInputStreamis not empty.java.io.UncheckedIOException- if an I/O error occurs.- Since:
- 3.17.0
-
assertIsEmpty
private void assertIsEmpty()
-
isNotEmpty
public SELF isNotEmpty()
Verifies that the content of the actualInputStreamis not empty.Warning: this will consume the first byte of the input stream in case the underlying implementation does not support
marking.Example:
// assertion will pass assertThat(new ByteArrayInputStream(new byte[] {0xa})).isNotEmpty()); // assertions will fail assertThat(new ByteArrayInputStream(new byte[] {})).isNotEmpty();- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the givenInputStreamisnull.java.lang.AssertionError- if the content of the actualInputStreamis empty.java.io.UncheckedIOException- if an I/O error occurs.- Since:
- 3.17.0
-
assertIsNotEmpty
private void assertIsNotEmpty()
-
hasContent
public SELF hasContent(java.lang.String expected)
Verifies that the content of the actualInputStreamis equal to the givenStringexcept for newlines wich are ignored.This will change in AssertJ 4.0 where newlines will be taken into account, in the meantime, to get this behavior one can use
asString(Charset)and then chain withAbstractStringAssert.isEqualTo(String).Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Example:
// assertion will pass assertThat(new ByteArrayInputStream("a".getBytes())).hasContent("a"); // assertions will fail assertThat(new ByteArrayInputStream("a".getBytes())).hasContent(""); assertThat(new ByteArrayInputStream("a".getBytes())).hasContent("ab");- Parameters:
expected- the givenStringto compare the actualInputStreamto.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the givenStringisnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the content of the actualInputStreamis not equal to the givenString.java.io.UncheckedIOException- if an I/O error occurs.- Since:
- 3.11.0
-
assertHasContent
private void assertHasContent(java.lang.String expected)
-
hasBinaryContent
public SELF hasBinaryContent(byte[] expected)
Verifies that the binary content of the actualInputStreamis exactly equal to the given one.Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Example:
InputStream inputStream = new ByteArrayInputStream(new byte[] {1, 2}); // assertion will pass assertThat(inputStream).hasContent(new byte[] {1, 2}); // assertions will fail assertThat(inputStream).hasBinaryContent(new byte[] { }); assertThat(inputStream).hasBinaryContent(new byte[] {0, 0});- Parameters:
expected- the expected binary content to compare the actualInputStream's content to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given content isnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the content of the actualInputStreamis not equal to the given binary content.java.io.UncheckedIOException- if an I/O error occurs.- Since:
- 3.16.0
-
assertHasBinaryContent
private void assertHasBinaryContent(byte[] expected)
-
hasDigest
public SELF hasDigest(java.security.MessageDigest algorithm, byte[] expected)
Verifies that the testedInputStreamdigest (calculated with the specifiedMessageDigest) is equal to the given one.Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Examples:
// assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); // The following assertions succeed: assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44}); assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25}); // The following assertions fail: assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes()); assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f".getBytes());- Parameters:
algorithm- the MessageDigest used to calculate the digests.expected- the expected binary content to compare the actualInputStream's digest to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given algorithm isnull.java.lang.NullPointerException- if the given digest isnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the actualInputStreamis not readable.java.io.UncheckedIOException- if an I/O error occurs.java.lang.AssertionError- if the content of the testedInputStream's digest is not equal to the given one.- Since:
- 3.11.0
-
hasDigest
public SELF hasDigest(java.security.MessageDigest algorithm, java.lang.String digest)
Verifies that the testedInputStreamdigest (calculated with the specifiedMessageDigest) is equal to the given one.Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Examples:
// assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); // The following assertions succeed: assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "5c5ae45b58f12023817abe492447cdc7912c1a2c"); assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "dcb3015cd28447644c810af352832c19"); // The following assertions fail: assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad"); assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f");- Parameters:
algorithm- the MessageDigest used to calculate the digests.digest- the expected binary content to compare the actualInputStream's digest to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given algorithm isnull.java.lang.NullPointerException- if the given digest isnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the actualInputStreamis not readable.java.io.UncheckedIOException- if an I/O error occurs.java.lang.AssertionError- if the content of the testedInputStream's digest is not equal to the given one.- Since:
- 3.11.0
-
hasDigest
public SELF hasDigest(java.lang.String algorithm, byte[] expected)
Verifies that the testedInputStreamdigest (calculated with the specified algorithm) is equal to the given one.Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Examples:
// assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); // The following assertion succeeds: assertThat(tested).hasDigest("SHA1", new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44}); assertThat(tested).hasDigest("MD5", new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25}); // The following assertion fails: assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes()); assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f".getBytes());- Parameters:
algorithm- the algorithm used to calculate the digests.expected- the expected binary content to compare the actualInputStream's content to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given algorithm isnull.java.lang.NullPointerException- if the given digest isnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the actualInputStreamis not readable.java.io.UncheckedIOException- if an I/O error occurs.java.lang.AssertionError- if the content of the testedInputStream's digest is not equal to the given one.- Since:
- 3.11.0
-
hasDigest
public SELF hasDigest(java.lang.String algorithm, java.lang.String digest)
Verifies that the testedInputStreamdigest (calculated with the specified algorithm) is equal to the given one.Warning: this will consume the whole input stream in case the underlying implementation does not support
marking.Examples:
// assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); // The following assertion succeeds: assertThat(tested).hasDigest("SHA1", "5c5ae45b58f12023817abe492447cdc7912c1a2c"); assertThat(tested).hasDigest("MD5", "dcb3015cd28447644c810af352832c19"); // The following assertion fails: assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad"); assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f");- Parameters:
algorithm- the algorithm used to calculate the digests.digest- the expected binary content to compare the actualInputStream's content to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given algorithm isnull.java.lang.NullPointerException- if the given digest isnull.java.lang.AssertionError- if the actualInputStreamisnull.java.lang.AssertionError- if the actualInputStreamis not readable.java.io.UncheckedIOException- if an I/O error occurs.java.lang.AssertionError- if the content of the testedInputStream's digest is not equal to the given one.- Since:
- 3.11.0
-
assertHasDigest
private void assertHasDigest(java.lang.String algorithm, java.lang.String digest)
-
assertHasDigest
private void assertHasDigest(java.lang.String algorithm, byte[] digest)
-
assertHasDigest
private void assertHasDigest(java.security.MessageDigest algorithm, byte[] digest)
-
wrapWithMarkAndReset
private static void wrapWithMarkAndReset(java.io.InputStream inputStream, java.lang.Runnable runnable)
-
wrapWithMarkAndReset
private static <T> T wrapWithMarkAndReset(java.io.InputStream inputStream, java.util.function.Supplier<T> callable)
-
-