diff --git a/CHANGES.txt b/CHANGES.txt index 3925930d79..b97ba18e5a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ Current +Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals. Fixed: GITHUB-2563: Skip test if its data provider provides no data (Krishnan Mahadevan) Fixed: GITHUB-2535: TestResult.getEndMillis() returns 0 for skipped configuration - after upgrading testng to 7.0 + (Krishnan Mahadevan) Fixed: GITHUB-2638: "[WARN] Ignoring duplicate listener" appears when running .xml suite with and (Krishnan Mahadevan) diff --git a/testng-asserts/src/main/java/org/testng/Assert.java b/testng-asserts/src/main/java/org/testng/Assert.java index dbe618f352..b9cd863921 100644 --- a/testng-asserts/src/main/java/org/testng/Assert.java +++ b/testng-asserts/src/main/java/org/testng/Assert.java @@ -728,6 +728,30 @@ public static void assertEquals(double actual, double expected, String message) } } + /** + * Asserts that two doubles are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Double actual, double expected, String message) { + assertEquals(actual, Double.valueOf(expected), message); + } + + /** + * Asserts that two doubles are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(double actual, Double expected, String message) { + assertEquals(Double.valueOf(actual), expected, message); + } + /** * Asserts that two doubles are equal. If they are not, an AssertionError is thrown. * @@ -738,6 +762,26 @@ public static void assertEquals(double actual, double expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two doubles are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Double actual, double expected) { + assertEquals(actual, Double.valueOf(expected), null); + } + + /** + * Asserts that two doubles are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(double actual, Double expected) { + assertEquals(Double.valueOf(actual), expected, null); + } + private static boolean areEqual(float actual, float expected, float delta) { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails @@ -801,6 +845,30 @@ public static void assertEquals(float actual, float expected, String message) { } } + /** + * Asserts that two floats are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Float actual, float expected, String message) { + assertEquals(actual, Float.valueOf(expected), message); + } + + /** + * Asserts that two floats are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(float actual, Float expected, String message) { + assertEquals(Float.valueOf(actual), expected, message); + } + /** * Asserts that two floats are equal. If they are not, an AssertionError is thrown. * @@ -811,6 +879,26 @@ public static void assertEquals(float actual, float expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two floats are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Float actual, float expected) { + assertEquals(actual, Float.valueOf(expected), null); + } + + /** + * Asserts that two floats are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(float actual, Float expected) { + assertEquals(Float.valueOf(actual), expected, null); + } + /** * Asserts that two longs are equal. If they are not, an AssertionError, with the given message, * is thrown. @@ -823,6 +911,30 @@ public static void assertEquals(long actual, long expected, String message) { assertEquals(Long.valueOf(actual), Long.valueOf(expected), message); } + /** + * Asserts that two longs are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Long actual, long expected, String message) { + assertEquals(actual, Long.valueOf(expected), message); + } + + /** + * Asserts that two longs are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(long actual, Long expected, String message) { + assertEquals(Long.valueOf(actual), expected, message); + } + /** * Asserts that two longs are equal. If they are not, an AssertionError is thrown. * @@ -832,6 +944,25 @@ public static void assertEquals(long actual, long expected, String message) { public static void assertEquals(long actual, long expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two longs are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Long actual, long expected) { + assertEquals(actual, Long.valueOf(expected), null); + } + + /** + * Asserts that two longs are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(long actual, Long expected) { + assertEquals(Long.valueOf(actual), expected, null); + } /** * Asserts that two booleans are equal. If they are not, an AssertionError, with the given @@ -845,6 +976,30 @@ public static void assertEquals(boolean actual, boolean expected, String message assertEquals(Boolean.valueOf(actual), Boolean.valueOf(expected), message); } + /** + * Asserts that two booleans are equal. If they are not, an AssertionError, with the given + * message, is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Boolean actual, boolean expected, String message) { + assertEquals(actual, Boolean.valueOf(expected), message); + } + + /** + * Asserts that two booleans are equal. If they are not, an AssertionError, with the given + * message, is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(boolean actual, Boolean expected, String message) { + assertEquals(Boolean.valueOf(actual), expected, message); + } + /** * Asserts that two booleans are equal. If they are not, an AssertionError is thrown. * @@ -855,6 +1010,26 @@ public static void assertEquals(boolean actual, boolean expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two booleans are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Boolean actual, boolean expected) { + assertEquals(actual, Boolean.valueOf(expected), null); + } + + /** + * Asserts that two booleans are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(boolean actual, Boolean expected) { + assertEquals(Boolean.valueOf(actual), expected, null); + } + /** * Asserts that two bytes are equal. If they are not, an AssertionError, with the given message, * is thrown. @@ -867,6 +1042,30 @@ public static void assertEquals(byte actual, byte expected, String message) { assertEquals(Byte.valueOf(actual), Byte.valueOf(expected), message); } + /** + * Asserts that two bytes are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Byte actual, byte expected, String message) { + assertEquals(actual, Byte.valueOf(expected), message); + } + + /** + * Asserts that two bytes are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(byte actual, Byte expected, String message) { + assertEquals(Byte.valueOf(actual), expected, message); + } + /** * Asserts that two bytes are equal. If they are not, an AssertionError is thrown. * @@ -877,6 +1076,26 @@ public static void assertEquals(byte actual, byte expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two bytes are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Byte actual, byte expected) { + assertEquals(actual, Byte.valueOf(expected), null); + } + + /** + * Asserts that two bytes are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(byte actual, Byte expected) { + assertEquals(Byte.valueOf(actual), expected, null); + } + /** * Asserts that two chars are equal. If they are not, an AssertionError, with the given message, * is thrown. @@ -889,6 +1108,30 @@ public static void assertEquals(char actual, char expected, String message) { assertEquals(Character.valueOf(actual), Character.valueOf(expected), message); } + /** + * Asserts that two chars are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Character actual, char expected, String message) { + assertEquals(actual, Character.valueOf(expected), message); + } + + /** + * Asserts that two chars are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(char actual, Character expected, String message) { + assertEquals(Character.valueOf(actual), expected, message); + } + /** * Asserts that two chars are equal. If they are not, an AssertionError is thrown. * @@ -899,6 +1142,26 @@ public static void assertEquals(char actual, char expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two chars are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Character actual, char expected) { + assertEquals(actual, Character.valueOf(expected), null); + } + + /** + * Asserts that two chars are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(char actual, Character expected) { + assertEquals(Character.valueOf(actual), expected, null); + } + /** * Asserts that two shorts are equal. If they are not, an AssertionError, with the given message, * is thrown. @@ -911,6 +1174,30 @@ public static void assertEquals(short actual, short expected, String message) { assertEquals(Short.valueOf(actual), Short.valueOf(expected), message); } + /** + * Asserts that two shorts are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Short actual, short expected, String message) { + assertEquals(actual, Short.valueOf(expected), message); + } + + /** + * Asserts that two shorts are equal. If they are not, an AssertionError, with the given message, + * is thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(short actual, Short expected, String message) { + assertEquals(Short.valueOf(actual), expected, message); + } + /** * Asserts that two shorts are equal. If they are not, an AssertionError is thrown. * @@ -921,6 +1208,26 @@ public static void assertEquals(short actual, short expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two shorts are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Short actual, short expected) { + assertEquals(actual, Short.valueOf(expected), null); + } + + /** + * Asserts that two shorts are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(short actual, Short expected) { + assertEquals(Short.valueOf(actual), expected, null); + } + /** * Asserts that two ints are equal. If they are not, an AssertionError, with the given message, is * thrown. @@ -933,6 +1240,30 @@ public static void assertEquals(int actual, int expected, String message) { assertEquals(Integer.valueOf(actual), Integer.valueOf(expected), message); } + /** + * Asserts that two ints are equal. If they are not, an AssertionError, with the given message, is + * thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Integer actual, int expected, String message) { + assertEquals(actual, Integer.valueOf(expected), message); + } + + /** + * Asserts that two ints are equal. If they are not, an AssertionError, with the given message, is + * thrown. + * + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(int actual, Integer expected, String message) { + assertEquals(Integer.valueOf(actual), expected, message); + } + /** * Asserts that two ints are equal. If they are not, an AssertionError is thrown. * @@ -943,6 +1274,26 @@ public static void assertEquals(int actual, int expected) { assertEquals(actual, expected, null); } + /** + * Asserts that two ints are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Integer actual, int expected) { + assertEquals(actual, Integer.valueOf(expected), null); + } + + /** + * Asserts that two ints are equal. If they are not, an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(int actual, Integer expected) { + assertEquals(Integer.valueOf(actual), expected, null); + } + /** * Asserts that an object isn't null. If it is, an AssertionError is thrown. * diff --git a/testng-asserts/src/test/java/test/asserttests/AssertTest.java b/testng-asserts/src/test/java/test/asserttests/AssertTest.java index d99c0f75e4..c086717b1b 100644 --- a/testng-asserts/src/test/java/test/asserttests/AssertTest.java +++ b/testng-asserts/src/test/java/test/asserttests/AssertTest.java @@ -12,6 +12,106 @@ public class AssertTest { + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedDouble() { + Double a = 3.14; + double b = 3.14; + Double deltaA = 0.1; + double deltaB = 0.1; + assertEquals(a, b, deltaA); + assertEquals(a, b, deltaB); + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedFloat() { + Float a = 3.1f; + float b = 3.1f; + Float deltaA = 0.1f; + float deltaB = 0.1f; + assertEquals(a, b, deltaA); + assertEquals(a, b, deltaB); + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedLong() { + Long a = 3L; + long b = 3L; + Long deltaA = 1L; + long deltaB = 1L; + assertEquals(a, b, deltaA); + assertEquals(a, b, deltaB); + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedBoolean() { + Boolean a = true; + boolean b = true; + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedByte() { + Byte a = Byte.valueOf("3"); + byte b = (byte) 3; + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedChar() { + Character a = 'a'; + char b = 'a'; + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedShort() { + Short a = Short.valueOf("3"); + short b = (short) 3; + Short deltaA = Short.valueOf("3"); + short deltaB = (short) 1; + assertEquals(a, b, deltaA); + assertEquals(a, b, deltaB); + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + + @Test(description = "GITHUB-2652") + public void assertEqualsBoxedUnboxedInteger() { + Integer a = 3; + int b = 3; + Integer deltaA = 1; + int deltaB = 1; + assertEquals(a, b, deltaA); + assertEquals(a, b, deltaB); + assertEquals(a, b); + assertEquals(a, b, ""); + assertEquals(b, a); + assertEquals(b, a, ""); + } + @Test public void noOrderSuccess() { String[] rto1 = {