Skip to content

Commit

Permalink
Adding ArchUnit in the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Mello committed Nov 4, 2020
1 parent a806696 commit bccc484
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
16 changes: 14 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>0.14.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -84,5 +97,4 @@
</plugin>
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.com.ricas;

import br.com.ricas.model.Finance;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/br/com/ricas/model/Category.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.ricas.domain;
package br.com.ricas.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/br/com/ricas/model/Finance.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.ricas.domain;
package br.com.ricas.model;

import br.com.ricas.FinanceType;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package br.com.ricas.archunit;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.lang.ArchRule;
import org.junit.jupiter.api.Test;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;

@AnalyzeClasses(packages = "br.com.ricas")
class CleanArchRuleDefinition {

@Test
public void model_should_only_be_accessed_by_model() {
JavaClasses importedClasses = new ClassFileImporter().importPackages("br.com.ricas");

ArchRule myRule = classes()
.that().resideInAPackage("br.com.ricas.model..")
.should().onlyBeAccessed().byAnyPackage("br.com.ricas.model..");

myRule.check(importedClasses);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.ricas.domain;
package br.com.ricas.model;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.ricas.domain;
package br.com.ricas.model;

import br.com.ricas.FinanceType;
import br.com.ricas.RicasFinancasApplication;
Expand Down

0 comments on commit bccc484

Please sign in to comment.