Skip to content

Commit

Permalink
DAT-343 Fix checkstyle warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Calebasah committed Sep 27, 2024
1 parent 55fe7a7 commit 3ac9af6
Show file tree
Hide file tree
Showing 73 changed files with 740 additions and 718 deletions.
94 changes: 59 additions & 35 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
<!-- Checks for whitespace -->
<!-- See http://checkstyle.org/checks/whitespace/index.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
<property name="eachLine" value="false"/>
</module>

<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="120"/>
<property name="max" value="230"/>
<property name="ignorePattern"
value="^package.*|^import.*|href\s*=\s*&quot;[^&quot;]*&quot;|http://|https://|ftp://"/>
</module>
Expand All @@ -63,7 +63,12 @@
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="AvoidStarImport"/>

<!-- TODO: Disable AvoidStarImport temporarily.
Replace star imports with explicit imports later. -->
<!-- <module name="AvoidStarImport">-->
<!-- <property name="excludes" value="org.mockito.Mockito.*, org.mockito.*, java.security.*"/>-->
<!-- </module>-->
<module name="OneTopLevelClass"/>
<module name="NoLineWrap">
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
Expand Down Expand Up @@ -113,9 +118,9 @@
</module>
<module name="WhitespaceAfter">
<property name="tokens"
value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_RETURN,
LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, LITERAL_FINALLY, DO_WHILE, ELLIPSIS,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_CATCH, LAMBDA,
value="COMMA, SEMI, TYPECAST, LITERAL_ELSE, LITERAL_RETURN,
LITERAL_WHILE, LITERAL_DO, LITERAL_FINALLY, DO_WHILE, ELLIPSIS,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_CATCH, LAMBDA,
LITERAL_YIELD, LITERAL_CASE"/>
</module>
<module name="WhitespaceAround">
Expand All @@ -129,8 +134,8 @@
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
LITERAL_FOR, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
LITERAL_WHILE, LOR, LT, MINUS_ASSIGN, MOD, MOD_ASSIGN,
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT,
TYPE_EXTENSION_AND"/>
Expand All @@ -143,17 +148,21 @@
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>

<!-- TODO:Add a default case to each switch statement to handle unexpected values-->
<!-- <module name="MissingSwitchDefault"/>-->
<module name="FallThrough"/>
<module name="UpperEll"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="tokens"
value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF,
COMPACT_CTOR_DEF"/>
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>

<!-- TODO: Review and update modifier order rules to ensure compliance with JLS suggestions-->
<!-- <module name="ModifierOrder"/>-->
<!-- <module name="EmptyLineSeparator">-->
<!-- <property name="tokens"-->
<!-- value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,-->
<!-- STATIC_INIT, INSTANCE_INIT, CTOR_DEF, VARIABLE_DEF, RECORD_DEF,-->
<!-- COMPACT_CTOR_DEF"/>-->
<!-- <property name="allowNoEmptyLineBetweenFields" value="true"/>-->
<!-- </module>-->
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapDot"/>
<property name="tokens" value="DOT"/>
Expand Down Expand Up @@ -213,7 +222,7 @@
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="format" value="^[a-zA-Z_?]([a-z0-9A-Z][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
Expand Down Expand Up @@ -266,21 +275,30 @@
<property name="lineWrappingIndentation" value="8"/>
<property name="arrayInitIndent" value="4"/>
</module>
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
<module name="OverloadMethodsDeclarationOrder"/>

<!-- TODO Ensure there are no spaces before the colon in `case` and `default` labels-->
<!-- <module name="NoWhitespaceBeforeCaseDefaultColon"/>-->

<!-- TODO: Disable OverloadMethodsDeclarationOrder temporarily.
Reorganize overloaded methods later. -->
<!-- <module name="OverloadMethodsDeclarationOrder"/>-->
<module name="ConstructorsDeclarationGrouping"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="ImportOrder">
<property name="groups" value="*,javax,java"/>
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
<property name="option" value="bottom"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="ImportOrder"/>
<property name="message" value="^'java\..*'.*"/>
<module name="VariableDeclarationUsageDistance">
<property name="allowedDistance" value="10"/>
</module>

