Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added boolean assertArrayEquals to Assert, fixing #86 #632

Merged
merged 2 commits into from
Feb 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/org/junit/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,35 @@ public static void assertArrayEquals(String message, Object[] expecteds,
public static void assertArrayEquals(Object[] expecteds, Object[] actuals) {
assertArrayEquals(null, expecteds, actuals);
}

/**
* Asserts that two boolean 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.
*
* @param message the identifying message for the {@link AssertionError} (<code>null</code>
* okay)
* @param expecteds boolean array with expected values.
* @param actuals boolean array with expected values.
*/
public static void assertArrayEquals(String message, boolean[] expecteds,
boolean[] actuals) throws ArrayComparisonFailure {
internalArrayEquals(message, expecteds, actuals);
}

/**
* Asserts that two boolean 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.
*
* @param expecteds boolean array with expected values.
* @param actuals boolean array with expected values.
*/
public static void assertArrayEquals(boolean[] expecteds, boolean[] actuals) {
assertArrayEquals(null, expecteds, actuals);
}

/**
* Asserts that two byte arrays are equal. If they are not, an
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/junit/tests/assertion/AssertionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void multiDimensionalIntArraysAreEqual() {

@Test
public void oneDimensionalPrimitiveArraysAreEqual() {
assertArrayEquals(new boolean[]{true}, new boolean[]{true});
assertArrayEquals(new byte[]{1}, new byte[]{1});
assertArrayEquals(new char[]{1}, new char[]{1});
assertArrayEquals(new short[]{1}, new short[]{1});
Expand All @@ -169,6 +170,11 @@ public void oneDimensionalDoubleArraysAreNotEqual() {
public void oneDimensionalFloatArraysAreNotEqual() {
assertArrayEquals(new float[]{1.0f}, new float[]{2.5f}, 1.0f);
}

@Test(expected = AssertionError.class)
public void oneDimensionalBooleanArraysAreNotEqual() {
assertArrayEquals(new boolean[]{true}, new boolean[]{false});
}

@Test(expected = AssertionError.class)
public void IntegerDoesNotEqualLong() {
Expand Down