Assert

A set of assertion methods useful for writing tests. Only failed assertions are recorded. These methods can be used directly: <code>Assert.assertEquals(...)</code>, however, they read better if they are referenced through static import:

<pre> import org.junit.Assert.*; ... assertEquals(...); </pre>

@see AssertionError

class Assert {}

Constructors

this
this()

Protect constructor since it is a static only class

Members

Static functions

assertArrayEquals
void assertArrayEquals(string message, T[] expecteds, T[] actuals)

Asserts that two object arrays are equal. If they are not, an {@link AssertionError} is thrown with the given message. If <code>expecteds</code> and <code>actuals</code> are <code>null</code>, they are considered equal.

assertArrayEquals
void assertArrayEquals(T[] expecteds, T[] actuals)

Asserts that two object arrays are equal. If they are not, an {@link AssertionError} is thrown. If <code>expected</code> and <code>actual</code> are <code>null</code>, they are considered equal.

assertContain
void assertContain(T source, T substring)
Undocumented in source. Be warned that the author may not have intended to support it.
assertEquals
void assertEquals(string message, T expected, T actual)

Asserts that two objects are equal. If they are not, an {@link AssertionError} is thrown with the given message. If <code>expected</code> and <code>actual</code> are <code>null</code>, they are considered equal.

assertEquals
void assertEquals(T expected, T actual)

Asserts that two objects are equal. If they are not, an {@link AssertionError} without a message is thrown. If <code>expected</code> and <code>actual</code> are <code>null</code>, they are considered equal.

assertEquals
void assertEquals(string message, double expected, double actual, double delta)

Asserts that two doubles are equal to within a positive delta. If they are not, an {@link AssertionError} is thrown with the given message. If the expected value is infinity then the delta value is ignored. NaNs are considered equal: <code>assertEquals(Double.NaN, Double.NaN, *)</code> passes

assertEquals
void assertEquals(string message, float expected, float actual, float delta)

Asserts that two floats are equal to within a positive delta. If they are not, an {@link AssertionError} is thrown with the given message. If the expected value is infinity then the delta value is ignored. NaNs are considered equal: <code>assertEquals(Float.NaN, Float.NaN, *)</code> passes

assertEquals
void assertEquals(long expected, long actual)

Asserts that two longs are equal. If they are not, an {@link AssertionError} is thrown.

assertEquals
void assertEquals(string message, long expected, long actual)

Asserts that two longs are equal. If they are not, an {@link AssertionError} is thrown with the given message.

assertEquals
void assertEquals(double expected, double actual, double delta)

Asserts that two doubles are equal to within a positive delta. If they are not, an {@link AssertionError} is thrown. If the expected value is infinity then the delta value is ignored.NaNs are considered equal: <code>assertEquals(Double.NaN, Double.NaN, *)</code> passes

assertEquals
void assertEquals(float expected, float actual, float delta)

Asserts that two floats are equal to within a positive delta. If they are not, an {@link AssertionError} is thrown. If the expected value is infinity then the delta value is ignored. NaNs are considered equal: <code>assertEquals(Float.NaN, Float.NaN, *)</code> passes

assertFalse
void assertFalse(string message, bool condition)

Asserts that a condition is false. If it isn't it throws an {@link AssertionError} with the given message.

assertFalse
void assertFalse(bool condition)

Asserts that a condition is false. If it isn't it throws an {@link AssertionError} without a message.

assertNotEquals
void assertNotEquals(string message, Object unexpected, Object actual)

Asserts that two objects are <b>not</b> equals. If they are, an {@link AssertionError} is thrown with the given message. If <code>unexpected</code> and <code>actual</code> are <code>null</code>, they are considered equal.

assertNotEquals
void assertNotEquals(Object unexpected, Object actual)

Asserts that two objects are <b>not</b> equals. If they are, an {@link AssertionError} without a message is thrown. If <code>unexpected</code> and <code>actual</code> are <code>null</code>, they are considered equal.

assertNotEquals
void assertNotEquals(string message, long unexpected, long actual)

Asserts that two longs are <b>not</b> equals. If they are, an {@link AssertionError} is thrown with the given message.

assertNotEquals
void assertNotEquals(long unexpected, long actual)

