Skip to content

Commit

Permalink
fix: correctindentation level 12 to 8 in UserControllerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsbalazs committed Jul 10, 2024
1 parent 5c58f26 commit 375e595
Showing 1 changed file with 128 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.springframework.test.web.servlet.MockMvc;



@SpringBootTest
@AutoConfigureMockMvc
class UserControllerTest {
Expand All @@ -37,40 +36,40 @@ class UserControllerTest {
void shouldReturnPasswordIsNotPresentWhenPasswordIsNotPresent() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath("$.password", is("Password should be added"))
);
.andExpectAll(
status().isBadRequest(),
jsonPath("$.password", is("Password should be added"))
);
}

@DisplayName("Should return password is short when password is short")
@Test
void shouldReturnPasswordIsNotLongEnoughWhenPasswordIsShort() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1Aa"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1Aa"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must be at least 8 characters long"))
);
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must be at least 8 characters long"))
);
}


Expand All @@ -79,22 +78,22 @@ void shouldReturnPasswordIsNotLongEnoughWhenPasswordIsShort() throws Exception {
void shouldReturnPasswordContainsNoDigitsIfItContainsNoDigits() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "aAaaaaaaaaaaaaaaaaaaaaaa"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "aAaaaaaaaaaaaaaaaaaaaaaa"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must contain at least one digit")
)
);
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must contain at least one digit")
)
);
}


Expand All @@ -103,22 +102,22 @@ void shouldReturnPasswordContainsNoDigitsIfItContainsNoDigits() throws Exception
void shouldReturnPasswordContainsNoUpperCaseIfPasswordContainsNoUppercase() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1aaaaaaaaaaaaaaaaaaaaaaa"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1aaaaaaaaaaaaaaaaaaaaaaa"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must contain at least one uppercase letter")
)
);
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must contain at least one uppercase letter")
)
);
}


Expand All @@ -127,93 +126,93 @@ void shouldReturnPasswordContainsNoUpperCaseIfPasswordContainsNoUppercase() thro
void shouldReturnPasswordContainsNoLowerCaseIfPasswordContainsNoLowercase() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1AAAAAAAAAAAAAAAAAAAAAA"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1AAAAAAAAAAAAAAAAAAAAAA"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andExpectAll(status().isBadRequest(),
.andExpectAll(status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must contain at least one lowercase letter")
"$.password",
is("Invalid password: must contain at least one lowercase letter")
)
);
);
}

@DisplayName("Should return password contains white space when password contains white space")
@Test
void shouldReturnPasswordContainsWhiteSpaceIfContainsWhiteSpace() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1 A c a 2 b B a 2"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": "1 A c a 2 b B a 2"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must not contain whitespace")
)
);
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must not contain whitespace")
)
);
}

@DisplayName("Should return password is invalid with all errors if it has all errors")
@Test
void shouldReturnPasswordIsInvalidWithAllErrorsIfItHasAllErrors() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": " "
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"password": " "
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must be at least 8 characters long,"
+ " must not contain whitespace, must contain at least one digit,"
+ " must contain at least one uppercase letter,"
+ " must contain at least one lowercase letter")
));
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.password",
is("Invalid password: must be at least 8 characters long,"
+ " must not contain whitespace, must contain at least one digit,"
+ " must contain at least one uppercase letter,"
+ " must contain at least one lowercase letter")
));
}

@DisplayName("Should return email is not valid when email in not valid")
@Test
void shouldReturnEmailIsInvalidWhenEmailIsInvalid() throws Exception {

String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe.com",
"password": "Aa2aaaaaBBBBaaaaa"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe.com",
"password": "Aa2aaaaaBBBBaaaaa"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.email",
is("must be a well-formed email address")
)
);
.andExpectAll(
status().isBadRequest(),
jsonPath(
"$.email",
is("must be a well-formed email address")
)
);
}


Expand All @@ -223,19 +222,19 @@ void shouldReturnEmailIsIsDuplicatedWhenEmailIsDuplicated() throws Exception {

Mockito.when(userRepository.save(Mockito.any())).thenThrow(new RuntimeException("Email is already taken"));

Check warning on line 223 in backend/src/test/java/com/greenfoxacademy/backend/controller/UserControllerTest.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Line is longer than 100 characters (found 111). Raw Output: /github/workspace/./backend/src/test/java/com/greenfoxacademy/backend/controller/UserControllerTest.java:223:0: warning: Line is longer than 100 characters (found 111). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "asd@asd.com",
"password": "Aa2aaaaaBBBBaaaaa"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "asd@asd.com",
"password": "Aa2aaaaaBBBBaaaaa"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isBadRequest(),
content().string("Email is already taken")
);
.andExpectAll(
status().isBadRequest(),
content().string("Email is already taken")
);
}

@DisplayName("Should return email is duplicated when email is duplicated")
Expand All @@ -244,19 +243,19 @@ void shouldReturnUserSuccessfullyCreatedIfEverythingIsCorrect() throws Exception

Mockito.when(userRepository.save(Mockito.any())).thenReturn(User.builder().id(1).build());
String content = """
{
"firstName": "John",
"lastName": "Doe",
"email": "asd@asd.com",
"password": "Aa2aaaaaBBBBaaaaa"
}
""";
{
"firstName": "John",
"lastName": "Doe",
"email": "asd@asd.com",
"password": "Aa2aaaaaBBBBaaaaa"
}
""";
this.mockMvc.perform(post("/register")
.contentType(MediaType.APPLICATION_JSON).content(content))
.andExpectAll(
status().isCreated(),
header().string("Location", "/users/1")
);
.andExpectAll(
status().isCreated(),
header().string("Location", "/users/1")
);
}

}

0 comments on commit 375e595

Please sign in to comment.