Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 13, 2023
1 parent f992fc0 commit c9a4799
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ ports:
onOpen: open-browser
- port: 5050
visibility: public
onOpen: open-browser
onOpen: open-browser
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public class MFSchemeNavEntity extends AuditableEntity<String> 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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public interface PortfolioApi {
ResponseEntity<String> 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<PortfolioResponse> getPortfolio(
@Parameter(description = "Pan of the end User", name = "pan", in = ParameterIn.PATH, example = "ABCDE1234F")
String panNumber,
Expand Down
35 changes: 18 additions & 17 deletions src/test/java/com/learning/mfscreener/archunit/CommonRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)\
""");
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,17 @@ 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));
}

if (forceSetters) {
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));
}
}
Expand All @@ -98,22 +92,18 @@ public void check(JavaClass javaClass, ConditionEvents events) {
Optional<JavaMethod> equalsMethod = findPublicMethodFromClass(javaClass, EQUALS_METHOD);
Optional<JavaMethod> 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())));
}
}
};
Expand All @@ -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())));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9a4799

Please sign in to comment.