Created
November 5, 2019 23:00
-
-
Save ahatzz11/89492a65ab0b594498412997c58df903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hatz.test | |
import com.tngtech.archunit.core.domain.JavaClasses | |
import com.tngtech.archunit.core.importer.ClassFileImporter | |
import groovy.util.logging.Slf4j | |
import org.springframework.boot.context.properties.ConfigurationProperties | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.stereotype.Service | |
import org.springframework.web.bind.annotation.RestController | |
import spock.lang.Ignore | |
import spock.lang.Shared | |
import spock.lang.Specification | |
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes | |
/** | |
* A set of tests using ArchUnit that test the project structure and naming of classes. | |
*/ | |
@Slf4j | |
class BaseArchUnitSpec extends Specification { | |
@Shared | |
JavaClasses importedClasses | |
def setup() { | |
// todo find a way for this to be defined by the application - can we use the package of the MainClass? | |
importedClasses = new ClassFileImporter().importPackages('com.hatz') | |
} | |
def 'config package tests'() { | |
expect: | |
classes() | |
.that().areAnnotatedWith(Configuration.class) | |
.should().haveSimpleNameEndingWith('Config') | |
.orShould().haveSimpleNameEndingWith('Properties') | |
.andShould().resideInAPackage('..config..') | |
.because('All configurations should be called a Config and live in config ') | |
.check(importedClasses) | |
classes() | |
.that().areAnnotatedWith(ConfigurationProperties.class) | |
.should().haveSimpleNameEndingWith('Properties') | |
.andShould().resideInAPackage('..config..') | |
.because('All properties should be called a Properties and live in config ') | |
.check(importedClasses) | |
} | |
def 'controller package tests'() { | |
expect: | |
classes() | |
.that().areAnnotatedWith(RestController.class) | |
.should().haveSimpleNameEndingWith('Controller') | |
.andShould().resideInAPackage('..controller..') | |
.because('All RestControllers should be called a Controller and live in controller') | |
.check(importedClasses) | |
} | |
def 'service package tests'() { | |
expect: | |
classes() | |
.that().areAnnotatedWith(Service.class) | |
.should().haveSimpleNameEndingWith('Service') | |
.andShould().resideInAPackage('..service..') | |
.because('All Services should be called a Service') | |
.check(importedClasses) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment