Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7275eac
Added syntax entry (members(), fields(), ...) and simple that(predica…
codecholeric Nov 25, 2018
1ca922b
Added negations (noMembers(), noFields(), ...) and example / integrat…
codecholeric Nov 25, 2018
e8620a4
Added some syntax elements for members (parts that have already been …
codecholeric Feb 2, 2019
fcce8f9
Added declaredIn syntax elements for members
codecholeric Feb 2, 2019
6e81bc8
Added declaredIn fluent API for members
codecholeric Feb 10, 2019
aab46d5
Added FieldsThat syntax with haveType(..) elements
codecholeric Feb 17, 2019
da8926f
Make naming of implementation consistent with interface.
codecholeric Feb 22, 2019
7145c55
Added CodeUnitsThat#haveRawParameterTypes(..) to syntax
codecholeric Feb 23, 2019
56f7d9e
Added CodeUnitsThat#haveRawReturnType(..) to syntax
codecholeric Feb 24, 2019
be5b2e7
Prepare introduction of generic return types
codecholeric Feb 24, 2019
b797b56
Added CodeUnitsThat#declareThrowableOfType(..) to syntax
codecholeric Feb 24, 2019
6fc9ac2
Added andShould(..)/orShould(..) to syntax
codecholeric Feb 24, 2019
b3d1440
Prepare introduction of generic parameter types
codecholeric Feb 24, 2019
f977ccf
Prepare introduction of generic field types
codecholeric Feb 24, 2019
aece4a9
ArchUnit domain objects should contain their "Occurrence" (chosen in …
codecholeric Mar 3, 2019
97a6617
Added should() + fluentAPI to members() syntax
codecholeric Mar 3, 2019
d397337
Removed obsolete interfaces. These interfaces really don't contribute…
codecholeric Mar 3, 2019
f4c88a3
Make GivenClassesThatInternal more generic
codecholeric Mar 3, 2019
df4f2bb
Replaced ClassesShouldThatInternal by generic ClassesThatInternal
codecholeric Mar 3, 2019
199d017
Further improved the structure of GivenClassesInternal to not rely on…
codecholeric Mar 3, 2019
eb413ff
Added beDeclaredInClassesThat() to members().should()
codecholeric Mar 3, 2019
f532a5f
Improve RandomSyntaxTestBase -> pull out MethodCallChain, focus on in…
codecholeric Mar 9, 2019
5800b9d
Improve RandomSyntaxTests -> Adding the method name to the expected d…
codecholeric Mar 9, 2019
699b015
Added fields().should().haveRawType(..) to syntax.
codecholeric Mar 9, 2019
92e2dda
We must override ClassesShouldConjunction should(ArchCondition<? supe…
codecholeric Mar 9, 2019
0d1fd2d
Added codeUnits().should().. to syntax.
codecholeric Mar 9, 2019
eef3c8f
Consistently avoid contractions
codecholeric Mar 9, 2019
792a95c
Added negations for fields().that().haveRawType(..)
codecholeric Mar 9, 2019
c2dc796
Added negations for codeUnits().that().(..)
codecholeric Mar 9, 2019
bb54b9f
Adjusted examples to new members fluent API.
codecholeric Mar 9, 2019
3081644
Adjust user guide to explain the new members API.
codecholeric Mar 10, 2019
3ad8f62
introduce and use DescribedPredicateAssertion
hankem Mar 13, 2019
9e0bdbf
require Throwable(s) for HasThrowsClause.Predicates.throwsClauseWithT…
hankem Mar 14, 2019
e5cc657
test fluent versions of MembersShouldConjunctionTest; make ArchCondit…
hankem Mar 14, 2019
3769e63
have ClassesShouldConjunctionTest's first cases consistently use Arch…
hankem Mar 14, 2019
92ff58c
rename Occurence to SourceCodeLocation
hankem Mar 15, 2019
5a89f8c
deprecate formatLocation in favor of SourceCodeLocation
hankem Mar 15, 2019
bbe2dcc
introduce and use ArchConditionAssertion
hankem Mar 15, 2019
acabd8a
fix message of ArchConditions.declareThrowableOfType's events
hankem Mar 15, 2019
d71deac
simplify example; demonstrate usage of ArchRuleDefinition.noMethods
hankem Mar 15, 2019
9ad2a8f
Some minor Javadoc adjustments
codecholeric Mar 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.tngtech.archunit.exampletest.junit4;

import java.sql.SQLException;

import javax.persistence.Entity;
import javax.persistence.EntityManager;

import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaMethod;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.sql.SQLException;

import static com.tngtech.archunit.core.domain.Formatters.formatLocation;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods;

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
Expand All @@ -44,22 +38,6 @@ public class DaoRulesTest {

@ArchTest
public static final ArchRule DAOs_must_not_throw_SQLException =
classes().that().haveNameMatching(".*Dao")
.should(notContainMethodsThrowing(SQLException.class));

private static ArchCondition<JavaClass> notContainMethodsThrowing(final Class<? extends Exception> exception) {
return new ArchCondition<JavaClass>("not contain methods throwing " + exception.getName()) {
@Override
public void check(JavaClass item, ConditionEvents events) {
for (JavaMethod method : item.getMethods()) {
if (method.getThrowsClause().containsType(exception)) {
String message = String.format("%s throws %s in %s",
method.getFullName(), exception.getName(),
formatLocation(method.getOwner(), 0));
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
noMethods().that().areDeclaredInClassesThat().haveNameMatching(".*Dao")
.should().declareThrowableOfType(SQLException.class);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.example.anticorruption.WrappedResult;
import com.tngtech.archunit.example.security.Secured;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
import com.tngtech.archunit.lang.ArchRule;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noCodeUnits;

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
public class MethodsTest {

@ArchTest
public static ArchRule all_public_methods_in_the_controller_layer_should_return_API_response_wrappers =
methods()
.that().areDeclaredInClassesThat().resideInAPackage("..anticorruption..")
.and().arePublic()
.should().haveRawReturnType(WrappedResult.class)
.because("we do not want to couple the client code directly to the return types of the encapsulated module");

@ArchTest
public static ArchRule code_units_in_DAO_layer_should_not_be_Secured =
noCodeUnits()
.that().areDeclaredInClassesThat().resideInAPackage("..persistence..")
.should().beAnnotatedWith(Secured.class);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.tngtech.archunit.exampletest.junit5;

import java.sql.SQLException;

import javax.persistence.Entity;
import javax.persistence.EntityManager;

import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaMethod;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTag;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;

import java.sql.SQLException;

import static com.tngtech.archunit.core.domain.Formatters.formatLocation;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods;

@ArchTag("example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
Expand All @@ -41,22 +36,6 @@ public class DaoRulesTest {

@ArchTest
static final ArchRule DAOs_must_not_throw_SQLException =
classes().that().haveNameMatching(".*Dao")
.should(notContainMethodsThrowing(SQLException.class));

private static ArchCondition<JavaClass> notContainMethodsThrowing(final Class<? extends Exception> exception) {
return new ArchCondition<JavaClass>("not contain methods throwing " + exception.getName()) {
@Override
public void check(JavaClass item, ConditionEvents events) {
for (JavaMethod method : item.getMethods()) {
if (method.getThrowsClause().containsType(exception)) {
String message = String.format("%s throws %s in %s",
method.getFullName(), exception.getName(),
formatLocation(method.getOwner(), 0));
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
noMethods().that().areDeclaredInClassesThat().haveNameMatching(".*Dao")
.should().declareThrowableOfType(SQLException.class);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.tngtech.archunit.exampletest.junit5;

import com.tngtech.archunit.example.anticorruption.WrappedResult;
import com.tngtech.archunit.example.security.Secured;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTag;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noCodeUnits;

@ArchTag("example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
public class MethodsTest {

@ArchTest
static ArchRule all_public_methods_in_the_controller_layer_should_return_API_response_wrappers =
methods()
.that().areDeclaredInClassesThat().resideInAPackage("..anticorruption..")
.and().arePublic()
.should().haveRawReturnType(WrappedResult.class)
.because("we do not want to couple the client code directly to the return types of the encapsulated module");

@ArchTest
static ArchRule code_units_in_DAO_layer_should_not_be_Secured =
noCodeUnits()
.that().areDeclaredInClassesThat().resideInAPackage("..persistence..")
.should().beAnnotatedWith(Secured.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private void doCustomNonsense() {
try (FileInputStream fileInput = new FileInputStream(new File("/some/magic/resource.cert"))) {
certificate = CertificateFactory.getInstance("X509").generateCertificate(fileInput);
} catch (CertificateException | IOException e) {
// we don't handle exceptions, because we're lazy ;-)
// we do not handle exceptions, because we're lazy ;-)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

import com.tngtech.archunit.example.persistence.first.dao.SomeDao;
import com.tngtech.archunit.example.persistence.first.dao.domain.PersistentObject;
import com.tngtech.archunit.example.security.Secured;

public class SomeJpa implements SomeDao {
@PersistenceContext
private EntityManager entityManager;

@Secured
public SomeJpa() {
}

@Override
public PersistentObject findById(long id) {
return entityManager.find(PersistentObject.class, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.tngtech.archunit.example.persistence.second.dao.OtherDao;
import com.tngtech.archunit.example.persistence.second.dao.domain.OtherPersistentObject;
import com.tngtech.archunit.example.security.Secured;

import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -20,11 +21,12 @@ public OtherPersistentObject findById(long id) {

@Override
public void testConnection() throws SQLException {
Connection conn = (Connection) entityManager.unwrap(java.sql.Connection.class);
Connection conn = entityManager.unwrap(Connection.class);
conn.prepareStatement("SELECT 1 FROM DUAL");
}

@Override
@Secured
public EntityManager getEntityManager() {
return entityManager;
}
Expand Down
Loading