Introduce Checkstyle rule to prohibit class names ending with "Test"
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package example.scannable;
|
||||
|
||||
|
||||
/**
|
||||
* Marker class for example.scannable package.
|
||||
* Marker class for {@code example.scannable} package.
|
||||
*
|
||||
* @see org.springframework.context.annotation.ComponentScan#basePackageClasses()
|
||||
*/
|
||||
public class _package { }
|
||||
public class PackageMarker {
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class ComponentScanAnnotationIntegrationTests {
|
||||
@Test
|
||||
public void controlScan() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan(example.scannable._package.class.getPackage().getName());
|
||||
ctx.scan(example.scannable.PackageMarker.class.getPackage().getName());
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean("fooServiceImpl")).as(
|
||||
"control scan for example.scannable package failed to register FooServiceImpl bean").isTrue();
|
||||
@@ -326,7 +326,7 @@ public class ComponentScanAnnotationIntegrationTests {
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = example.scannable._package.class)
|
||||
@ComponentScan(basePackageClasses = example.scannable.PackageMarker.class)
|
||||
class ComponentScanAnnotatedConfig {
|
||||
|
||||
@Bean
|
||||
@@ -456,7 +456,7 @@ class ComponentScanWithMultipleAnnotationIncludeFilters2 {}
|
||||
@ComponentScan(
|
||||
value = "example.scannable",
|
||||
basePackages = "example.scannable",
|
||||
basePackageClasses = example.scannable._package.class)
|
||||
basePackageClasses = example.scannable.PackageMarker.class)
|
||||
class ComponentScanWithBasePackagesAndValueAlias {}
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,14 @@
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.design.InnerTypeLastCheck" />
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.design.OneTopLevelClassCheck" />
|
||||
|
||||
<!-- Type Names -->
|
||||
<module name="TypeName">
|
||||
<property name="format" value="^[A-Z][a-zA-Z0-9_]*(?<!Test)$" />
|
||||
<property name="tokens" value="CLASS_DEF" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Class name ''{0}'' must not end with ''Test'' (checked pattern ''{1}'')." />
|
||||
</module>
|
||||
|
||||
<!-- Coding -->
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.coding.CovariantEqualsCheck" />
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck" />
|
||||
|
||||
Reference in New Issue
Block a user