优化
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
package com.baiyue.lastleg;
|
||||
|
||||
import com.tngtech.archunit.core.domain.JavaClasses;
|
||||
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class MapperRegistrationArchitectureTest {
|
||||
private static final JavaClasses PRODUCTION_CLASSES = new ClassFileImporter()
|
||||
.importPackages("com.baiyue.lastleg");
|
||||
|
||||
@Test
|
||||
void everyMapperInterfaceDeclaresItsRegistrationMarker() {
|
||||
classes().that().areInterfaces().and().haveSimpleNameEndingWith("Mapper")
|
||||
.should().beAnnotatedWith(Mapper.class)
|
||||
.because("Mapper registration must fail during tests instead of service startup")
|
||||
.check(PRODUCTION_CLASSES);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applicationUsesOneAnnotationFilteredRootScan() {
|
||||
MapperScan scan = BaiyueLastlegApplication.class.getAnnotation(MapperScan.class);
|
||||
assertThat(scan.basePackages()).containsExactly("com.baiyue.lastleg");
|
||||
assertThat(scan.annotationClass()).isEqualTo(Mapper.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user