Skip to content

Commit

Permalink
Add missing .as methods for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
mnhock authored and mnhock committed Oct 20, 2024
1 parent ff57515 commit 8af2ad7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/enofex/taikai/java/JavaConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public JavaConfigurer utilityClassesShouldBeFinalAndHavePrivateConstructor(
Configuration configuration) {
return addRule(TaikaiRule.of(utilityClasses()
.should(beFinal())
.andShould(havePrivateConstructor()), configuration));
.andShould(havePrivateConstructor())
.as("Utility classes should be final and have a private constructor"), configuration));
}

public JavaConfigurer methodsShouldNotDeclareGenericExceptions() {
Expand Down Expand Up @@ -147,7 +148,9 @@ public JavaConfigurer noUsageOfDeprecatedAPIs() {
}

public JavaConfigurer noUsageOfDeprecatedAPIs(Configuration configuration) {
return addRule(TaikaiRule.of(classes().should(notUseDeprecatedAPIs()), configuration));
return addRule(TaikaiRule.of(classes()
.should(notUseDeprecatedAPIs())
.as("Classes should not use deprecated APIs"), configuration));
}

public JavaConfigurer classesShouldResideInPackage(String packageIdentifier) {
Expand Down Expand Up @@ -297,7 +300,8 @@ public JavaConfigurer classesShouldImplementHashCodeAndEquals() {

public JavaConfigurer classesShouldImplementHashCodeAndEquals(Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.should(implementHashCodeAndEquals()), configuration));
.should(implementHashCodeAndEquals())
.as("Classes should implement hashCode and equals"), configuration));
}

public JavaConfigurer classesShouldBeAssignableTo(String regex, Class<?> clazz) {
Expand Down Expand Up @@ -350,7 +354,8 @@ public JavaConfigurer fieldsShouldNotBePublic() {

public JavaConfigurer fieldsShouldNotBePublic(Configuration configuration) {
return addRule(TaikaiRule.of(fields()
.should(notBePublicButNotStatic()), configuration));
.should(notBePublicButNotStatic())
.as("Fields should not be public unless they are static"), configuration));
}

public JavaConfigurer fieldsShouldHaveModifiers(String regex,
Expand Down Expand Up @@ -420,7 +425,8 @@ public JavaConfigurer noUsageOfSystemOutOrErr() {

public JavaConfigurer noUsageOfSystemOutOrErr(Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.should(notUseSystemOutOrErr()), configuration));
.should(notUseSystemOutOrErr())
.as("Classes should not use System.out or System.err"), configuration));
}

public JavaConfigurer finalClassesShouldNotHaveProtectedMembers() {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/enofex/taikai/logging/LoggingConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public LoggingConfigurer classesShouldUseLogger(Class<?> clazz, String regex,
public LoggingConfigurer classesShouldUseLogger(String typeName, String regex,
Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().haveNameMatching(regex)
.should(haveFieldOfType(typeName)), configuration));
.that().haveNameMatching(regex)
.should(haveFieldOfType(typeName))
.as("Classes with names matching %s should use a logger of type %s".formatted(regex,
typeName)),
configuration));
}

public LoggingConfigurer loggersShouldFollowConventions(String typeName, String regex) {
Expand Down Expand Up @@ -84,7 +87,10 @@ public LoggingConfigurer loggersShouldFollowConventions(Class<?> clazz, String r
public LoggingConfigurer loggersShouldFollowConventions(String typeName, String regex,
Collection<JavaModifier> requiredModifiers, Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.should(followLoggerConventions(typeName, regex, requiredModifiers)), configuration));
.should(followLoggerConventions(typeName, regex, requiredModifiers))
.as("Loggers in classes matching %s should follow conventions and be of type %s with required modifiers %s".formatted(
regex, typeName, requiredModifiers)),
configuration));
}

public static final class Disableable extends LoggingConfigurer implements DisableableConfigurer {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/enofex/taikai/test/JUnit5Configurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ public JUnit5Configurer methodsShouldContainAssertionsOrVerifications() {
return methodsShouldContainAssertionsOrVerifications(CONFIGURATION);
}

public JUnit5Configurer methodsShouldContainAssertionsOrVerifications(Configuration configuration) {
public JUnit5Configurer methodsShouldContainAssertionsOrVerifications(
Configuration configuration) {
return addRule(TaikaiRule.of(methods()
.that(are(annotatedWithTestOrParameterizedTest(true)))
.should(containAssertionsOrVerifications()), configuration));
.that(are(annotatedWithTestOrParameterizedTest(true)))
.should(containAssertionsOrVerifications())
.as("Methods annotated with %s or %s should contain assertions or verifications".formatted(
ANNOTATION_TEST, ANNOTATION_PARAMETRIZED_TEST)),
configuration));
}

public JUnit5Configurer classesShouldNotBeAnnotatedWithDisabled() {
Expand Down

0 comments on commit 8af2ad7

Please sign in to comment.