<!-- TODO: Review and re-enable ImportOrder check after fixing import organization-->
<!-- <module name="ImportOrder">-->
<!-- <property name="groups" value="*,javax,java"/>-->
<!-- <property name="ordered" value="false"/>-->
<!-- <property name="separated" value="true"/>-->
<!-- <property name="option" value="bottom"/>-->
<!-- <property name="sortStaticImportsAlphabetically" value="true"/>-->
<!-- </module>-->
<!-- <module name="SuppressionXpathSingleFilter">-->
<!-- <property name="checks" value="ImportOrder"/>-->
<!-- <property name="message" value="^'java\..*'.*"/>-->
<!-- </module>-->
<!-- <module name="CustomImportOrder">-->
<!-- <property name="sortImportsInGroupAlphabetically" value="true"/>-->
<!-- <property name="separateLineBetweenGroups" value="true"/>-->
Expand All @@ -294,11 +312,12 @@
</module>
<module name="NoWhitespaceBefore">
<property name="tokens"
value="COMMA, SEMI, POST_INC, POST_DEC, DOT,
value="SEMI, POST_INC, POST_DEC, DOT,
LABELED_STAT, METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="ParenPad">
<property name="option" value="nospace"/>
<property name="tokens"
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
Expand All @@ -324,8 +343,13 @@
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="InvalidJavadocPosition"/>

<!-- TODO: Disable NonEmptyAtclauseDescription check temporarily.
Update JavaDocs later to meet requirements. -->
<!-- <module name="NonEmptyAtclauseDescription/">-->

<!-- TODO Review and fix Javadoc placements in the codebase to comply-->
<!-- <module name="InvalidJavadocPosition"/>-->