Asserts that two longs are <b>not</b> equals. If they are, an {@link AssertionError} without a message is thrown.

assertNotEquals
void assertNotEquals(string message, double unexpected, double actual, double delta)

Asserts that two doubles are <b>not</b> equal to within a positive delta. If they are, an {@link AssertionError} is thrown with the given message. If the unexpected value is infinity then the delta value is ignored. NaNs are considered equal: <code>assertNotEquals(Double.NaN, Double.NaN, *)</code> fails

assertNotEquals
void assertNotEquals(double unexpected, double actual, double delta)

Asserts that two doubles are <b>not</b> equal to within a positive delta. If they are, an {@link AssertionError} is thrown. If the unexpected value is infinity then the delta value is ignored.NaNs are considered equal: <code>assertNotEquals(Double.NaN, Double.NaN, *)</code> fails

assertNotEquals
void assertNotEquals(float unexpected, float actual, float delta)

Asserts that two floats are <b>not</b> equal to within a positive delta. If they are, an {@link AssertionError} is thrown. If the unexpected value is infinity then the delta value is ignored.NaNs are considered equal: <code>assertNotEquals(Float.NaN, Float.NaN, *)</code> fails

assertNotEquals
void assertNotEquals(string message, float unexpected, float actual, float delta)

Asserts that two floats are <b>not</b> equal to within a positive delta. If they are, an {@link AssertionError} is thrown with the given message. If the unexpected value is infinity then the delta value is ignored. NaNs are considered equal: <code>assertNotEquals(Float.NaN, Float.NaN, *)</code> fails

assertNotNull
void assertNotNull(string message, T object)

Asserts that an object isn't null. If it is an {@link AssertionError} is thrown with the given message.

assertNotNull
void assertNotNull(T object)

Asserts that an object isn't null. If it is an {@link AssertionError} is thrown.

assertNotSame
void assertNotSame(string message, T unexpected, T actual)

Asserts that two objects do not refer to the same object. If they do refer to the same object, an {@link AssertionError} is thrown with the given message.

assertNotSame
void assertNotSame(T unexpected, T actual)

Asserts that two objects do not refer to the same object. If they do refer to the same object, an {@link AssertionError} without a message is thrown.

assertNull
void assertNull(string message, T object)

Asserts that an object is null. If it is not, an {@link AssertionError} is thrown with the given message.

assertNull
void assertNull(T object)

Asserts that an object is null. If it isn't an {@link AssertionError} is thrown.

assertSame
void assertSame(string message, T expected, T actual)

Asserts that two objects refer to the same object. If they are not, an {@link AssertionError} is thrown with the given message.

assertSame
void assertSame(T expected, T actual)

Asserts that two objects refer to the same object. If they are not the same, an {@link AssertionError} without a message is thrown.

assertStartsWith
void assertStartsWith(T source, T substring)
Undocumented in source. Be warned that the author may not have intended to support it.
assertThat
void assertThat(T actual, T matcher)

Asserts that <code>actual</code> satisfies the condition specified by <code>matcher</code>. If not, an {@link AssertionError} is thrown with information about the matcher and failing value. Example:

assertThat
void assertThat(string message, T actual, T matcher)

Asserts that <code>actual</code> satisfies the condition specified by <code>matcher</code>. If not, an {@link AssertionError} is thrown with the reason and information about the matcher and failing value. Example:

assertTrue
void assertTrue(string message, bool condition)

Asserts that a condition is true. If it isn't it throws an {@link AssertionError} with the given message.

assertTrue
void assertTrue(bool condition)

Asserts that a condition is true. If it isn't it throws an {@link AssertionError} without a message.

fail
void fail(string message)

Fails a test with the given message.

fail
void fail()

Fails a test with no message.

format
string format(string message, T expected, T actual)
Undocumented in source. Be warned that the author may not have intended to support it.
format
string format(string message, T expected, T actual)
Undocumented in source. Be warned that the author may not have intended to support it.
state
void state(bool expression, string message)

Assert a bool expression, throwing {@code IllegalStateException} if the test result is {@code false}. Call isTrue if you wish to throw IllegalArgumentException on an assertion failure.

Meta