Skip to content

Commit

Permalink
Merge pull request #2519 from Marcono1234/marcono1234/assertEqualsNoO…
Browse files Browse the repository at this point in the history
…rder

Mention in assertEqualsNoOrder doc that arrays are not compared deeply
  • Loading branch information
juherr authored Apr 11, 2021
2 parents 1c18076 + d345397 commit 5182035
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Fixed: GITHUB-2493: Avoid NPE from TextReporter execution when a dataprovider me
Fixed: GITHUB-2483: Asymmetric not equals (cdalexndr)
Fixed: GITHUB-2486: assertSame/assertNotSame broken after GITHUB-2296 (Vitalii Diravka)
Fixed: GITHUB-2490: assertNotEquals returns fast when argument is null, not calling equals(Object) (Anindya Roy)
Fixed: GITHUB-2500: Mention in assertEqualsNoOrder doc that arrays are not compared deeply (Marcono1234)

7.4.0
New : GITHUB-2459: Support configurable start time - emailable report (Barry Evans)
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/org/testng/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,9 @@ public static void assertEquals(Object[] actual, Object[] expected, String messa

/**
* Asserts that two arrays contain the same elements in no particular order. If they do not, an
* AssertionError, with the given message, is thrown.
* {@code AssertionError}, with the given message, is thrown. The arrays are not compared 'deeply',
* that means, if the elements are arrays as well their {@code equals} method is used which only
* checks for reference equality.
*
* @param actual the actual value
* @param expected the expected value
Expand Down Expand Up @@ -1324,7 +1326,9 @@ public static void assertEquals(Object[] actual, Object[] expected) {

/**
* Asserts that two arrays contain the same elements in no particular order. If they do not, an
* AssertionError is thrown.
* {@code AssertionError} is thrown. The arrays are not compared 'deeply', that means, if the
* elements are arrays as well their {@code equals} method is used which only checks for reference
* equality.
*
* @param actual the actual value
* @param expected the expected value
Expand Down
51 changes: 51 additions & 0 deletions core/src/test/java/org/testng/AssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,57 @@ public void testInequalityMessage() {
Assert.assertEquals("x", "y");
}

@Test
public void testAssertEqualsNoOrder() {
String[] actual = {"a", "b"};
String[] expected = {"b", "a"};
Assert.assertEqualsNoOrder(actual, expected);
}

@Test
public void testAssertEqualsNoOrderWithEmpty() {
Assert.assertEqualsNoOrder(new String[0], new String[0]);
}

@Test
public void testAssertEqualsNoOrderWithDifferentElementType() {
Assert.assertEqualsNoOrder(new String[0], new Object[0]);
Object[] actual = {"a"};
String[] expected = {"a"};
Assert.assertEqualsNoOrder(actual, expected);
}

@Test(expectedExceptions = AssertionError.class)
public void testAssertEqualsNoOrderWithDuplicate() {
String[] actual = {"a"};
String[] expected = {"a", "a"};
Assert.assertEqualsNoOrder(actual, expected);
}

@Test
public void testAssertEqualsNoOrderWithBothNull() {
Assert.assertEqualsNoOrder(null, null);
}

@Test(expectedExceptions = AssertionError.class)
public void testAssertEqualsNoOrderWithActualNull() {
Assert.assertEqualsNoOrder(null, new String[0]);
}

@Test(expectedExceptions = AssertionError.class)
public void testAssertEqualsNoOrderWithExpectedNull() {
Assert.assertEqualsNoOrder(new String[0], null);
}

@Test(description = "GITHUB-2500", expectedExceptions = AssertionError.class)
public void testAssertEqualsNoOrderNotDeep() {
// assertEqualsNoOrder does not compare arrays deeply, so elements which are
// arrays as well are only compared for reference equality
String[][] actual = {{}};
String[][] expected = {{}};
Assert.assertEqualsNoOrder(actual, expected);
}

@Test(description = "GITHUB-2080", expectedExceptions = AssertionError.class,
expectedExceptionsMessageRegExp = "test expected \\[true\\] but found \\[false\\]")
public void testAssertTrueMessage() {
Expand Down

0 comments on commit 5182035

Please sign in to comment.