Class IOAssertions
- java.lang.Object
-
- com.github.robtimus.junit.support.IOAssertions
-
public final class IOAssertions extends Object
A collection of utility methods that support asserting conditions related to I/O.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertContainsContent(InputStream inputStream, byte[] expectedContent)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(InputStream inputStream, byte[] expectedContent, String message)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(InputStream inputStream, byte[] expectedContent, Supplier<String> messageSupplier)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(InputStream inputStream, Charset charset, String expectedContent)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(InputStream inputStream, Charset charset, String expectedContent, String message)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(InputStream inputStream, Charset charset, String expectedContent, Supplier<String> messageSupplier)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(InputStream inputStream, Charset charset, org.hamcrest.Matcher<? super String> matcher)
Asserts that anInputStream
contains specific content.static void
assertContainsContent(Reader reader, String expectedContent)
Asserts that aReader
contains specific content.static void
assertContainsContent(Reader reader, String expectedContent, String message)
Asserts that aReader
contains specific content.static void
assertContainsContent(Reader reader, String expectedContent, Supplier<String> messageSupplier)
Asserts that aReader
contains specific content.static void
assertContainsContent(Reader reader, org.hamcrest.Matcher<? super String> matcher)
Asserts that aReader
contains specific content.static void
assertNotSerializable(Object object)
Asserts that an object is not serializable.static void
assertNotSerializable(Object object, String message)
Asserts that an object is not serializable.static void
assertNotSerializable(Object object, Supplier<String> messageSupplier)
Asserts that an object is not serializable.static <T> T
assertSerializable(T object)
Asserts that an object is serializable.static <T> T
assertSerializable(T object, String message)
Asserts that an object is serializable.static <T> T
assertSerializable(T object, Supplier<String> messageSupplier)
Asserts that an object is serializable.
-
-
-
Method Detail
-
assertContainsContent
public static void assertContainsContent(Reader reader, String expectedContent)
Asserts that aReader
contains specific content.- Parameters:
reader
- The reader to read from. It will be exhausted at the end of this method call.expectedContent
- The expected content.- Throws:
NullPointerException
- If the given reader is null.
-
assertContainsContent
public static void assertContainsContent(Reader reader, String expectedContent, String message)
Asserts that aReader
contains specific content.- Parameters:
reader
- The reader to read from. It will be exhausted at the end of this method call.expectedContent
- The expected content.message
- The failure message to fail with.- Throws:
NullPointerException
- If the given reader is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(Reader reader, String expectedContent, Supplier<String> messageSupplier)
Asserts that aReader
contains specific content.- Parameters:
reader
- The reader to read from. It will be exhausted at the end of this method call.expectedContent
- The expected content.messageSupplier
- The supplier for the failure message to fail with.- Throws:
NullPointerException
- If the given reader is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(Reader reader, org.hamcrest.Matcher<? super String> matcher)
Asserts that aReader
contains specific content.- Parameters:
reader
- The reader to read from. It will be exhausted at the end of this method call.matcher
- The matcher for the content.- Throws:
NullPointerException
- If the given reader or matcher is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, byte[] expectedContent)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.expectedContent
- The expected content.- Throws:
NullPointerException
- If the given input stream is null.
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, byte[] expectedContent, String message)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.expectedContent
- The expected content.message
- The failure message to fail with.- Throws:
NullPointerException
- If the given input stream is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, byte[] expectedContent, Supplier<String> messageSupplier)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.expectedContent
- The expected content.messageSupplier
- The supplier for the failure message to fail with.- Throws:
NullPointerException
- If the given input stream is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, Charset charset, String expectedContent)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.charset
- The charset to use.expectedContent
- The expected content.- Throws:
NullPointerException
- If the given input stream or charset is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, Charset charset, String expectedContent, String message)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.charset
- The charset to use.expectedContent
- The expected content.message
- The failure message to fail with.- Throws:
NullPointerException
- If the given input stream or charset is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, Charset charset, String expectedContent, Supplier<String> messageSupplier)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.charset
- The charset to use.expectedContent
- The expected content.messageSupplier
- The supplier for the failure message to fail with.- Throws:
NullPointerException
- If the given input stream or charset is null.- Since:
- 2.0
-
assertContainsContent
public static void assertContainsContent(InputStream inputStream, Charset charset, org.hamcrest.Matcher<? super String> matcher)
Asserts that anInputStream
contains specific content.- Parameters:
inputStream
- The input stream to read from. It will be exhausted at the end of this method call.charset
- The charset to use.matcher
- The matcher for the content.- Throws:
NullPointerException
- If the given reader, charset or matcher is null.- Since:
- 2.0
-
assertSerializable
public static <T> T assertSerializable(T object)
Asserts that an object is serializable.- Type Parameters:
T
- The type of object to test.- Parameters:
object
- The object to test.- Returns:
- A deserialized copy of the object.
-
assertSerializable
public static <T> T assertSerializable(T object, String message)
Asserts that an object is serializable.- Type Parameters:
T
- The type of object to test.- Parameters:
object
- The object to test.message
- The failure message to fail with.- Returns:
- A deserialized copy of the object.
- Since:
- 2.0
-
assertSerializable
public static <T> T assertSerializable(T object, Supplier<String> messageSupplier)
Asserts that an object is serializable.- Type Parameters:
T
- The type of object to test.- Parameters:
object
- The object to test.messageSupplier
- The supplier for the failure message to fail with.- Returns:
- A deserialized copy of the object.
- Since:
- 2.0
-
assertNotSerializable
public static void assertNotSerializable(Object object)
Asserts that an object is not serializable.- Parameters:
object
- The object to test.
-
assertNotSerializable
public static void assertNotSerializable(Object object, String message)
Asserts that an object is not serializable.- Parameters:
object
- The object to test.message
- The failure message to fail with.- Since:
- 2.0
-
-