Package com.tngtech.archunit.library
Class GeneralCodingRules
- java.lang.Object
-
- com.tngtech.archunit.library.GeneralCodingRules
-
public final class GeneralCodingRules extends java.lang.Object
When checking these rules, it is always important to remember that all necessary classes need to be imported. E.g. ifACCESS_STANDARD_STREAMS
is checked, which looks for calls on classes assignable toThrowable
, it is important to ensure thatException
andRuntimeException
are imported as well, otherwise ArchUnit does not know about the inheritance structure of these exceptions, and thus will not consider a call ofRuntimeException
a violation, since it does not know thatRuntimeException
extendsThrowable
. For further information refer toClassFileImporter
.
-
-
Field Summary
Fields Modifier and Type Field Description static ArchCondition<JavaClass>
ACCESS_STANDARD_STREAMS
For information about checking this condition, refer toGeneralCodingRules
.static ArchCondition<JavaField>
BE_ANNOTATED_WITH_AN_INJECTION_ANNOTATION
For information about checking this condition, refer toGeneralCodingRules
.static ArchRule
NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS
It is generally good practice to use correct logging instead of writing to the console.static ArchRule
NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS
It is generally good practice to throw specific exceptions likeIllegalArgumentException
or custom exceptions, instead of throwing generic exceptions likeRuntimeException
.static ArchRule
NO_CLASSES_SHOULD_USE_FIELD_INJECTION
Field injection is seen as an anti-pattern.static ArchRule
NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING
Most projects use the more powerful LOG4J or Logback instead of java.util.logging, often hidden behind SLF4J.static ArchRule
NO_CLASSES_SHOULD_USE_JODATIME
Modern Java projects use the [java.time] API instead of the JodaTime library
For information about checking this rule, refer toGeneralCodingRules
.static ArchCondition<JavaClass>
THROW_GENERIC_EXCEPTIONS
For information about checking this condition, refer toGeneralCodingRules
.static ArchCondition<JavaClass>
USE_JAVA_UTIL_LOGGING
For information about checking this condition, refer toGeneralCodingRules
.static ArchCondition<JavaClass>
USE_JODATIME
For information about checking this condition, refer toGeneralCodingRules
.
-
-
-
Field Detail
-
ACCESS_STANDARD_STREAMS
@PublicAPI(usage=ACCESS) public static final ArchCondition<JavaClass> ACCESS_STANDARD_STREAMS
For information about checking this condition, refer toGeneralCodingRules
.
-
NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS
@PublicAPI(usage=ACCESS) public static final ArchRule NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS
It is generally good practice to use correct logging instead of writing to the console.- Writing to the console cannot be configured in production
- Writing to the console is synchronized and can lead to bottle necks
GeneralCodingRules
.
-
THROW_GENERIC_EXCEPTIONS
@PublicAPI(usage=ACCESS) public static final ArchCondition<JavaClass> THROW_GENERIC_EXCEPTIONS
For information about checking this condition, refer toGeneralCodingRules
.
-
NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS
@PublicAPI(usage=ACCESS) public static final ArchRule NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS
It is generally good practice to throw specific exceptions likeIllegalArgumentException
or custom exceptions, instead of throwing generic exceptions likeRuntimeException
.
For information about checking this rule, refer toGeneralCodingRules
.
-
USE_JAVA_UTIL_LOGGING
@PublicAPI(usage=ACCESS) public static final ArchCondition<JavaClass> USE_JAVA_UTIL_LOGGING
For information about checking this condition, refer toGeneralCodingRules
.
-
NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING
@PublicAPI(usage=ACCESS) public static final ArchRule NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING
Most projects use the more powerful LOG4J or Logback instead of java.util.logging, often hidden behind SLF4J. In this case it's important to ensure consistent use of the agreed logging framework.
For information about checking this rule, refer toGeneralCodingRules
.
-
USE_JODATIME
@PublicAPI(usage=ACCESS) public static final ArchCondition<JavaClass> USE_JODATIME
For information about checking this condition, refer toGeneralCodingRules
.
-
NO_CLASSES_SHOULD_USE_JODATIME
@PublicAPI(usage=ACCESS) public static final ArchRule NO_CLASSES_SHOULD_USE_JODATIME
Modern Java projects use the [java.time] API instead of the JodaTime library
For information about checking this rule, refer toGeneralCodingRules
.
-
BE_ANNOTATED_WITH_AN_INJECTION_ANNOTATION
@PublicAPI(usage=ACCESS) public static final ArchCondition<JavaField> BE_ANNOTATED_WITH_AN_INJECTION_ANNOTATION
For information about checking this condition, refer toGeneralCodingRules
.
-
NO_CLASSES_SHOULD_USE_FIELD_INJECTION
@PublicAPI(usage=ACCESS) public static final ArchRule NO_CLASSES_SHOULD_USE_FIELD_INJECTION
Field injection is seen as an anti-pattern. It is a good practice to use constructor injection for mandatory dependencies and setter injection for optional dependencies.
For information about checking this rule, refer toGeneralCodingRules
.
-
-