diff --git a/.gitpod.yml b/.gitpod.yml index df0ce1c4..bba98e3d 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -18,4 +18,4 @@ ports: onOpen: open-browser - port: 5050 visibility: public - onOpen: open-browser \ No newline at end of file + onOpen: open-browser diff --git a/sonar-project.properties b/sonar-project.properties index 482591e9..90124636 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,6 +3,7 @@ sonar.projectKey=rajadilipkolli_mfscreener sonar.organization=rajadilipkolli sonar.host.url=https://sonarcloud.io +sonar.gradle.skipCompile=true sonar.sources=src/main/java sonar.tests=src/test/java sonar.exclusions=src/main/java/**/config/*.*,src/main/java/**/entities/*.*,src/main/java/**/models/*.*,src/main/java/**/exceptions/*.*,src/main/java/**/utils/*.*,src/main/java/**/*Application.* diff --git a/src/main/java/com/learning/mfscreener/config/logging/LoggingAspect.java b/src/main/java/com/learning/mfscreener/config/logging/LoggingAspect.java index 84fee0aa..0638e3af 100644 --- a/src/main/java/com/learning/mfscreener/config/logging/LoggingAspect.java +++ b/src/main/java/com/learning/mfscreener/config/logging/LoggingAspect.java @@ -25,15 +25,21 @@ public LoggingAspect(Environment env) { this.env = env; } - @Pointcut("within(@org.springframework.stereotype.Repository *)" - + " || within(@org.springframework.stereotype.Service *)" - + " || within(@org.springframework.web.bind.annotation.RestController *)") + @Pointcut( + """ + within(@org.springframework.stereotype.Repository *)\ + || within(@org.springframework.stereotype.Service *)\ + || within(@org.springframework.web.bind.annotation.RestController *)\ + """) public void springBeanPointcut() { // pointcut definition } - @Pointcut("@within(com.learning.mfscreener.config.logging.Loggable) || " - + "@annotation(com.learning.mfscreener.config.logging.Loggable)") + @Pointcut( + """ + @within(com.learning.mfscreener.config.logging.Loggable) || \ + @annotation(com.learning.mfscreener.config.logging.Loggable)\ + """) public void applicationPackagePointcut() { // pointcut definition } diff --git a/src/main/java/com/learning/mfscreener/entities/MFSchemeNavEntity.java b/src/main/java/com/learning/mfscreener/entities/MFSchemeNavEntity.java index 0f1e7680..ca182e7c 100644 --- a/src/main/java/com/learning/mfscreener/entities/MFSchemeNavEntity.java +++ b/src/main/java/com/learning/mfscreener/entities/MFSchemeNavEntity.java @@ -48,11 +48,11 @@ public class MFSchemeNavEntity extends AuditableEntity implements Serial public final boolean equals(Object o) { if (this == o) return true; if (o == null) return false; - Class oEffectiveClass = o instanceof HibernateProxy - ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() + Class oEffectiveClass = o instanceof HibernateProxy hp + ? hp.getHibernateLazyInitializer().getPersistentClass() : o.getClass(); - Class thisEffectiveClass = this instanceof HibernateProxy - ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() + Class thisEffectiveClass = this instanceof HibernateProxy hp + ? hp.getHibernateLazyInitializer().getPersistentClass() : this.getClass(); if (thisEffectiveClass != oEffectiveClass) return false; MFSchemeNavEntity that = (MFSchemeNavEntity) o; @@ -65,11 +65,8 @@ public final boolean equals(Object o) { @Override public final int hashCode() { - return this instanceof HibernateProxy - ? ((HibernateProxy) this) - .getHibernateLazyInitializer() - .getPersistentClass() - .hashCode() + return this instanceof HibernateProxy hp + ? hp.getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode(); } } diff --git a/src/main/java/com/learning/mfscreener/web/api/PortfolioApi.java b/src/main/java/com/learning/mfscreener/web/api/PortfolioApi.java index add582ea..4f94b2ce 100644 --- a/src/main/java/com/learning/mfscreener/web/api/PortfolioApi.java +++ b/src/main/java/com/learning/mfscreener/web/api/PortfolioApi.java @@ -17,8 +17,11 @@ public interface PortfolioApi { ResponseEntity upload(@RequestPart("file") MultipartFile multipartFile) throws IOException; @Operation( - summary = "Fetches the portfolio by Pan and given date, if date is empty then current" - + " date portfolio will be returned") + summary = + """ + Fetches the portfolio by Pan and given date, if date is empty then current\ + date portfolio will be returned\ + """) ResponseEntity getPortfolio( @Parameter(description = "Pan of the end User", name = "pan", in = ParameterIn.PATH, example = "ABCDE1234F") String panNumber, diff --git a/src/test/java/com/learning/mfscreener/archunit/CommonRules.java b/src/test/java/com/learning/mfscreener/archunit/CommonRules.java index ffb9a469..9685067a 100644 --- a/src/test/java/com/learning/mfscreener/archunit/CommonRules.java +++ b/src/test/java/com/learning/mfscreener/archunit/CommonRules.java @@ -33,7 +33,7 @@ static ArchRule interfacesAreOnlyAllowedRule(String packageName, String... exclu .resideOutsideOfPackages(excludedPackages) .should() .beInterfaces() - .because(String.format("Resources should be interfaces in %s", packageName)); + .because("Resources should be interfaces in %s".formatted(packageName)); } static ArchRule componentAnnotationIsNotAllowedRule(String packageName) { @@ -44,7 +44,7 @@ static ArchRule componentAnnotationIsNotAllowedRule(String packageName) { .haveSimpleNameNotEndingWith("BeanDefinitions") .should() .notBeAnnotatedWith(Component.class) - .because(String.format("Component annotation is not allowed in %s", packageName)); + .because("Component annotation is not allowed in %s".formatted(packageName)); } static ArchRule springAnnotationsClassesAreNotAllowedRule(String... packageNames) { @@ -65,9 +65,8 @@ static ArchRule springAnnotationsClassesAreNotAllowedRule(String... packageNames .notBeAnnotatedWith(Controller.class) .andShould() .notBeAnnotatedWith(RestController.class) - .because(String.format( - "Classes in %s should not be annotated with Spring annotations", - Arrays.toString(packageNames))); + .because("Classes in %s should not be annotated with Spring annotations" + .formatted(Arrays.toString(packageNames))); } // Fields @@ -94,7 +93,7 @@ static ArchRule fieldsShouldNotBePublic(String packageName) { .resideInAPackage(packageName) .should() .notBePublic() - .because(String.format("Public fields are not allowed in %s", packageName)); + .because("Public fields are not allowed in %s".formatted(packageName)); } static ArchRule publicAndFinalFieldsAreNotAllowedRule(String... packageNames) { @@ -107,8 +106,8 @@ static ArchRule publicAndFinalFieldsAreNotAllowedRule(String... packageNames) { .notBeFinal() .andShould() .notBePublic() - .because(String.format( - "Fields with public and final modifiers are not allowed in %s", Arrays.toString(packageNames))); + .because("Fields with public and final modifiers are not allowed in %s" + .formatted(Arrays.toString(packageNames))); } static ArchRule fieldsShouldHaveGetterRule(String... packageNames) { @@ -128,10 +127,12 @@ static ArchRule finalFieldsRule(String packageName, String... excludedPackages) .doNotHaveModifier(JavaModifier.SYNTHETIC) .should() .beFinal() - .because(String.format( - "Private attributes should be instanced by constructor classes, or" - + " it should be static in %s", - packageName)); + .because( + (""" + Private attributes should be instanced by constructor classes, or\ + it should be static in %s\ + """) + .formatted(packageName)); } // Constructors @@ -145,7 +146,7 @@ static ArchRule publicConstructorsRule(String packageName) { .areNotAnonymousClasses() .should() .bePublic() - .because(String.format("Public constructors are only allowed in %s", packageName)); + .because("Public constructors are only allowed in %s".formatted(packageName)); } // Methods @@ -156,7 +157,7 @@ static ArchRule beanMethodsAreNotAllowedRule(String packageName) { .resideInAPackage(packageName) .should() .notBeAnnotatedWith(Bean.class) - .because(String.format("Bean methods are not allowed in %s", packageName)); + .because("Bean methods are not allowed in %s".formatted(packageName)); } static ArchRule privateMethodsAreNotAllowedRule(String packageName) { @@ -168,7 +169,7 @@ static ArchRule privateMethodsAreNotAllowedRule(String packageName) { .haveNameNotEndingWith("InstanceSupplier") .should() .notBePrivate() - .because(String.format("Private methods are not allowed in %s", packageName)); + .because("Private methods are not allowed in %s".formatted(packageName)); } static ArchRule staticMethodsAreNotAllowedRule(String packageName) { @@ -182,7 +183,7 @@ static ArchRule staticMethodsAreNotAllowedRule(String packageName) { .haveNameNotEndingWith("InstanceSupplier") .should() .notBeStatic() - .because(String.format("Static methods are not allowed in %s", packageName)); + .because("Static methods are not allowed in %s".formatted(packageName)); } static ArchRule methodsShouldBePublicRule(String... packageNames) { @@ -202,6 +203,6 @@ static ArchRule staticMethodsAreOnlyAllowedRule(String packageName) { .resideInAPackage(packageName) .should() .beStatic() - .because(String.format("Static methods are only allowed in %s", packageName)); + .because("Static methods are only allowed in %s".formatted(packageName)); } } diff --git a/src/test/java/com/learning/mfscreener/archunit/ControllerRulesTest.java b/src/test/java/com/learning/mfscreener/archunit/ControllerRulesTest.java index 1699ef62..c0cf58c7 100644 --- a/src/test/java/com/learning/mfscreener/archunit/ControllerRulesTest.java +++ b/src/test/java/com/learning/mfscreener/archunit/ControllerRulesTest.java @@ -44,7 +44,7 @@ class ControllerRulesTest { .beAnnotatedWith(RestController.class) .andShould() .notBeAnnotatedWith(Controller.class) - .because(String.format(ANNOTATED_EXPLANATION, CONTROLLER_SUFFIX, "@RestController") + .because(ANNOTATED_EXPLANATION.formatted(CONTROLLER_SUFFIX, "@RestController") + ", and not with @Controller"); // Fields @@ -97,6 +97,9 @@ class ControllerRulesTest { .beAnnotatedWith(PatchMapping.class) .orShould() .beAnnotatedWith(PutMapping.class) - .because("Controller methods should be annotated only with valid options of REST" - + " (POST, PUT, PATCH, GET, and DELETE)"); + .because( + """ + Controller methods should be annotated only with valid options of REST\ + (POST, PUT, PATCH, GET, and DELETE)\ + """); } diff --git a/src/test/java/com/learning/mfscreener/archunit/CustomConditions.java b/src/test/java/com/learning/mfscreener/archunit/CustomConditions.java index c1908de0..d6dc36d7 100644 --- a/src/test/java/com/learning/mfscreener/archunit/CustomConditions.java +++ b/src/test/java/com/learning/mfscreener/archunit/CustomConditions.java @@ -66,11 +66,8 @@ public void check(JavaField field, ConditionEvents events) { String getter = calculateGetterPrefix(field.reflect().getType().getName()) + capitalize(name); if (!publicMethods.contains(getter)) { - String message = String.format( - GETTER_OR_SETTER_NOT_PRESENT_ERROR_MESSAGE, - field.getName(), - field.getOwner().getName(), - GETTER_PREFIX); + String message = GETTER_OR_SETTER_NOT_PRESENT_ERROR_MESSAGE.formatted( + field.getName(), field.getOwner().getName(), GETTER_PREFIX); events.add(SimpleConditionEvent.violated(field, message)); } @@ -78,11 +75,8 @@ public void check(JavaField field, ConditionEvents events) { String setter = SETTER_PREFIX + capitalize(name); if (!publicMethods.contains(setter)) { - String message = String.format( - GETTER_OR_SETTER_NOT_PRESENT_ERROR_MESSAGE, - field.getName(), - field.getOwner().getName(), - SETTER_PREFIX); + String message = GETTER_OR_SETTER_NOT_PRESENT_ERROR_MESSAGE.formatted( + field.getName(), field.getOwner().getName(), SETTER_PREFIX); events.add(SimpleConditionEvent.violated(field, message)); } } @@ -98,22 +92,18 @@ public void check(JavaClass javaClass, ConditionEvents events) { Optional equalsMethod = findPublicMethodFromClass(javaClass, EQUALS_METHOD); Optional hashCodeMethod = findPublicMethodFromClass(javaClass, HASH_CODE_METHOD); - if (!equalsMethod.isPresent()) { + if (equalsMethod.isEmpty()) { events.add(SimpleConditionEvent.violated( javaClass, - String.format( - EQUALS_OR_HASH_CODE_NOT_PRESENT_ERROR_MESSAGE, - EQUALS_METHOD, - javaClass.getName()))); + EQUALS_OR_HASH_CODE_NOT_PRESENT_ERROR_MESSAGE.formatted( + EQUALS_METHOD, javaClass.getName()))); } - if (!hashCodeMethod.isPresent()) { + if (hashCodeMethod.isEmpty()) { events.add(SimpleConditionEvent.violated( javaClass, - String.format( - EQUALS_OR_HASH_CODE_NOT_PRESENT_ERROR_MESSAGE, - HASH_CODE_METHOD, - javaClass.getName()))); + EQUALS_OR_HASH_CODE_NOT_PRESENT_ERROR_MESSAGE.formatted( + HASH_CODE_METHOD, javaClass.getName()))); } } }; @@ -128,8 +118,7 @@ public void check(JavaClass javaClass, ConditionEvents events) { .filter(m -> m.getModifiers().contains(JavaModifier.STATIC)) .forEach(m -> SimpleConditionEvent.violated( javaClass, - String.format( - "Static method %s in %s is not allowed", m.getName(), javaClass.getName()))); + "Static method %s in %s is not allowed".formatted(m.getName(), javaClass.getName()))); } }; } diff --git a/src/test/java/com/learning/mfscreener/archunit/EntityRulesTest.java b/src/test/java/com/learning/mfscreener/archunit/EntityRulesTest.java index 4af51643..9cf102cb 100644 --- a/src/test/java/com/learning/mfscreener/archunit/EntityRulesTest.java +++ b/src/test/java/com/learning/mfscreener/archunit/EntityRulesTest.java @@ -29,7 +29,7 @@ public class EntityRulesTest { .beAnnotatedWith(Entity.class) .andShould() .beAnnotatedWith(Table.class) - .because(String.format(ANNOTATED_EXPLANATION, ENTITY_SUFFIX, "@Entity")); + .because(ANNOTATED_EXPLANATION.formatted(ENTITY_SUFFIX, "@Entity")); @ArchTest static final ArchRule CLASSES_SHOULD_END_WITH_NAME_RULE = diff --git a/src/test/java/com/learning/mfscreener/archunit/RepositoryRulesTest.java b/src/test/java/com/learning/mfscreener/archunit/RepositoryRulesTest.java index 092eec1a..2456c9f8 100644 --- a/src/test/java/com/learning/mfscreener/archunit/RepositoryRulesTest.java +++ b/src/test/java/com/learning/mfscreener/archunit/RepositoryRulesTest.java @@ -29,7 +29,7 @@ class RepositoryRulesTest { .haveSimpleNameNotStartingWith("Custom") .should() .beAnnotatedWith(Repository.class) - .because(String.format(ANNOTATED_EXPLANATION, REPOSITORY_SUFFIX, "@Repository")); + .because(ANNOTATED_EXPLANATION.formatted(REPOSITORY_SUFFIX, "@Repository")); @ArchTest static final ArchRule classesShouldBeInterfaces = diff --git a/src/test/java/com/learning/mfscreener/archunit/ServiceRulesTest.java b/src/test/java/com/learning/mfscreener/archunit/ServiceRulesTest.java index d3018808..0ad35ca5 100644 --- a/src/test/java/com/learning/mfscreener/archunit/ServiceRulesTest.java +++ b/src/test/java/com/learning/mfscreener/archunit/ServiceRulesTest.java @@ -36,7 +36,7 @@ class ServiceRulesTest { .doNotHaveSimpleName("package-info") .should() .beAnnotatedWith(Service.class) - .because(String.format(ANNOTATED_EXPLANATION, SERVICE_SUFFIX, "@Service")); + .because(ANNOTATED_EXPLANATION.formatted(SERVICE_SUFFIX, "@Service")); // Fields @ArchTest