use of com.tngtech.archunit.base.DescribedPredicate in project git-machete-intellij-plugin by VirtusLab.
the class ClassStructureTestSuite method actions_overriding_onUpdate_should_call_super_onUpdate.
@Test
public void actions_overriding_onUpdate_should_call_super_onUpdate() {
classes().that().areAssignableTo(com.virtuslab.gitmachete.frontend.actions.base.BaseProjectDependentAction.class).and().areNotAssignableFrom(com.virtuslab.gitmachete.frontend.actions.base.BaseProjectDependentAction.class).and(new DescribedPredicate<JavaClass>("override onUpdate method") {
@Override
public boolean apply(JavaClass input) {
return input.getMethods().stream().anyMatch(method -> method.getName().equals("onUpdate"));
}
}).should().callMethodWhere(new DescribedPredicate<JavaMethodCall>("name is onUpdate and owner is the direct superclass") {
@Override
public boolean apply(JavaMethodCall input) {
// where is the method called from?
JavaCodeUnit origin = input.getOrigin();
// where is the method declared?
AccessTarget.MethodCallTarget target = input.getTarget();
if (origin.getName().equals("onUpdate") && target.getName().equals("onUpdate")) {
return target.getOwner().equals(origin.getOwner().getSuperclass().orElse(null));
}
return false;
}
}).check(importedClasses);
}
use of com.tngtech.archunit.base.DescribedPredicate in project sirius-components by eclipse-sirius.
the class AbstractServicesTests method nonAuditedRepositoryMethod.
private DescribedPredicate<JavaMethodCall> nonAuditedRepositoryMethod() {
return new // $NON-NLS-1$
DescribedPredicate<>(// $NON-NLS-1$
"the repository method called has not been audited") {
@Override
public boolean apply(JavaMethodCall javaMethodCall) {
JavaClass targetJavaClass = javaMethodCall.getTargetOwner();
String fullName = targetJavaClass.getFullName();
// $NON-NLS-1$
boolean isRepository = fullName.endsWith("Repository");
boolean hasBeenAudited = javaMethodCall.getTarget().isAnnotatedWith(Audited.class);
return isRepository && !hasBeenAudited;
}
};
}
use of com.tngtech.archunit.base.DescribedPredicate in project flink-mirror by flink-ci.
the class Conditions method haveLeafArgumentTypes.
/**
* Tests leaf argument types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafArgumentTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf argument types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
final List<JavaClass> leafArgumentTypes = method.getParameterTypes().stream().flatMap(argumentType -> getLeafTypes(argumentType).stream()).collect(Collectors.toList());
for (JavaClass leafType : leafArgumentTypes) {
if (!isJavaClass(leafType)) {
continue;
}
if (!typePredicate.apply(leafType)) {
final String message = String.format("%s: Argument leaf type %s does not satisfy: %s", method.getFullName(), leafType.getName(), typePredicate.getDescription());
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
use of com.tngtech.archunit.base.DescribedPredicate in project flink by apache.
the class Conditions method haveLeafArgumentTypes.
/**
* Tests leaf argument types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafArgumentTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf argument types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
final List<JavaClass> leafArgumentTypes = method.getParameterTypes().stream().flatMap(argumentType -> getLeafTypes(argumentType).stream()).collect(Collectors.toList());
for (JavaClass leafType : leafArgumentTypes) {
if (!isJavaClass(leafType)) {
continue;
}
if (!typePredicate.apply(leafType)) {
final String message = String.format("%s: Argument leaf type %s does not satisfy: %s", method.getFullName(), leafType.getName(), typePredicate.getDescription());
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
use of com.tngtech.archunit.base.DescribedPredicate in project teammates by TEAMMATES.
the class ArchitectureTest method testArchitecture_logic_coreLogicCanOnlyAccessItsCorrespondingDb.
@Test
public void testArchitecture_logic_coreLogicCanOnlyAccessItsCorrespondingDb() {
for (JavaClass coreLogicClass : forClasses(LOGIC_CORE_PACKAGE)) {
String logicClassName = coreLogicClass.getSimpleName();
if ("DataBundleLogic".equals(logicClassName)) {
continue;
}
if (logicClassName.endsWith(TEST_FILE_SUFFIX)) {
continue;
}
String dbClassName = logicClassName.replace("Logic", "Db");
noClasses().that().resideInAPackage(includeSubpackages(LOGIC_CORE_PACKAGE)).and().doNotHaveSimpleName(logicClassName).and().doNotHaveSimpleName(logicClassName + TEST_FILE_SUFFIX).and().doNotHaveSimpleName("DataBundleLogic").should().accessClassesThat(new DescribedPredicate<>("") {
@Override
public boolean apply(JavaClass input) {
return input.getPackageName().startsWith(STORAGE_API_PACKAGE) && input.getSimpleName().equals(dbClassName);
}
}).check(forClasses(LOGIC_CORE_PACKAGE, STORAGE_API_PACKAGE));
}
}
Aggregations