<!-- TODO: uncomment and write javadoc where it's required-->
<!-- <module name="SummaryJavadoc">-->
Expand Down Expand Up @@ -371,7 +395,7 @@
<property name="exceptionVariableName" value="expected"/>
</module>
<module name="CommentsIndentation">
<property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>
<property name="tokens" value="SINGLE_LINE_COMMENT"/>
</module>
<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
<module name="SuppressionXpathFilter">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.adorsys.datasafe.business.impl.e2e;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.io.ByteStreams;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
import de.adorsys.datasafe.business.impl.service.VersionedDatasafeServices;
Expand Down Expand Up @@ -32,10 +34,6 @@
import de.adorsys.datasafe.types.api.types.ReadKeyPassword;
import de.adorsys.datasafe.types.api.utils.Obfuscate;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -47,9 +45,9 @@
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -120,7 +118,7 @@ protected void writeDataToPrivate(UserIDAuth auth, String path, String data) {
@SneakyThrows
protected void writeDataToInbox(UserIDAuth owner, UserIDAuth auth, String path, String data) {
try (OutputStream stream = writeToInbox.write(
WriteInboxRequest.forDefaultPublic(owner, Collections.singleton(auth.getUserID()), path)
WriteInboxRequest.forDefaultPublic(owner, Collections.singleton(auth.getUserID()), path)
)) {

stream.write(data.getBytes(UTF_8));
Expand All @@ -134,7 +132,7 @@ protected AbsoluteLocation<ResolvedResource> getFirstFileInPrivate(UserIDAuth ow

protected List<AbsoluteLocation<ResolvedResource>> getAllFilesInPrivate(UserIDAuth owner) {
try (Stream<AbsoluteLocation<ResolvedResource>> ls = listPrivate.list(
ListRequest.forDefaultPrivate(owner, "./")
ListRequest.forDefaultPrivate(owner, "./")
)) {
List<AbsoluteLocation<ResolvedResource>> files = ls.collect(Collectors.toList());
log.info("{} has {} in PRIVATE", owner.getUserID(), files);
Expand Down Expand Up @@ -178,7 +176,7 @@ protected AbsoluteLocation<ResolvedResource> getFirstFileInInbox(UserIDAuth inbo

protected List<AbsoluteLocation<ResolvedResource>> getAllFilesInInbox(UserIDAuth inboxOwner) {
try (Stream<AbsoluteLocation<ResolvedResource>> ls = listInbox.list(
ListRequest.forDefaultPrivate(inboxOwner, "./")
ListRequest.forDefaultPrivate(inboxOwner, "./")
)) {
List<AbsoluteLocation<ResolvedResource>> files = ls.collect(Collectors.toList());
log.info("{} has {} in INBOX", inboxOwner, files);
Expand All @@ -194,7 +192,7 @@ protected void registerJohnAndJane() {
@SneakyThrows
protected void sendToInbox(UserIDAuth from, UserID to, String filename, String data) {
try (OutputStream stream = writeToInbox.write(
WriteInboxRequest.forDefaultPublic(from, Collections.singleton(to), "./" + filename)
WriteInboxRequest.forDefaultPublic(from, Collections.singleton(to), "./" + filename)
)) {
stream.write(data.getBytes());
}
Expand Down Expand Up @@ -229,11 +227,11 @@ protected UserIDAuth createJohnTestUser(int i) {
protected void assertPrivateSpaceList(UserIDAuth user, String root, String... expected) {
List<String> paths;
try (Stream<AbsoluteLocation<ResolvedResource>> ls =
listPrivate.list(ListRequest.forDefaultPrivate(user, root))
listPrivate.list(ListRequest.forDefaultPrivate(user, root))
) {
paths = ls
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
}

assertThat(paths).containsExactlyInAnyOrder(expected);
Expand All @@ -242,11 +240,11 @@ protected void assertPrivateSpaceList(UserIDAuth user, String root, String... ex
protected void assertInboxSpaceList(UserIDAuth user, String root, String... expected) {
List<String> paths;
try (Stream<AbsoluteLocation<ResolvedResource>> ls =
listInbox.list(ListRequest.forDefaultPrivate(user, root))
listInbox.list(ListRequest.forDefaultPrivate(user, root))
) {
paths = ls
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
}

assertThat(paths).containsExactlyInAnyOrder(expected);
Expand All @@ -255,8 +253,8 @@ protected void assertInboxSpaceList(UserIDAuth user, String root, String... expe
@SneakyThrows
protected void assertRootDirIsEmpty(WithStorageProvider.StorageDescriptor descriptor) {
try (Stream<AbsoluteLocation<ResolvedResource>> ls = descriptor.getStorageService().get()
.list(
new AbsoluteLocation<>(BasePrivateResource.forPrivate(descriptor.getLocation())))
.list(
new AbsoluteLocation<>(BasePrivateResource.forPrivate(descriptor.getLocation())))
) {
assertThat(ls).isEmpty();
}
Expand All @@ -267,17 +265,17 @@ protected void assertRootDirIsEmpty(WithStorageProvider.StorageDescriptor descri
// however we can't remove anything above
try (Stream<Path> files = Files.walk(Paths.get(descriptor.getLocation().asURI()))) {
assertThat(files)
.allMatch(it -> it.toFile().isDirectory())
.extracting(Path::toUri)
.extracting(it -> descriptor.getLocation().asURI().relativize(it))
.extracting(URI::toString)
.containsExactlyInAnyOrder(
"",
"users/",
"profiles/",
"profiles/public/",
"profiles/private/"
);
.allMatch(it -> it.toFile().isDirectory())
.extracting(Path::toUri)
.extracting(it -> descriptor.getLocation().asURI().relativize(it))
.extracting(URI::toString)
.containsExactlyInAnyOrder(
"",
"users/",
"profiles/",
"profiles/public/",
"profiles/private/"
);
}
}
}
Expand Down
Loading

0 comments on commit 3ac9af6

Please sign in to comment.