From: Roland Häder Date: Wed, 16 Nov 2022 13:13:05 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=56165a10ac68a5afbe5f01a0340a2018a4fe512b;p=juser-core.git Continued: - renamed testUserEquals*() to testUser2Equals() as user2 (right side) has being set class fields - also duplicated them for setting class fields in user1 (left side) and testing equals() method --- diff --git a/test/org/mxchange/jusercore/model/user/LoginUserTest.java b/test/org/mxchange/jusercore/model/user/LoginUserTest.java index 07698da..efa6eba 100644 --- a/test/org/mxchange/jusercore/model/user/LoginUserTest.java +++ b/test/org/mxchange/jusercore/model/user/LoginUserTest.java @@ -346,59 +346,74 @@ public class LoginUserTest { Assert.fail("Providing a null for Parameter userName should always throw a NPE. user=" + user); //NOI18N } - @Test (description = "Tests method User.compareTo() with different User instance", dataProvider = "different-user-provider") - public void testUserCompareToDifferentserInstance (final User user1, final User user2) { - // Should always be zero - Assert.assertNotEquals(user1.compareTo(user2), 0); - } - - @Test (description = "Tests method User.compareTo() with different userLastLocked set", dataProvider = "same-user-provider") - public void testUserCompareToDifferentserLastLocked (final User user1, final User user2) { - // Set userLastLocked - user2.setUserLastLocked(new Date()); + @Test (description = "Tests method User.equals() with different userConfirmKey set", dataProvider = "same-user-provider") + public void testUser1EqualsToDifferentUserConfirmKey (final User user1, final User user2) { + // Set userConfirmKey + user1.setUserConfirmKey(UserTestData.USER_CONFIRM_KEY); - // Should always be zero - Assert.assertNotEquals(user1.compareTo(user2), 0); + // Should always be false + Assert.assertFalse(user1.equals(user2)); - // Set userLastLocked back to null - user2.setUserLastLocked(null); + // Set userConfirmKey back to null + user1.setUserConfirmKey(null); } - @Test (description = "Tests method User.compareTo() with a null user", dataProvider = "one-user-provider", expectedExceptions = NullPointerException.class) - public void testUserCompareToNullUser (final User user1) { - // Should throw an exception - final int comparison = user1.compareTo(null); + @Test (description = "Tests method User.equals() with different userId set", dataProvider = "same-user-provider") + public void testUser1EqualsToDifferentUserId (final User user1, final User user2) { + // Set userId + user1.setUserId(1l); - // Should never be reached - Assert.fail("Providing a null reference to User.compareTo() should always throw a NPE. comparison=" + comparison); + // Should always be false + Assert.assertFalse(user1.equals(user2)); + + // Set userId back to null + user1.setUserId(null); } - @Test (description = "Tests method User.compareTo() with same User instance", dataProvider = "same-user-provider") - public void testUserCompareToSameUserInstance (final User user1, final User user2) { - // Should always be zero - Assert.assertEquals(user1.compareTo(user2), 0); + @Test (description = "Tests method User.equals() with different User instance", dataProvider = "different-user-provider") + public void testUser1EqualsToDifferentUserInstance (final User user1, final User user2) { + // Should always be false + Assert.assertFalse(user1.equals(user2)); } - @Test (description = "Tests method User.equals() with same User instance", dataProvider = "one-user-provider") - public void testUserEqualsNullUserInstance (final User user) { + @Test (description = "Tests method User.equals() with different userLastLocked set", dataProvider = "same-user-provider") + public void testUser1EqualsToDifferentUserLastLocked (final User user1, final User user2) { + // Set userLastLocked + user1.setUserLastLocked(new Date()); + // Should always be false - Assert.assertFalse(user.equals(null)); + Assert.assertFalse(user1.equals(user2)); + + // Set userLastLocked back to null + user1.setUserLastLocked(null); } - @Test (description = "Tests method User.equals() with same User instance", dataProvider = "one-user-provider") - public void testUserEqualsOtherInstance (final User user) { + @Test (description = "Tests method User.equals() with different userLastLockedReason set", dataProvider = "same-user-provider") + public void testUser1EqualsToDifferentUserLastLockedReason (final User user1, final User user2) { + // Set userLastLockedReason + user1.setUserLastLockedReason("Some test reason"); + // Should always be false - Assert.assertFalse(user.equals(this)); + Assert.assertFalse(user1.equals(user2)); + + // Set userLastLockedReason back to null + user1.setUserLastLockedReason(null); } - @Test (description = "Tests method User.equals() with same User instance", dataProvider = "same-user-provider") - public void testUserEqualsSameUserInstance (final User user1, final User user2) { - // Should always be true - Assert.assertTrue(user1.equals(user2)); + @Test (description = "Tests method User.equals() with different userLocale set", dataProvider = "same-user-provider") + public void testUser1EqualsToDifferentUserLocale (final User user1, final User user2) { + // Set userLocale + user1.setUserLocale(Locale.FRANCE); + + // Should always be false + Assert.assertFalse(user1.equals(user2)); + + // Set userLocale back to null + user1.setUserLocale(null); } @Test (description = "Tests method User.equals() with different userConfirmKey set", dataProvider = "same-user-provider") - public void testUserEqualsToDifferentUserConfirmKey (final User user1, final User user2) { + public void testUser2EqualsToDifferentUserConfirmKey (final User user1, final User user2) { // Set userConfirmKey user2.setUserConfirmKey(UserTestData.USER_CONFIRM_KEY); @@ -410,7 +425,7 @@ public class LoginUserTest { } @Test (description = "Tests method User.equals() with different userId set", dataProvider = "same-user-provider") - public void testUserEqualsToDifferentUserId (final User user1, final User user2) { + public void testUser2EqualsToDifferentUserId (final User user1, final User user2) { // Set userId user2.setUserId(1l); @@ -422,13 +437,13 @@ public class LoginUserTest { } @Test (description = "Tests method User.equals() with different User instance", dataProvider = "different-user-provider") - public void testUserEqualsToDifferentUserInstance (final User user1, final User user2) { + public void testUser2EqualsToDifferentUserInstance (final User user1, final User user2) { // Should always be false Assert.assertFalse(user1.equals(user2)); } @Test (description = "Tests method User.equals() with different userLastLocked set", dataProvider = "same-user-provider") - public void testUserEqualsToDifferentUserLastLocked (final User user1, final User user2) { + public void testUser2EqualsToDifferentUserLastLocked (final User user1, final User user2) { // Set userLastLocked user2.setUserLastLocked(new Date()); @@ -440,7 +455,7 @@ public class LoginUserTest { } @Test (description = "Tests method User.equals() with different userLastLockedReason set", dataProvider = "same-user-provider") - public void testUserEqualsToDifferentUserLastLockedReason (final User user1, final User user2) { + public void testUser2EqualsToDifferentUserLastLockedReason (final User user1, final User user2) { // Set userLastLockedReason user2.setUserLastLockedReason("Some test reason"); @@ -452,7 +467,7 @@ public class LoginUserTest { } @Test (description = "Tests method User.equals() with different userLocale set", dataProvider = "same-user-provider") - public void testUserEqualsToDifferentUserLocale (final User user1, final User user2) { + public void testUser2EqualsToDifferentUserLocale (final User user1, final User user2) { // Set userLocale user2.setUserLocale(Locale.FRANCE); @@ -463,4 +478,55 @@ public class LoginUserTest { user2.setUserLocale(null); } + @Test (description = "Tests method User.compareTo() with different User instance", dataProvider = "different-user-provider") + public void testUserCompareToDifferentserInstance (final User user1, final User user2) { + // Should always be zero + Assert.assertNotEquals(user1.compareTo(user2), 0); + } + + @Test (description = "Tests method User.compareTo() with different userLastLocked set", dataProvider = "same-user-provider") + public void testUserCompareToDifferentserLastLocked (final User user1, final User user2) { + // Set userLastLocked + user2.setUserLastLocked(new Date()); + + // Should always be zero + Assert.assertNotEquals(user1.compareTo(user2), 0); + + // Set userLastLocked back to null + user2.setUserLastLocked(null); + } + + @Test (description = "Tests method User.compareTo() with a null user", dataProvider = "one-user-provider", expectedExceptions = NullPointerException.class) + public void testUserCompareToNullUser (final User user1) { + // Should throw an exception + final int comparison = user1.compareTo(null); + + // Should never be reached + Assert.fail("Providing a null reference to User.compareTo() should always throw a NPE. comparison=" + comparison); + } + + @Test (description = "Tests method User.compareTo() with same User instance", dataProvider = "same-user-provider") + public void testUserCompareToSameUserInstance (final User user1, final User user2) { + // Should always be zero + Assert.assertEquals(user1.compareTo(user2), 0); + } + + @Test (description = "Tests method User.equals() with same User instance", dataProvider = "one-user-provider") + public void testUserEqualsNullUserInstance (final User user) { + // Should always be false + Assert.assertFalse(user.equals(null)); + } + + @Test (description = "Tests method User.equals() with same User instance", dataProvider = "one-user-provider") + public void testUserEqualsOtherInstance (final User user) { + // Should always be false + Assert.assertFalse(user.equals(this)); + } + + @Test (description = "Tests method User.equals() with same User instance", dataProvider = "same-user-provider") + public void testUserEqualsSameUserInstance (final User user1, final User user2) { + // Should always be true + Assert.assertTrue(user1.equals(user2)); + } + }