I wanna use ArchUnit to enforce usage only SLF4J logging framework and avoid simple System.out
calls. Also I would like to avoid any other logging frameworks for using. How can I implement the such check?
Currently I write this test
class EnforceSlf4JLoggingTest {
private final JavaClasses importedClasses = new ClassFileImporter()
.withImportOption(new ImportOption.DoNotIncludeTests())
.importPackages("... my packages ...");
@Test
public void classesShouldNotUseJavaUtilLogging() {
NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING.check(importedClasses);
}
@Test
public void classesShouldNotUseSystemOutLogging() {
noClasses()
.should()
.dependOnClassesThat()
.belongToAnyOf(java.lang.System.class)
.because("use SLF4J instead")
.check(importedClasses);
}
}
but it doesn't actually enforce SLF4J usage but only restrict java.unit.logging
usage and prevent of having dependency to java.lang.System
class (where actually System.out
constant is located).
Whether is more elegant solution of my case?