From 3833601762443448c79ca8c8f8ae2ed140d9df81 Mon Sep 17 00:00:00 2001 From: kitdim Date: Thu, 23 May 2024 12:34:15 +0300 Subject: [PATCH 1/2] Correcting the lineman's remarks. --- config/checkstyle/checkstyle.xml | 2 +- .../typoreporter/HexletTypoReporter.java | 3 +- .../config/CustomAccessDeniedHandler.java | 1 - .../typoreporter/config/I18nConfig.java | 1 - .../controller/SignupController.java | 25 ++++++++++++++-- .../controller/WidgetController.java | 6 ++-- .../controller/WorkspaceController.java | 5 ++-- .../typoreporter/domain/typo/TypoStatus.java | 2 +- .../constraint/WorkspaceDescription.java | 1 - .../workspace/constraint/WorkspaceName.java | 1 - .../handler/GlobalExceptionHandler.java | 6 +++- .../AccountAlreadyExistException.java | 3 +- .../NewPasswordTheSameException.java | 3 +- .../exception/TypoNotFoundException.java | 3 +- .../WorkspaceAlreadyExistException.java | 3 +- .../exception/WorkspaceNotFoundException.java | 6 ++-- .../WorkspaceRoleNotFoundException.java | 3 +- .../service/WorkspaceService.java | 3 +- .../service/account/signup/SignupAccount.java | 3 +- .../service/dto/FieldMatchConsiderCase.java | 5 +++- .../service/dto/FieldMatchIgnoreCase.java | 5 +++- .../dto/FieldMatchIgnoreCaseValidator.java | 6 ---- .../service/dto/account/InfoAccount.java | 2 +- .../service/dto/account/UpdatePassword.java | 5 +++- .../dto/workspace/WorkspaceRoleInfo.java | 2 +- .../service/mapper/TypoMapper.java | 6 ++-- .../service/mapper/WorkspaceMapper.java | 6 ++-- .../typoreporter/utils/ValidationEmail.java | 3 +- .../web/model/SignupAccountModel.java | 6 ++-- .../web/model/WorkspaceUserModel.java | 7 +++-- .../repository/TypoRepositoryIT.java | 16 ++++++---- .../repository/WorkspaceRepositoryIT.java | 13 +++++--- .../repository/WorkspaceRoleRepositoryIT.java | 1 - .../typoreporter/service/TypoServiceIT.java | 7 +++-- .../mapper/WorkspaceToWorkspaceInfoTest.java | 3 +- .../typoreporter/test/DBUnitEnumPostgres.java | 3 +- .../test/asserts/ReportedTypoAssert.java | 3 +- .../typoreporter/test/asserts/TypoAssert.java | 3 +- .../test/asserts/TypoInfoAssert.java | 3 +- .../io/hexlet/typoreporter/web/LoginIT.java | 24 +++++++-------- .../typoreporter/web/SignupControllerIT.java | 9 +++--- .../typoreporter/web/TypoControllerIT.java | 4 +-- .../web/WorkspaceControllerIT.java | 30 ++++++++++++------- .../web/WorkspaceSettingsControllerIT.java | 11 +++---- 44 files changed, 165 insertions(+), 98 deletions(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index bce88032..2bac0db1 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -178,7 +178,7 @@ - + diff --git a/src/main/java/io/hexlet/typoreporter/HexletTypoReporter.java b/src/main/java/io/hexlet/typoreporter/HexletTypoReporter.java index 44ad0d47..d9419813 100644 --- a/src/main/java/io/hexlet/typoreporter/HexletTypoReporter.java +++ b/src/main/java/io/hexlet/typoreporter/HexletTypoReporter.java @@ -41,6 +41,7 @@ private static void logApplicationStartup(Environment env) { ---------------------------------------------------------- """; final var appName = env.getProperty("spring.application.name"); - log.info(msg, appName, protocol, port, contextPath, protocol, hostAddress, port, contextPath, env.getActiveProfiles()); + log.info(msg, appName, protocol, port, contextPath, + protocol, hostAddress, port, contextPath, env.getActiveProfiles()); } } diff --git a/src/main/java/io/hexlet/typoreporter/config/CustomAccessDeniedHandler.java b/src/main/java/io/hexlet/typoreporter/config/CustomAccessDeniedHandler.java index aad0e48e..c451fc8c 100644 --- a/src/main/java/io/hexlet/typoreporter/config/CustomAccessDeniedHandler.java +++ b/src/main/java/io/hexlet/typoreporter/config/CustomAccessDeniedHandler.java @@ -1,6 +1,5 @@ package io.hexlet.typoreporter.config; -import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.security.access.AccessDeniedException; diff --git a/src/main/java/io/hexlet/typoreporter/config/I18nConfig.java b/src/main/java/io/hexlet/typoreporter/config/I18nConfig.java index 1a785ec7..414b24de 100644 --- a/src/main/java/io/hexlet/typoreporter/config/I18nConfig.java +++ b/src/main/java/io/hexlet/typoreporter/config/I18nConfig.java @@ -8,7 +8,6 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; -import org.springframework.web.servlet.i18n.SessionLocaleResolver; import java.util.Locale; diff --git a/src/main/java/io/hexlet/typoreporter/controller/SignupController.java b/src/main/java/io/hexlet/typoreporter/controller/SignupController.java index 9c731b1d..fd8b406d 100644 --- a/src/main/java/io/hexlet/typoreporter/controller/SignupController.java +++ b/src/main/java/io/hexlet/typoreporter/controller/SignupController.java @@ -67,16 +67,35 @@ public String createAccount(@ModelAttribute("signupAccount") @Valid SignupAccoun return "redirect:/workspaces"; } catch (UsernameAlreadyExistException e) { log.warn(e.getMessage(), e); - bindingResult.addError(new FieldError("signupAccount", "username", e.getUsername(), false, null, null, e.getMessage())); + bindingResult.addError( + new FieldError( + "signupAccount", + "username", + e.getUsername(), + false, + null, + null, + e.getMessage()) + ); return "account/signup"; } catch (EmailAlreadyExistException e) { log.warn(e.getMessage(), e); - bindingResult.addError(new FieldError("signupAccount", "email", e.getEmail(), false, null, null, e.getMessage())); + bindingResult.addError( + new FieldError( + "signupAccount", + "email", + e.getEmail(), + false, + null, + null, + e.getMessage())); return "account/signup"; } } - private void autoLoginAfterSignup(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { + private void autoLoginAfterSignup(HttpServletRequest request, + HttpServletResponse response, + Authentication authentication) { SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder.getContextHolderStrategy(); SecurityContext context = securityContextHolderStrategy.createEmptyContext(); context.setAuthentication(authentication); diff --git a/src/main/java/io/hexlet/typoreporter/controller/WidgetController.java b/src/main/java/io/hexlet/typoreporter/controller/WidgetController.java index f84bf5c9..7352847a 100644 --- a/src/main/java/io/hexlet/typoreporter/controller/WidgetController.java +++ b/src/main/java/io/hexlet/typoreporter/controller/WidgetController.java @@ -62,14 +62,16 @@ String postWidgetTypoForm(HttpServletResponse response, response.addHeader("Content-Security-Policy", "frame-ancestors " + wks.get().getUrl()); if (bindingResult.hasFieldErrors("reporterComment")) { - log.warn("Validation error during saving typo from widget. Typo not valid. Errors: {}", bindingResult.getAllErrors()); + log.warn("Validation error during saving typo from widget. Typo not valid. Errors: {}", + bindingResult.getAllErrors()); model.addAttribute("typoReport", typoReport); model.addAttribute("formModified", true); return "widget/typo-form"; } if (bindingResult.hasErrors()) { - log.error("Validation error during saving typo from widget. Typo not valid. Errors: {}", bindingResult.getAllErrors()); + log.error("Validation error during saving typo from widget. Typo not valid. Errors: {}", + bindingResult.getAllErrors()); return "widget/report-typo-error"; } diff --git a/src/main/java/io/hexlet/typoreporter/controller/WorkspaceController.java b/src/main/java/io/hexlet/typoreporter/controller/WorkspaceController.java index 58cb7671..200168ba 100644 --- a/src/main/java/io/hexlet/typoreporter/controller/WorkspaceController.java +++ b/src/main/java/io/hexlet/typoreporter/controller/WorkspaceController.java @@ -1,6 +1,6 @@ package io.hexlet.typoreporter.controller; -import io.hexlet.typoreporter.web.model.*; +import io.hexlet.typoreporter.web.model.WorkspaceUserModel; import org.springframework.ui.Model; import io.hexlet.typoreporter.domain.account.Account; import io.hexlet.typoreporter.domain.typo.TypoStatus; @@ -32,7 +32,8 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; -import org.springframework.validation.*; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; diff --git a/src/main/java/io/hexlet/typoreporter/domain/typo/TypoStatus.java b/src/main/java/io/hexlet/typoreporter/domain/typo/TypoStatus.java index 71747a21..c88502d0 100644 --- a/src/main/java/io/hexlet/typoreporter/domain/typo/TypoStatus.java +++ b/src/main/java/io/hexlet/typoreporter/domain/typo/TypoStatus.java @@ -86,7 +86,7 @@ public String getStyle() { }; } - public abstract TypoStatus next(final TypoEvent event); + public abstract TypoStatus next(TypoEvent event); public abstract Collection getValidEvents(); } diff --git a/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceDescription.java b/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceDescription.java index 33422508..fe376c1e 100644 --- a/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceDescription.java +++ b/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceDescription.java @@ -2,7 +2,6 @@ import jakarta.validation.Constraint; import jakarta.validation.Payload; -import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import java.lang.annotation.ElementType; diff --git a/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceName.java b/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceName.java index c3f76944..4b701014 100644 --- a/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceName.java +++ b/src/main/java/io/hexlet/typoreporter/domain/workspace/constraint/WorkspaceName.java @@ -5,7 +5,6 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; import java.lang.annotation.ElementType; diff --git a/src/main/java/io/hexlet/typoreporter/handler/GlobalExceptionHandler.java b/src/main/java/io/hexlet/typoreporter/handler/GlobalExceptionHandler.java index a4c1f064..2e749797 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/GlobalExceptionHandler.java +++ b/src/main/java/io/hexlet/typoreporter/handler/GlobalExceptionHandler.java @@ -1,6 +1,10 @@ package io.hexlet.typoreporter.handler; -import io.hexlet.typoreporter.handler.exception.*; +import io.hexlet.typoreporter.handler.exception.AccountAlreadyExistException; +import io.hexlet.typoreporter.handler.exception.AccountNotFoundException; +import io.hexlet.typoreporter.handler.exception.NewPasswordTheSameException; +import io.hexlet.typoreporter.handler.exception.OldPasswordWrongException; +import io.hexlet.typoreporter.handler.exception.WorkspaceAlreadyExistException; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/io/hexlet/typoreporter/handler/exception/AccountAlreadyExistException.java b/src/main/java/io/hexlet/typoreporter/handler/exception/AccountAlreadyExistException.java index 635344a0..de851746 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/exception/AccountAlreadyExistException.java +++ b/src/main/java/io/hexlet/typoreporter/handler/exception/AccountAlreadyExistException.java @@ -16,7 +16,8 @@ public class AccountAlreadyExistException extends ErrorResponseException { private final String errorValue; public AccountAlreadyExistException(final String fieldName, final String errorValue) { - super(CONFLICT, ProblemDetail.forStatusAndDetail(CONFLICT, "Account already exists"), null, format(MESSAGE_TEMPLATE, fieldName, errorValue), new Object[]{fieldName, errorValue}); + super(CONFLICT, ProblemDetail.forStatusAndDetail(CONFLICT, "Account already exists"), null, + format(MESSAGE_TEMPLATE, fieldName, errorValue), new Object[]{fieldName, errorValue}); this.fieldName = fieldName; this.errorValue = errorValue; } diff --git a/src/main/java/io/hexlet/typoreporter/handler/exception/NewPasswordTheSameException.java b/src/main/java/io/hexlet/typoreporter/handler/exception/NewPasswordTheSameException.java index 17c8e29c..5411b73c 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/exception/NewPasswordTheSameException.java +++ b/src/main/java/io/hexlet/typoreporter/handler/exception/NewPasswordTheSameException.java @@ -11,7 +11,8 @@ public class NewPasswordTheSameException extends ErrorResponseException implemen private static final String MESSAGE_TEMPLATE = "New password is the same as the old one"; public NewPasswordTheSameException() { - super(CONFLICT, ProblemDetail.forStatusAndDetail(CONFLICT, "The same new password"), null, MESSAGE_TEMPLATE, null); + super(CONFLICT, ProblemDetail.forStatusAndDetail(CONFLICT, "The same new password"), + null, MESSAGE_TEMPLATE, null); } @Override diff --git a/src/main/java/io/hexlet/typoreporter/handler/exception/TypoNotFoundException.java b/src/main/java/io/hexlet/typoreporter/handler/exception/TypoNotFoundException.java index c09ab4cc..c2c9a43d 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/exception/TypoNotFoundException.java +++ b/src/main/java/io/hexlet/typoreporter/handler/exception/TypoNotFoundException.java @@ -11,6 +11,7 @@ public class TypoNotFoundException extends ErrorResponseException { private static final String MESSAGE = "Typo with id=''{0}'' not found"; public TypoNotFoundException(final Long id) { - super(NOT_FOUND, ProblemDetail.forStatusAndDetail(NOT_FOUND, "Typo not found"), null, format(MESSAGE, id), new Object[]{id}); + super(NOT_FOUND, ProblemDetail.forStatusAndDetail(NOT_FOUND, "Typo not found"), + null, format(MESSAGE, id), new Object[]{id}); } } diff --git a/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceAlreadyExistException.java b/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceAlreadyExistException.java index 46bd2321..44662e31 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceAlreadyExistException.java +++ b/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceAlreadyExistException.java @@ -16,7 +16,8 @@ public class WorkspaceAlreadyExistException extends ErrorResponseException { private final String errorValue; public WorkspaceAlreadyExistException(String fieldName, String errorValue) { - super(BAD_REQUEST, ProblemDetail.forStatusAndDetail(BAD_REQUEST, "Workspace already exists"), null, format(MESSAGE_TEMPLATE, fieldName, errorValue), + super(BAD_REQUEST, ProblemDetail.forStatusAndDetail(BAD_REQUEST, "Workspace already exists"), null, + format(MESSAGE_TEMPLATE, fieldName, errorValue), new Object[]{fieldName, errorValue}); this.fieldName = fieldName; this.errorValue = errorValue; diff --git a/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceNotFoundException.java b/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceNotFoundException.java index 11e873c6..07b3a15b 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceNotFoundException.java +++ b/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceNotFoundException.java @@ -13,12 +13,12 @@ public class WorkspaceNotFoundException extends ErrorResponseException { private static final String ID_NOT_FOUND_MSG = "Workspace with id=''{0}'' not found"; public WorkspaceNotFoundException(final Long id) { - super(NOT_FOUND, ProblemDetail.forStatusAndDetail(NOT_FOUND, "Workspace not found"), null, format(ID_NOT_FOUND_MSG, id), new Object[]{id}); + super(NOT_FOUND, ProblemDetail.forStatusAndDetail(NOT_FOUND, "Workspace not found"), + null, format(ID_NOT_FOUND_MSG, id), new Object[]{id}); } public WorkspaceNotFoundException(final String wksIdStr, final Throwable cause) { super(NOT_FOUND, ProblemDetail.forStatusAndDetail(NOT_FOUND, "Workspace not found"), cause, - "Workspace with id='" + wksIdStr + "' not found" - , new Object[]{wksIdStr}); + "Workspace with id='" + wksIdStr + "' not found", new Object[]{wksIdStr}); } } diff --git a/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceRoleNotFoundException.java b/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceRoleNotFoundException.java index 1043049d..6cb3ede2 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceRoleNotFoundException.java +++ b/src/main/java/io/hexlet/typoreporter/handler/exception/WorkspaceRoleNotFoundException.java @@ -7,7 +7,8 @@ import static org.springframework.http.HttpStatus.NOT_FOUND; public class WorkspaceRoleNotFoundException extends ErrorResponseException { - private static final String NAME_NOT_FOUND_MSG = "Workspace role with accountId=''{0}'' and workspaceId=''{1}'' not found"; + private static final String NAME_NOT_FOUND_MSG = "Workspace role with accountId=''{0}'' " + + "and workspaceId=''{1}'' not found"; public WorkspaceRoleNotFoundException(final Long accountId, final Long workspaceId) { super(NOT_FOUND, ProblemDetail.forStatusAndDetail(NOT_FOUND, "Workspace role not found"), null, diff --git a/src/main/java/io/hexlet/typoreporter/service/WorkspaceService.java b/src/main/java/io/hexlet/typoreporter/service/WorkspaceService.java index 623ba683..b9e78d24 100644 --- a/src/main/java/io/hexlet/typoreporter/service/WorkspaceService.java +++ b/src/main/java/io/hexlet/typoreporter/service/WorkspaceService.java @@ -132,6 +132,7 @@ public boolean isAdminRoleUserInWorkspace(Long wksId, String email) { account.getId(), workspace.getId() ); - return workSpaceRoleOptional.filter(workspaceRole -> workspaceRole.getRole() == AccountRole.ROLE_ADMIN).isPresent(); + return workSpaceRoleOptional.filter(workspaceRole -> workspaceRole.getRole() == AccountRole.ROLE_ADMIN) + .isPresent(); } } diff --git a/src/main/java/io/hexlet/typoreporter/service/account/signup/SignupAccount.java b/src/main/java/io/hexlet/typoreporter/service/account/signup/SignupAccount.java index b4c6c978..cd8f120c 100644 --- a/src/main/java/io/hexlet/typoreporter/service/account/signup/SignupAccount.java +++ b/src/main/java/io/hexlet/typoreporter/service/account/signup/SignupAccount.java @@ -10,6 +10,7 @@ public record SignupAccount( @Override public String toString() { - return "SignupAccount(username=%s, email=%s, firstName=%s, lastName=%s)".formatted(username, email, firstName, lastName); + return "SignupAccount(username=%s, email=%s, firstName=%s, lastName=%s)" + .formatted(username, email, firstName, lastName); } } diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchConsiderCase.java b/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchConsiderCase.java index c704c6c5..3e3b489f 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchConsiderCase.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchConsiderCase.java @@ -21,7 +21,10 @@ *
* Example, compare more than 1 pair of fields: *
- * {@code @FieldMatchConsiderCase(first = "password", second = "confirmPassword", message = "The password and it confirmation must match")} + * {@code @FieldMatchConsiderCase( + * first = "password", + * second = "confirmPassword", + * message = "The password and it confirmation must match")} */ @Constraint(validatedBy = FieldMatchConsiderCaseValidator.class) public @interface FieldMatchConsiderCase { diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCase.java b/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCase.java index 46aff967..10ef80c2 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCase.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCase.java @@ -21,7 +21,10 @@ *
* Example, compare more than 1 pair of fields: *
- * {@code @FieldMatchConsiderCase(first = "password", second = "confirmPassword", message = "The password and it confirmation must match")} + * {@code @FieldMatchConsiderCase( + * first = "password", + * second = "confirmPassword", + * message = "The password and it confirmation must match")} */ @Target({TYPE, ANNOTATION_TYPE}) @Retention(RUNTIME) diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCaseValidator.java b/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCaseValidator.java index c98e0f6c..de9ec4b4 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCaseValidator.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/FieldMatchIgnoreCaseValidator.java @@ -1,13 +1,7 @@ package io.hexlet.typoreporter.service.dto; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; -import org.springframework.beans.PropertyAccessorFactory; - import java.util.Objects; -import static java.text.MessageFormat.format; - public class FieldMatchIgnoreCaseValidator extends AbstractFieldMatchValidator { @Override public void initialize(final FieldMatchIgnoreCase constraintAnnotation) { diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/account/InfoAccount.java b/src/main/java/io/hexlet/typoreporter/service/dto/account/InfoAccount.java index 18bcb131..58c860cb 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/account/InfoAccount.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/account/InfoAccount.java @@ -6,4 +6,4 @@ public record InfoAccount( String username, String firstName, String lastName -) {} +) { } diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdatePassword.java b/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdatePassword.java index 95e61c2a..4695a9b8 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdatePassword.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdatePassword.java @@ -9,7 +9,10 @@ @Getter @Setter @Accessors(chain = true) -@FieldMatchConsiderCase(first = "newPassword", second = "confirmNewPassword", message = "The password and it confirmation must match") +@FieldMatchConsiderCase( + first = "newPassword", + second = "confirmNewPassword", + message = "The password and it confirmation must match") public class UpdatePassword { private String oldPassword; diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/workspace/WorkspaceRoleInfo.java b/src/main/java/io/hexlet/typoreporter/service/dto/workspace/WorkspaceRoleInfo.java index 528e988c..276383c9 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/workspace/WorkspaceRoleInfo.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/workspace/WorkspaceRoleInfo.java @@ -2,7 +2,7 @@ import io.hexlet.typoreporter.domain.workspace.AccountRole; -public record WorkspaceRoleInfo ( +public record WorkspaceRoleInfo( Long workspaceId, Long accountId, String workspaceName, diff --git a/src/main/java/io/hexlet/typoreporter/service/mapper/TypoMapper.java b/src/main/java/io/hexlet/typoreporter/service/mapper/TypoMapper.java index 10f7e058..072f22d1 100644 --- a/src/main/java/io/hexlet/typoreporter/service/mapper/TypoMapper.java +++ b/src/main/java/io/hexlet/typoreporter/service/mapper/TypoMapper.java @@ -15,7 +15,7 @@ @Mapper public interface TypoMapper { - PrettyTime prettyTime = new PrettyTime(); + PrettyTime PRETTY_TIME = new PrettyTime(); Typo toTypo(TypoReport source); @@ -28,7 +28,7 @@ public interface TypoMapper { @Named(value = "mapToPrettyDateAgo") default String getDateAgoAsString(Instant date) { - prettyTime.setLocale(LocaleContextHolder.getLocale()); - return prettyTime.format(date); + PRETTY_TIME.setLocale(LocaleContextHolder.getLocale()); + return PRETTY_TIME.format(date); } } diff --git a/src/main/java/io/hexlet/typoreporter/service/mapper/WorkspaceMapper.java b/src/main/java/io/hexlet/typoreporter/service/mapper/WorkspaceMapper.java index fe12ea91..94f07bd2 100644 --- a/src/main/java/io/hexlet/typoreporter/service/mapper/WorkspaceMapper.java +++ b/src/main/java/io/hexlet/typoreporter/service/mapper/WorkspaceMapper.java @@ -14,7 +14,7 @@ @Mapper public interface WorkspaceMapper { - PrettyTime prettyTime = new PrettyTime(); + PrettyTime PRETTY_TIME = new PrettyTime(); Workspace toWorkspace(CreateWorkspace source); @@ -24,7 +24,7 @@ public interface WorkspaceMapper { @Named(value = "mapToPrettyDateAgo") default String getDateAgoAsString(Instant date) { - prettyTime.setLocale(LocaleContextHolder.getLocale()); - return prettyTime.format(date); + PRETTY_TIME.setLocale(LocaleContextHolder.getLocale()); + return PRETTY_TIME.format(date); } } diff --git a/src/main/java/io/hexlet/typoreporter/utils/ValidationEmail.java b/src/main/java/io/hexlet/typoreporter/utils/ValidationEmail.java index 67f9e050..36787bf7 100644 --- a/src/main/java/io/hexlet/typoreporter/utils/ValidationEmail.java +++ b/src/main/java/io/hexlet/typoreporter/utils/ValidationEmail.java @@ -1,6 +1,7 @@ package io.hexlet.typoreporter.utils; -import java.util.regex.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ValidationEmail { public static boolean isValidEmail(String email) { diff --git a/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java b/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java index 8ca55d06..16e5edee 100644 --- a/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java +++ b/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java @@ -3,7 +3,6 @@ import io.hexlet.typoreporter.domain.account.constraint.AccountPassword; import io.hexlet.typoreporter.domain.account.constraint.AccountUsername; import io.hexlet.typoreporter.service.dto.FieldMatchConsiderCase; -import io.hexlet.typoreporter.service.dto.FieldMatchIgnoreCase; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; @@ -17,7 +16,10 @@ @Setter @AllArgsConstructor @NoArgsConstructor -@FieldMatchConsiderCase(first = "password", second = "confirmPassword", message = "The password and it confirmation must match") +@FieldMatchConsiderCase( + first = "password", + second = "confirmPassword", + message = "The password and it confirmation must match") @ToString public class SignupAccountModel { diff --git a/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java b/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java index 2f63a0f2..c58c57f0 100644 --- a/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java +++ b/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java @@ -1,7 +1,10 @@ package io.hexlet.typoreporter.web.model; -import jakarta.validation.constraints.*; -import lombok.*; +import jakarta.validation.constraints.Email; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Getter @Setter diff --git a/src/test/java/io/hexlet/typoreporter/repository/TypoRepositoryIT.java b/src/test/java/io/hexlet/typoreporter/repository/TypoRepositoryIT.java index 7e656a8a..4594a51b 100644 --- a/src/test/java/io/hexlet/typoreporter/repository/TypoRepositoryIT.java +++ b/src/test/java/io/hexlet/typoreporter/repository/TypoRepositoryIT.java @@ -7,17 +7,23 @@ import io.hexlet.typoreporter.domain.typo.Typo; import io.hexlet.typoreporter.test.DBUnitEnumPostgres; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.*; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullSource; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import org.springframework.dao.*; -import org.springframework.data.domain.*; -import org.springframework.test.context.*; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.transaction.annotation.Transactional; import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.junit.jupiter.*; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import static com.github.database.rider.core.api.configuration.Orthography.LOWERCASE; import static io.hexlet.typoreporter.test.Constraints.POSTGRES_IMAGE; diff --git a/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRepositoryIT.java b/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRepositoryIT.java index 71c7f130..88b1373b 100644 --- a/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRepositoryIT.java +++ b/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRepositoryIT.java @@ -7,15 +7,20 @@ import io.hexlet.typoreporter.domain.workspace.Workspace; import io.hexlet.typoreporter.test.DBUnitEnumPostgres; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.*; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullSource; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import org.springframework.test.context.*; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.transaction.annotation.Transactional; import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.junit.jupiter.*; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + import static com.github.database.rider.core.api.configuration.Orthography.LOWERCASE; import static io.hexlet.typoreporter.test.Constraints.POSTGRES_IMAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -29,7 +34,7 @@ @DataSet(value = {"workspaces.yml", "typos.yml"}) @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class WorkspaceRepositoryIT { - final Integer SUCCESSFUL_CODE = 1; + private static final Integer SUCCESSFUL_CODE = 1; @Container public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>(POSTGRES_IMAGE) diff --git a/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRoleRepositoryIT.java b/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRoleRepositoryIT.java index f65b7652..e29cbbf4 100644 --- a/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRoleRepositoryIT.java +++ b/src/test/java/io/hexlet/typoreporter/repository/WorkspaceRoleRepositoryIT.java @@ -4,7 +4,6 @@ import com.github.database.rider.core.api.dataset.DataSet; import com.github.database.rider.spring.api.DBRider; import io.hexlet.typoreporter.config.audit.AuditConfiguration; -import io.hexlet.typoreporter.domain.account.Account; import io.hexlet.typoreporter.domain.workspace.WorkspaceRole; import io.hexlet.typoreporter.test.DBUnitEnumPostgres; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/io/hexlet/typoreporter/service/TypoServiceIT.java b/src/test/java/io/hexlet/typoreporter/service/TypoServiceIT.java index 92a30b36..5ddaf8cb 100644 --- a/src/test/java/io/hexlet/typoreporter/service/TypoServiceIT.java +++ b/src/test/java/io/hexlet/typoreporter/service/TypoServiceIT.java @@ -41,7 +41,8 @@ import static io.hexlet.typoreporter.domain.typo.TypoStatus.REPORTED; import static io.hexlet.typoreporter.domain.typo.TypoStatus.RESOLVED; import static io.hexlet.typoreporter.test.Constraints.POSTGRES_IMAGE; -import static io.hexlet.typoreporter.test.factory.EntitiesFactory.*; +import static io.hexlet.typoreporter.test.factory.EntitiesFactory.WORKSPACE_101_ID; +import static io.hexlet.typoreporter.test.factory.EntitiesFactory.WORKSPACE_103_ID; import static java.util.function.Predicate.not; import static org.assertj.core.api.Assertions.assertThat; @@ -219,7 +220,7 @@ void getCountTypoByStatusForWorkspaceId() { @Test void getLastTypoByWorkspaceId() { - Optional Top = repository.findAll() + Optional top = repository.findAll() .stream() .filter(x -> x.getWorkspace().getId().equals(WORKSPACE_101_ID)) .sorted(Comparator.comparing(AbstractAuditingEntity::getCreatedDate)) @@ -228,7 +229,7 @@ void getLastTypoByWorkspaceId() { Optional typoInfo = service.getLastTypoByWorkspaceId(WORKSPACE_101_ID); assertThat(typoInfo).isNotEmpty(); - assertThat(typoInfo.get().id()).isEqualTo(Top.get().getId()); + assertThat(typoInfo.get().id()).isEqualTo(top.get().getId()); Optional typoInfo2 = service.getLastTypoByWorkspaceId(WORKSPACE_103_ID); assertThat(typoInfo2).isEmpty(); } diff --git a/src/test/java/io/hexlet/typoreporter/service/mapper/WorkspaceToWorkspaceInfoTest.java b/src/test/java/io/hexlet/typoreporter/service/mapper/WorkspaceToWorkspaceInfoTest.java index 4fe928ac..b5ff1c18 100644 --- a/src/test/java/io/hexlet/typoreporter/service/mapper/WorkspaceToWorkspaceInfoTest.java +++ b/src/test/java/io/hexlet/typoreporter/service/mapper/WorkspaceToWorkspaceInfoTest.java @@ -16,7 +16,8 @@ class WorkspaceToWorkspaceInfoTest { void requestWorkspaceToInfo(final Workspace workspace) { final var workspaceInfo = workspaceMapper.toWorkspaceInfo(workspace); assertThat(workspaceInfo).usingRecursiveComparison() - .ignoringFields("createdBy", "createdDate", "createdDateAgo", "modifiedBy", "modifiedDate", "modifiedDateAgo") + .ignoringFields("createdBy", "createdDate", "createdDateAgo", "modifiedBy", + "modifiedDate", "modifiedDateAgo") .isEqualTo(workspace); } } diff --git a/src/test/java/io/hexlet/typoreporter/test/DBUnitEnumPostgres.java b/src/test/java/io/hexlet/typoreporter/test/DBUnitEnumPostgres.java index e56c0e16..9036938f 100644 --- a/src/test/java/io/hexlet/typoreporter/test/DBUnitEnumPostgres.java +++ b/src/test/java/io/hexlet/typoreporter/test/DBUnitEnumPostgres.java @@ -1,6 +1,7 @@ package io.hexlet.typoreporter.test; -import org.dbunit.dataset.datatype.*; +import org.dbunit.dataset.datatype.DataType; +import org.dbunit.dataset.datatype.DataTypeException; import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; import org.springframework.context.annotation.Configuration; diff --git a/src/test/java/io/hexlet/typoreporter/test/asserts/ReportedTypoAssert.java b/src/test/java/io/hexlet/typoreporter/test/asserts/ReportedTypoAssert.java index bc5a521b..7e637b49 100644 --- a/src/test/java/io/hexlet/typoreporter/test/asserts/ReportedTypoAssert.java +++ b/src/test/java/io/hexlet/typoreporter/test/asserts/ReportedTypoAssert.java @@ -1,7 +1,8 @@ package io.hexlet.typoreporter.test.asserts; import io.hexlet.typoreporter.domain.typo.Typo; -import io.hexlet.typoreporter.service.dto.typo.*; +import io.hexlet.typoreporter.service.dto.typo.ReportedTypo; +import io.hexlet.typoreporter.service.dto.typo.TypoReport; import org.assertj.core.api.ObjectAssert; public class ReportedTypoAssert extends ObjectAssert { diff --git a/src/test/java/io/hexlet/typoreporter/test/asserts/TypoAssert.java b/src/test/java/io/hexlet/typoreporter/test/asserts/TypoAssert.java index 37e61b8f..2c050bd0 100644 --- a/src/test/java/io/hexlet/typoreporter/test/asserts/TypoAssert.java +++ b/src/test/java/io/hexlet/typoreporter/test/asserts/TypoAssert.java @@ -18,7 +18,8 @@ public TypoAssert isEqualsToTypoReport(TypoReport expected) { isNotNull(); assertThat(actual) .usingRecursiveComparison() - .ignoringFields("id", "typoStatus", "createdDate", "createdBy", "modifiedDate", "modifiedBy", "workspace", "account") + .ignoringFields("id", "typoStatus", "createdDate", "createdBy", + "modifiedDate", "modifiedBy", "workspace", "account") .isEqualTo(expected); return this; } diff --git a/src/test/java/io/hexlet/typoreporter/test/asserts/TypoInfoAssert.java b/src/test/java/io/hexlet/typoreporter/test/asserts/TypoInfoAssert.java index f378afff..b02a7546 100644 --- a/src/test/java/io/hexlet/typoreporter/test/asserts/TypoInfoAssert.java +++ b/src/test/java/io/hexlet/typoreporter/test/asserts/TypoInfoAssert.java @@ -18,7 +18,8 @@ public TypoInfoAssert isEqualsToTypoInfo(Typo expected) { isNotNull(); assertThat(actual) .usingRecursiveComparison() - .ignoringFields("typoStatusStr", "createdBy", "createdDateAgo", "createdDate", "modifiedBy", "modifiedDateAgo", "modifiedDate", "account") + .ignoringFields("typoStatusStr", "createdBy", "createdDateAgo", + "createdDate", "modifiedBy", "modifiedDateAgo", "modifiedDate", "account") .isEqualTo(expected); return this; } diff --git a/src/test/java/io/hexlet/typoreporter/web/LoginIT.java b/src/test/java/io/hexlet/typoreporter/web/LoginIT.java index a3ded431..29d387bc 100644 --- a/src/test/java/io/hexlet/typoreporter/web/LoginIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/LoginIT.java @@ -16,6 +16,7 @@ import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; + import static com.github.database.rider.core.api.configuration.Orthography.LOWERCASE; import static io.hexlet.typoreporter.test.Constraints.POSTGRES_IMAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -48,13 +49,13 @@ static void datasourceProperties(DynamicPropertyRegistry registry) { @Autowired private AccountRepository accountRepository; - private final String EMAIL_UPPER_CASE = "EMAIL_ADDRESS@GOOGLE.COM"; - private final String EMAIL_LOWER_CASE = EMAIL_UPPER_CASE.toLowerCase(); + private static final String EMAIL_UPPER_CASE = "EMAIL_ADDRESS@GOOGLE.COM"; + private static final String EMAIL_LOWER_CASE = EMAIL_UPPER_CASE.toLowerCase(); private SignupAccountModel model = new SignupAccountModel( "model_upper_case", EMAIL_UPPER_CASE, - "password","password", + "password", "password", "firstName", "lastName"); @Test @@ -72,20 +73,19 @@ void loginByEmailInAnyCaseSuccess() throws Exception { assertThat(accountRepository.findAccountByEmail(EMAIL_LOWER_CASE)).isNotEmpty(); String locationHeaderStrLowerCaseEmail = mockMvc.perform(post("/login") - .param("email", EMAIL_LOWER_CASE) - .param("password", model.getPassword()) - .with(csrf())) - .andReturn() - .getResponse() - .getHeader("Location"); + .param("email", EMAIL_LOWER_CASE) + .param("password", model.getPassword()) + .with(csrf())) + .andReturn() + .getResponse() + .getHeader("Location"); assertThat(locationHeaderStrLowerCaseEmail).contains("workspaces"); String locationHeaderStrBadEmail = mockMvc.perform(post("/login") .param("email", "bad@email.com") .param("password", model.getPassword()) - .with(csrf()) - ).andReturn().getResponse().getHeader("Location"); - assertThat(locationHeaderStrBadEmail).doesNotContain ("workspaces"); + .with(csrf())).andReturn().getResponse().getHeader("Location"); + assertThat(locationHeaderStrBadEmail).doesNotContain("workspaces"); assertThat(locationHeaderStrBadEmail).contains("login"); String locationHeaderStrUpperCaseEmail = mockMvc.perform(post("/login") diff --git a/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java index c6adcad2..81ce229d 100644 --- a/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java @@ -16,6 +16,7 @@ import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.containers.PostgreSQLContainer; + import static com.github.database.rider.core.api.configuration.Orthography.LOWERCASE; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -49,16 +50,16 @@ static void datasourceProperties(DynamicPropertyRegistry registry) { @Autowired private AccountRepository accountRepository; - private final String EMAIL_UPPER_CASE = "EMAIL_ADDRESS@GOOGLE.COM"; - private final String EMAIL_LOWER_CASE = EMAIL_UPPER_CASE.toLowerCase(); + private static final String EMAIL_UPPER_CASE = "EMAIL_ADDRESS@GOOGLE.COM"; + private static final String EMAIL_LOWER_CASE = EMAIL_UPPER_CASE.toLowerCase(); private final SignupAccountModel model = new SignupAccountModel( "model_upper_case", EMAIL_UPPER_CASE, - "password","password", + "password", "password", "firstName", "lastName"); - private final SignupAccountModel anotherModelWithSameButLowerCaseEmail = new SignupAccountModel( + private final SignupAccountModel anotherModelWithSameButLowerCaseEmail = new SignupAccountModel( "model_lower_case", EMAIL_LOWER_CASE, "another_password", "another_password", diff --git a/src/test/java/io/hexlet/typoreporter/web/TypoControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/TypoControllerIT.java index 9d5da850..01e25ff5 100644 --- a/src/test/java/io/hexlet/typoreporter/web/TypoControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/TypoControllerIT.java @@ -114,8 +114,8 @@ void updateTypoStatusWithEventIsEmpty(final Long typoId) throws Exception { @ParameterizedTest @MethodSource("io.hexlet.typoreporter.test.factory.EntitiesFactory#getWorkspaceIdsExist") void updateTypoStatusWithUpdatedTypoIsEmpty(final Long wksId) throws Exception { - final Long NOT_EXIST_TYPO_ID = 11L; - mockMvc.perform(patch("/typos/{id}/status", NOT_EXIST_TYPO_ID) + Long nonExistTypoId = 11L; + mockMvc.perform(patch("/typos/{id}/status", nonExistTypoId) .param("wksId", wksId.toString()) .param("event", CANCEL.name()) .with(csrf())) diff --git a/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java index d9577c79..b3d6fbd6 100644 --- a/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java @@ -67,11 +67,13 @@ @AutoConfigureMockMvc @Transactional @DBRider -@DBUnit(caseInsensitiveStrategy = LOWERCASE, dataTypeFactoryClass = DBUnitEnumPostgres.class, cacheConnection = false) +@DBUnit(caseInsensitiveStrategy = LOWERCASE, + dataTypeFactoryClass = DBUnitEnumPostgres.class, + cacheConnection = false) @DataSet(value = {"workspaces.yml", "workspaceRoles.yml", "accounts.yml", "typos.yml"}) class WorkspaceControllerIT { - private final Long NOT_EXISTING_WKS_ID = 9999L; + private static final Long NOT_EXISTING_WKS_ID = 9999L; @Container static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>(POSTGRES_IMAGE) @@ -151,7 +153,8 @@ void getWorkspaceTyposPageIsSuccessful(final Long wksId, final String email) thr MockHttpServletResponse response = mockMvc.perform(get("/workspace/{wksId}/typos", wksId) .with(user(email))) - .andExpect(model().attributeExists("wksInfo", "wksName", "typoPage", "availableSizes", "sortProp", "sortDir", "DESC", "ASC")) + .andExpect(model().attributeExists("wksInfo", "wksName", + "typoPage", "availableSizes", "sortProp", "sortDir", "DESC", "ASC")) .andReturn().getResponse(); Typo typo = workspace.getTypos().stream() @@ -167,14 +170,16 @@ void getWorkspaceTyposPageIsSuccessful(final Long wksId, final String email) thr @ParameterizedTest @MethodSource("io.hexlet.typoreporter.test.factory.EntitiesFactory#getWorkspacesAndUsersAndTypoStatusRelated") - void getWorkspaceTyposPageFilteredIsSuccessful(final Long wksId, final String email, final String typoStatus) throws Exception { + void getWorkspaceTyposPageFilteredIsSuccessful(final Long wksId, final String email, + final String typoStatus) throws Exception { Workspace workspace = repository.getWorkspaceById(wksId).orElse(null); var request = get("/workspace/{wksId}/typos", wksId).queryParam("typoStatus", typoStatus); MockHttpServletResponse response = mockMvc.perform(request .with(user(email))) - .andExpect(model().attributeExists("wksInfo", "wksName", "typoPage", "availableSizes", "sortProp", "sortDir", "DESC", "ASC", "typoStatus")) + .andExpect(model().attributeExists("wksInfo", "wksName", "typoPage", + "availableSizes", "sortProp", "sortDir", "DESC", "ASC", "typoStatus")) .andReturn().getResponse(); Typo typo = workspace.getTypos().stream() @@ -324,7 +329,8 @@ void getWorkspaceUsersPage(final Long wksId, final String email) throws Exceptio accounts.forEach(account -> { final var workspaceRoleId = new WorkspaceRoleId(workspace.getId(), account.getId()); - final var workspaceRole = new WorkspaceRole(workspaceRoleId, AccountRole.ROLE_ANONYMOUS, workspace, account); + final var workspaceRole = new WorkspaceRole(workspaceRoleId, AccountRole.ROLE_ANONYMOUS, + workspace, account); workspace.addWorkspaceRole(workspaceRole); }); @@ -332,7 +338,8 @@ void getWorkspaceUsersPage(final Long wksId, final String email) throws Exceptio get("/workspace/{wksId}/users", wksId) .with(user(email))) .andExpect(status().isOk()) - .andExpect(model().attributeExists("wksInfo", "wksName", "userPage", "availableSizes", "sortProp", "sortDir", "DESC", "ASC")) + .andExpect(model().attributeExists("wksInfo", "wksName", + "userPage", "availableSizes", "sortProp", "sortDir", "DESC", "ASC")) .andReturn().getResponse(); var html = response.getContentAsString(); @@ -352,7 +359,8 @@ void delUserFromWorkspace() throws Exception { .with(user(ACCOUNT_103_EMAIL)) .with(csrf())); assertThat(workspaceRoleRepository.count()).isEqualTo(rolesCountBeforeAdding + 1L); - Optional addedWksRoleOptional = workspaceRoleRepository.getWorkspaceRoleByAccountIdAndWorkspaceId(ACCOUNT_102_ID, WORKSPACE_103_ID); + Optional addedWksRoleOptional = workspaceRoleRepository + .getWorkspaceRoleByAccountIdAndWorkspaceId(ACCOUNT_102_ID, WORKSPACE_103_ID); assertThat(addedWksRoleOptional).isNotEmpty(); mockMvc.perform( @@ -361,7 +369,8 @@ void delUserFromWorkspace() throws Exception { .with(user(ACCOUNT_102_EMAIL)) .with(csrf())); assertThat(workspaceRoleRepository.count()).isEqualTo(rolesCountBeforeAdding + 1L); - Optional addedWksRoleStillThereOptional = workspaceRoleRepository.getWorkspaceRoleByAccountIdAndWorkspaceId(ACCOUNT_102_ID, WORKSPACE_103_ID); + Optional addedWksRoleStillThereOptional = workspaceRoleRepository + .getWorkspaceRoleByAccountIdAndWorkspaceId(ACCOUNT_102_ID, WORKSPACE_103_ID); assertThat(addedWksRoleStillThereOptional).isNotEmpty(); mockMvc.perform( @@ -370,7 +379,8 @@ void delUserFromWorkspace() throws Exception { .with(user(ACCOUNT_103_EMAIL)) .with(csrf())); assertThat(workspaceRoleRepository.count()).isEqualTo(rolesCountBeforeAdding); - Optional addedWksRoleDeletedOptional = workspaceRoleRepository.getWorkspaceRoleByAccountIdAndWorkspaceId(ACCOUNT_102_ID, WORKSPACE_103_ID); + Optional addedWksRoleDeletedOptional = workspaceRoleRepository + .getWorkspaceRoleByAccountIdAndWorkspaceId(ACCOUNT_102_ID, WORKSPACE_103_ID); assertThat(addedWksRoleDeletedOptional).isEmpty(); } } diff --git a/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java index f1a35d1b..d532e73a 100644 --- a/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java @@ -119,16 +119,17 @@ void patchWorkspaceTokenIsSuccessful(final Long wksId, final String email) throw @ParameterizedTest @MethodSource("io.hexlet.typoreporter.test.factory.EntitiesFactory#getWorkspaceAndNotAdminRelated") - void patchWorkspaceTokenWithNoRights(final Long wksId, final String email) throws Exception { + void patchWorkspaceTokenWithNoRights(final Long wksId, final String email) throws Exception { String previousWksToken = workspaceSettingsRepository.getWorkspaceSettingsByWorkspaceId(wksId) .map(WorkspaceSettings::getApiAccessToken) .map(UUID::toString) .orElse(null); - MockHttpServletResponse response = mockMvc.perform(patch("/workspace/{wksId}/token/regenerate", wksId.toString()) - .with(user(email)) - .with(csrf())) - .andReturn().getResponse(); + MockHttpServletResponse response = + mockMvc.perform(patch("/workspace/{wksId}/token/regenerate", wksId.toString()) + .with(user(email)) + .with(csrf())) + .andReturn().getResponse(); String newWksToken = workspaceSettingsRepository.getWorkspaceSettingsByWorkspaceId(wksId) .map(WorkspaceSettings::getApiAccessToken) From 8af15e50d1ec4d42769dc17bd0ace4078ed6bc91 Mon Sep 17 00:00:00 2001 From: kitdim Date: Thu, 23 May 2024 12:38:33 +0300 Subject: [PATCH 2/2] add a command ./gradlew checkstyleTest --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7ff77c19..7986779d 100644 --- a/Makefile +++ b/Makefile @@ -46,3 +46,4 @@ vagrant-run: lint: ./gradlew checkstyleMain + ./gradlew checkstyleTest