FileDocCategorySizeDatePackage
Assert.javaAPI DocAndroid 1.5 API9505Wed May 06 22:41:02 BST 2009junit.framework

Assert

public class Assert extends Object
A set of assert methods. Messages are only displayed when an assert fails.

Fields Summary
Constructors Summary
protected Assert()
Protect constructor since it is a static only class

	
Methods Summary
public static voidassertEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
Asserts that two Strings are equal.

		if (expected == null && actual == null)
			return;
		if (expected != null && expected.equals(actual))
			return;
		throw new ComparisonFailure(message, expected, actual);
	
public static voidassertEquals(java.lang.String expected, java.lang.String actual)
Asserts that two Strings are equal.

	    assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, double expected, double actual, double delta)
Asserts that two doubles are equal concerning a delta. If they are not an AssertionFailedError is thrown with the given message. If the expected value is infinity then the delta value is ignored.

		// handle infinity specially since subtracting to infinite values gives NaN and the
		// the following test fails
		if (Double.isInfinite(expected)) {
			if (!(expected == actual))
				failNotEquals(message, new Double(expected), new Double(actual));
		} else if (!(Math.abs(expected-actual) <= delta)) // Because comparison with NaN always returns false
			failNotEquals(message, new Double(expected), new Double(actual));
	
public static voidassertEquals(double expected, double actual, double delta)
Asserts that two doubles are equal concerning a delta. If the expected value is infinity then the delta value is ignored.

	    assertEquals(null, expected, actual, delta);
	
public static voidassertEquals(java.lang.String message, float expected, float actual, float delta)
Asserts that two floats are equal concerning a delta. If they are not an AssertionFailedError is thrown with the given message. If the expected value is infinity then the delta value is ignored.

 		// handle infinity specially since subtracting to infinite values gives NaN and the
		// the following test fails
		if (Float.isInfinite(expected)) {
			if (!(expected == actual))
				failNotEquals(message, new Float(expected), new Float(actual));
		} else if (!(Math.abs(expected-actual) <= delta))
      		failNotEquals(message, new Float(expected), new Float(actual));
	
public static voidassertEquals(float expected, float actual, float delta)
Asserts that two floats are equal concerning a delta. If the expected value is infinity then the delta value is ignored.

		assertEquals(null, expected, actual, delta);
	
public static voidassertEquals(java.lang.String message, long expected, long actual)
Asserts that two longs are equal. If they are not an AssertionFailedError is thrown with the given message.

	    assertEquals(message, new Long(expected), new Long(actual));
	
public static voidassertEquals(long expected, long actual)
Asserts that two longs are equal.

	    assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, boolean expected, boolean actual)
Asserts that two booleans are equal. If they are not an AssertionFailedError is thrown with the given message.

    		assertEquals(message, new Boolean(expected), new Boolean(actual));
  	
public static voidassertEquals(boolean expected, boolean actual)
Asserts that two booleans are equal.

		assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, byte expected, byte actual)
Asserts that two bytes are equal. If they are not an AssertionFailedError is thrown with the given message.

		assertEquals(message, new Byte(expected), new Byte(actual));
	
public static voidassertEquals(byte expected, byte actual)
Asserts that two bytes are equal.

		assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, char expected, char actual)
Asserts that two chars are equal. If they are not an AssertionFailedError is thrown with the given message.

    		assertEquals(message, new Character(expected), new Character(actual));
  	
public static voidassertEquals(char expected, char actual)
Asserts that two chars are equal.

		assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, short expected, short actual)
Asserts that two shorts are equal. If they are not an AssertionFailedError is thrown with the given message.

    		assertEquals(message, new Short(expected), new Short(actual));
	
public static voidassertEquals(short expected, short actual)
Asserts that two shorts are equal.

		assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, int expected, int actual)
Asserts that two ints are equal. If they are not an AssertionFailedError is thrown with the given message.

		assertEquals(message, new Integer(expected), new Integer(actual));
  	
public static voidassertEquals(int expected, int actual)
Asserts that two ints are equal.

  		assertEquals(null, expected, actual);
	
public static voidassertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown with the given message.

		if (expected == null && actual == null)
			return;
		if (expected != null && expected.equals(actual))
			return;
		failNotEquals(message, expected, actual);
	
public static voidassertEquals(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.

	    assertEquals(null, expected, actual);
	
public static voidassertFalse(java.lang.String message, boolean condition)
Asserts that a condition is false. If it isn't it throws an AssertionFailedError with the given message.

		assertTrue(message, !condition);
	
public static voidassertFalse(boolean condition)
Asserts that a condition is false. If it isn't it throws an AssertionFailedError.

		assertFalse(null, condition);
	
public static voidassertNotNull(java.lang.Object object)
Asserts that an object isn't null.

		assertNotNull(null, object);
	
public static voidassertNotNull(java.lang.String message, java.lang.Object object)
Asserts that an object isn't null. If it is an AssertionFailedError is thrown with the given message.

		assertTrue(message, object != null);
	
public static voidassertNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not an AssertionFailedError is thrown with the given message.

		if (expected == actual)
			failSame(message);
	
public static voidassertNotSame(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not the same an AssertionFailedError is thrown.

		assertNotSame(null, expected, actual);
	
public static voidassertNull(java.lang.Object object)
Asserts that an object is null.

		assertNull(null, object);
	
public static voidassertNull(java.lang.String message, java.lang.Object object)
Asserts that an object is null. If it is not an AssertionFailedError is thrown with the given message.

		assertTrue(message, object == null);
	
public static voidassertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not an AssertionFailedError is thrown with the given message.

		if (expected == actual)
			return;
		failNotSame(message, expected, actual);
	
public static voidassertSame(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not the same an AssertionFailedError is thrown.

	    assertSame(null, expected, actual);
	
public static voidassertTrue(java.lang.String message, boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError with the given message.

		if (!condition)
			fail(message);
	
public static voidassertTrue(boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError.

		assertTrue(null, condition);
	
public static voidfail(java.lang.String message)
Fails a test with the given message.

		throw new AssertionFailedError(message);
	
public static voidfail()
Fails a test with no message.

		fail(null);
	
private static voidfailNotEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)

		fail(format(message, expected, actual));
	
private static voidfailNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)

		String formatted= "";
		if (message != null)
			formatted= message+" ";
		fail(formatted+"expected same:<"+expected+"> was not:<"+actual+">");
	
private static voidfailSame(java.lang.String message)

		String formatted= "";
 		if (message != null)
 			formatted= message+" ";
 		fail(formatted+"expected not same");
	
static java.lang.Stringformat(java.lang.String message, java.lang.Object expected, java.lang.Object actual)

		String formatted= "";
		if (message != null)
			formatted= message+" ";
		return formatted+"expected:<"+expected+"> but was:<"+actual+">";