Package org.springframework.test.util

# Class AssertionErrors

java.lang.Object
org.springframework.test.util.AssertionErrors

public abstract class AssertionErrors extends Object
Test assertions that are independent of any third-party assertion library.

Since:
  3.2
Author:
  Lukas Krecan, Arjen Poutsma, Sam Brannen

## Constructor Summary

Constructors
Constructor
Description
`AssertionErrors()`

## Method Summary

Modifier and Type
Method
Description
`static void`
`assertEquals(String message, Object expected, Object actual)`
Assert two objects are equal and raise an `AssertionError` otherwise.
`static void`
`assertFalse(String message, boolean condition)`
Assert the given condition is `false` and raise an `AssertionError` otherwise.
`static void`
`assertNotEquals(String message, Object expected, Object actual)`
Assert two objects are not equal and raise an `AssertionError` otherwise.
`static void`
`assertNotNull(String message, Object object)`
Assert that the given object is not `null` and raise an `AssertionError` otherwise.
`static void`
`assertNull(String message, Object object)`
Assert that the given object is `null` and raise an `AssertionError` otherwise.
`static void`
`assertTrue(String message, boolean condition)`
Assert the given condition is `true` and raise an `AssertionError` otherwise.
`static void`
`fail(String message)`
Fail a test with the given message.
`static void`
`fail(String message, Object expected, Object actual)`
Fail a test with the given message passing along expected and actual values to be appended to the message.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AssertionErrors

public AssertionErrors()

## Method Details

### fail

@Contract("_ -> fail") public static void fail(String message)
Fail a test with the given message.

Parameters:
  `message` - a message that describes the reason for the failure

### fail

public static void fail(String message, @Nullable Object expected, @Nullable Object actual)
Fail a test with the given message passing along expected and actual values to be appended to the message.

For example given:

     String name = "Accept";
     String expected = "application/json";
     String actual = "text/plain";
     fail("Response header [" + name + "]", expected, actual);

The resulting message is:

     Response header [Accept] expected:<application/json> but was:<text/plain>

Parameters:
  `message` - a message that describes the use case that failed
  `expected` - the expected value
  `actual` - the actual value

### assertTrue

@Contract("_, false -> fail") public static void assertTrue(String message, boolean condition)
Assert the given condition is `true` and raise an `AssertionError` otherwise.

Parameters:
  `message` - a message that describes the reason for the failure
  `condition` - the condition to test for

### assertFalse

@Contract("_, true -> fail") public static void assertFalse(String message, boolean condition)
Assert the given condition is `false` and raise an `AssertionError` otherwise.

Parameters:
  `message` - a message that describes the reason for the failure
  `condition` - the condition to test for
Since:
  5.2.1

### assertNull

@Contract("_, !null -> fail") public static void assertNull(String message, @Nullable Object object)
Assert that the given object is `null` and raise an `AssertionError` otherwise.

Parameters:
  `message` - a message that describes the reason for the failure
  `object` - the object to check
Since:
  5.2.1

### assertNotNull

@Contract("_, null -> fail") public static void assertNotNull(String message, @Nullable Object object)
Assert that the given object is not `null` and raise an `AssertionError` otherwise.

Parameters:
  `message` - a message that describes the reason for the failure
  `object` - the object to check
Since:
  5.1.8

### assertEquals

public static void assertEquals(String message, @Nullable Object expected, @Nullable Object actual)
Assert two objects are equal and raise an `AssertionError` otherwise.

For example:

     assertEquals("Response header [" + name + "]", expected, actual);

Parameters:
  `message` - a message that describes the value being checked
  `expected` - the expected value
  `actual` - the actual value
See Also:
  - `fail(String, Object, Object)`

### assertNotEquals

public static void assertNotEquals(String message, @Nullable Object expected, @Nullable Object actual)
Assert two objects are not equal and raise an `AssertionError` otherwise.

For example:

     assertNotEquals("Response header [" + name + "]", expected, actual);

Parameters:
  `message` - a message that describes the value being checked
  `expected` - the expected value
  `actual` - the actual value