diff --git a/sign-in/spring-mvc-normal/src/test/java/net/petrikainulainen/spring/social/signinmvc/user/controller/RegistrationControllerTest.java b/sign-in/spring-mvc-normal/src/test/java/net/petrikainulainen/spring/social/signinmvc/user/controller/RegistrationControllerTest.java index 8663574..5b958a7 100644 --- a/sign-in/spring-mvc-normal/src/test/java/net/petrikainulainen/spring/social/signinmvc/user/controller/RegistrationControllerTest.java +++ b/sign-in/spring-mvc-normal/src/test/java/net/petrikainulainen/spring/social/signinmvc/user/controller/RegistrationControllerTest.java @@ -95,16 +95,12 @@ public void showRegistrationForm_NormalRegistration_ShouldRenderRegistrationPage @Test public void showRegistrationForm_SocialSignUpWithAllValues_ShouldRenderRegistrationPageWithAllValuesSet() throws Exception { - UserProfile socialUser = new UserProfileBuilder() - .setEmail(EMAIL) - .setFirstName(FIRST_NAME) - .setLastName(LAST_NAME) - .setName(FIRST_NAME + " " + LAST_NAME) - .build(); - TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) .build(); ProviderSignInAttempt socialSignIn = new ProviderSignInAttemptStub(socialConnection); @@ -127,11 +123,9 @@ public void showRegistrationForm_SocialSignUpWithAllValues_ShouldRenderRegistrat @Test public void showRegistrationForm_SocialSignUpWithNoValues_ShouldRenderRegistrationPageWithProviderDetails() throws Exception { - UserProfile socialUser = new UserProfileBuilder().build(); - TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() .build(); ProviderSignInAttempt socialSignIn = new ProviderSignInAttemptStub(socialConnection); @@ -343,7 +337,7 @@ public void registerUserAccount_NormalRegistration_ShouldCreateNewUserAccountAnd .andExpect(status().isMovedTemporarily()) .andExpect(redirectedUrl("/")); - assertThat(SecurityContextHolder.getContext()).loggedInUserIsSignedInByUsingSocialProvider(registered); + assertThat(SecurityContextHolder.getContext()).loggedInUserIsRegisteredByUsingRegistrationForm(registered); verify(userServiceMock, times(1)).registerNewUserAccount(userAccountData); verifyNoMoreInteractions(userServiceMock); @@ -351,16 +345,12 @@ public void registerUserAccount_NormalRegistration_ShouldCreateNewUserAccountAnd @Test public void registerUserAccount_SignUpViaSocialProviderAndEmptyForm_ShouldRenderRegistrationFormWithValidationErrors() throws Exception { - UserProfile socialUser = new UserProfileBuilder() - .setEmail(EMAIL) - .setFirstName(FIRST_NAME) - .setLastName(LAST_NAME) - .setName(FIRST_NAME + " " + LAST_NAME) - .build(); - TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) .build(); ProviderSignInAttemptStub socialSignIn = new ProviderSignInAttemptStub(socialConnection); @@ -394,16 +384,12 @@ public void registerUserAccount_SignUpViaSocialProviderAndEmptyForm_ShouldRender @Test public void registerUserAccount_SocialSignInAndTooLongValues_ShouldRenderRegistrationFormWithValidationErrors() throws Exception { - UserProfile socialUser = new UserProfileBuilder() - .setEmail(EMAIL) - .setFirstName(FIRST_NAME) - .setLastName(LAST_NAME) - .setName(FIRST_NAME + " " + LAST_NAME) - .build(); - TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) .build(); ProviderSignInAttemptStub socialSignIn = new ProviderSignInAttemptStub(socialConnection); @@ -444,16 +430,12 @@ public void registerUserAccount_SocialSignInAndTooLongValues_ShouldRenderRegistr @Test public void registerUserAccount_SocialSignInAndMalformedEmail_ShouldRenderRegistrationFormWithValidationError() throws Exception { - UserProfile socialUser = new UserProfileBuilder() - .setEmail(EMAIL) - .setFirstName(FIRST_NAME) - .setLastName(LAST_NAME) - .setName(FIRST_NAME + " " + LAST_NAME) - .build(); - TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) .build(); ProviderSignInAttemptStub socialSignIn = new ProviderSignInAttemptStub(socialConnection); @@ -489,17 +471,13 @@ public void registerUserAccount_SocialSignInAndMalformedEmail_ShouldRenderRegist } @Test - public void registerUserAccount_SocialSignInAndEmailExist_ShouldRenderRegistrationFormWithFieldErrror() throws Exception { - UserProfile socialUser = new UserProfileBuilder() - .setEmail(EMAIL) - .setFirstName(FIRST_NAME) - .setLastName(LAST_NAME) - .setName(FIRST_NAME + " " + LAST_NAME) - .build(); - + public void registerUserAccount_SocialSignInAndEmailExist_ShouldRenderRegistrationFormWithFieldError() throws Exception { TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) .build(); ProviderSignInAttemptStub socialSignIn = new ProviderSignInAttemptStub(socialConnection); @@ -540,16 +518,12 @@ public void registerUserAccount_SocialSignInAndEmailExist_ShouldRenderRegistrati @Test public void registerUserAccount_SocialSignIn_ShouldCreateNewUserAccountAndRenderHomePage() throws Exception { - UserProfile socialUser = new UserProfileBuilder() - .setEmail(EMAIL) - .setFirstName(FIRST_NAME) - .setLastName(LAST_NAME) - .setName(FIRST_NAME + " " + LAST_NAME) - .build(); - TestConnection socialConnection = new TestConnectionBuilder() .providerId(SOCIAL_MEDIA_SERVICE) - .userProfile(socialUser) + .userProfile() + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) .build(); ProviderSignInAttemptStub socialSignIn = new ProviderSignInAttemptStub(socialConnection); diff --git a/sign-in/spring-mvc-normal/src/test/java/org/springframework/social/connect/support/TestConnectionBuilder.java b/sign-in/spring-mvc-normal/src/test/java/org/springframework/social/connect/support/TestConnectionBuilder.java index be0c800..03843f3 100644 --- a/sign-in/spring-mvc-normal/src/test/java/org/springframework/social/connect/support/TestConnectionBuilder.java +++ b/sign-in/spring-mvc-normal/src/test/java/org/springframework/social/connect/support/TestConnectionBuilder.java @@ -2,6 +2,7 @@ import org.springframework.social.connect.ConnectionData; import org.springframework.social.connect.UserProfile; +import org.springframework.social.connect.UserProfileBuilder; /** * @author Petri Kainulainen @@ -10,15 +11,21 @@ public class TestConnectionBuilder { private String displayName; + private String email; + + private String firstName; + private String imageUrl; + private String lastName; + private String profileUrl; private String providerId; private String providerUserId; - private UserProfile userProfile; + private UserProfileBuilder userProfileBuilder; public TestConnectionBuilder() { @@ -29,11 +36,26 @@ public TestConnectionBuilder displayName(String displayName) { return this; } + public TestConnectionBuilder email(String email) { + this.email = email; + return this; + } + + public TestConnectionBuilder firstName(String firstName) { + this.firstName = firstName; + return this; + } + public TestConnectionBuilder imageUrl(String imageUrl) { this.imageUrl = imageUrl; return this; } + public TestConnectionBuilder lastName(String lastName) { + this.lastName = lastName; + return this; + } + public TestConnectionBuilder profileUrl(String profileUrl) { this.profileUrl = profileUrl; return this; @@ -49,8 +71,8 @@ public TestConnectionBuilder providerUserId(String providerUserId) { return this; } - public TestConnectionBuilder userProfile(UserProfile userProfile) { - this.userProfile = userProfile; + public TestConnectionBuilder userProfile() { + userProfileBuilder = new UserProfileBuilder(); return this; } @@ -64,6 +86,13 @@ public TestConnection build() { null, null, null); + + UserProfile userProfile = new UserProfileBuilder() + .setEmail(email) + .setFirstName(firstName) + .setLastName(lastName) + .build(); + return new TestConnection(connectionData, userProfile); } }