This repository was archived by the owner on Dec 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathArchUnitRulesTest.java
59 lines (49 loc) · 2.24 KB
/
ArchUnitRulesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.openapijsonschematools.codegen;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;
import org.junit.Test;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING;
public class ArchUnitRulesTest {
private static final JavaClasses CLASSES = new ClassFileImporter()
.importPackages("org.openapijsonschematools.codegen.generators");
@Test
public void testLoggersAreNotPublicFinalAndNotStatic() {
ArchUnitRulesTest.LOGGERS_SHOULD_BE_NOT_PUBLIC_NOT_STATIC_AND_FINAL.check(CLASSES);
}
@Test
public void classesNotAllowedToUseStandardStreams() {
NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS.check(CLASSES);
}
@Test
public void disallowJavaUtilLogging() {
NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING.check(CLASSES);
}
@Test
public void abstractClassesAreAbstract() {
ArchUnitRulesTest.ABSTRACT_CLASS_MUST_BE_ABSTRACT.check(CLASSES);
}
/**
* Making loggers not static decreases memory consumption when running generator:
* https://github.com/OpenAPITools/openapi-generator/pull/8799
*/
public static final ArchRule LOGGERS_SHOULD_BE_NOT_PUBLIC_NOT_STATIC_AND_FINAL =
fields()
.that()
.haveRawType(org.slf4j.Logger.class)
.should().notBePublic()
.andShould().notBeStatic()
.andShould().beFinal()
.because("Code generators are most often used once per program lifetime, " +
"so making them all static will cause higher memory consumption. " +
"See PR #8799");
public static final ArchRule ABSTRACT_CLASS_MUST_BE_ABSTRACT =
classes()
.that()
.haveSimpleNameContaining("Abstract").or().haveSimpleNameContaining("abstract")
.should()
.haveModifier(JavaModifier.ABSTRACT);
}