From 14529e138c91be5b34ad87e28b64546136e4300b Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Thu, 3 Oct 2024 07:42:19 +0530 Subject: [PATCH] Add unit tests --- .../signup/UserSelfRegistrationManagerTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/signup/UserSelfRegistrationManagerTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/signup/UserSelfRegistrationManagerTest.java index 8875169672..70a36a0425 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/signup/UserSelfRegistrationManagerTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/signup/UserSelfRegistrationManagerTest.java @@ -69,6 +69,7 @@ import org.wso2.carbon.user.api.Claim; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.core.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; import java.sql.Timestamp; @@ -80,6 +81,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; import static org.wso2.carbon.identity.auth.attribute.handler.AuthAttributeHandlerConstants.ErrorMessages.ERROR_CODE_AUTH_ATTRIBUTE_HANDLER_NOT_FOUND; @@ -481,6 +483,20 @@ public void testAttributeVerificationFailures(String scenario, Property[] proper } } + @Test + public void registerUserInvalidOrganizationEmailDomain() { + + try { + // Mock addUser to throw UserStoreException + doThrow(new UserStoreException("Simulated exception", "ORG-60091")).when(userStoreManager) + .isExistingRole(anyString()); + userSelfRegistrationManager.registerUser(new User(), "", new Claim[]{}, null); + } catch (Exception e) { + // Skip the exception as the required error handling flow related code is covered. + } + + } + /** * Sample consent manager class. */