use of com.tngtech.archunit.core.domain.JavaMethodCall 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.core.domain.JavaMethodCall in project arch-unit-build-plugin-core by societe-generale.
the class NoJodaTimeRuleTest method notUseJodaTime.
protected static ArchCondition<JavaClass> notUseJodaTime() {
return new ArchCondition<JavaClass>("not use Joda time ") {
@Override
public void check(JavaClass item, ConditionEvents events) {
List<JavaField> classesWithJodaTimeFields = item.getAllFields().stream().filter(this::isJodaTimeField).collect(toList());
for (JavaField field : classesWithJodaTimeFields) {
events.add(SimpleConditionEvent.violated(field, NO_JODA_VIOLATION_MESSAGE + " - class: " + field.getOwner().getName() + " - field name: " + field.getName()));
}
List<JavaMethodCall> methodsUsingJodaTimeInternally = item.getCodeUnits().stream().filter(codeUnit -> codeUnit instanceof JavaMethod).flatMap(method -> method.getMethodCallsFromSelf().stream()).filter(method -> method instanceof JavaMethodCall).filter(this::isMethodUsingJodaTimeInternally).collect(toList());
for (JavaMethodCall methodCall : methodsUsingJodaTimeInternally) {
events.add(SimpleConditionEvent.violated(methodCall.getOriginOwner(), NO_JODA_VIOLATION_MESSAGE + " - class: " + methodCall.getOriginOwner().getName() + " - method: " + methodCall.getTarget().getOwner().getSimpleName() + "." + methodCall.getTarget().getName() + " - line: " + methodCall.getLineNumber()));
}
}
private boolean isJodaTimeField(JavaField field) {
return field.getRawType().getName().startsWith(JODATIME_PACKAGE_PREFIX);
}
private boolean isMethodUsingJodaTimeInternally(JavaMethodCall javaMethodCall) {
return javaMethodCall.getTarget().getFullName().startsWith(JODATIME_PACKAGE_PREFIX);
}
};
}
use of com.tngtech.archunit.core.domain.JavaMethodCall 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.core.domain.JavaMethodCall in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_multiple_method_calls_from_single_lambda.
@Test
public void imports_multiple_method_calls_from_single_lambda() {
class Target {
void target() {
}
}
@SuppressWarnings("unused")
class Caller {
private Target target;
Runnable call() {
return () -> {
target.target();
target.target();
};
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
Set<JavaMethodCall> calls = classes.get(Caller.class).getMethodCallsFromSelf();
assertThat(calls).hasSize(2);
calls.forEach(call -> assertThatCall(call).isFrom("call").isTo(Target.class, "target"));
}
use of com.tngtech.archunit.core.domain.JavaMethodCall in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_multiple_method_calls_from_multiple_lambda_in_one_method.
@Test
public void imports_multiple_method_calls_from_multiple_lambda_in_one_method() {
@SuppressWarnings("unused")
class Target {
Target target(String s) {
return this;
}
Target target(int i) {
return this;
}
}
@SuppressWarnings("unused")
class Caller {
private Target target;
Function<String, Target> call(int i) {
Function<Target, Target> function = t -> t.target(i);
return s -> target.target(s);
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
Set<JavaMethodCall> calls = classes.get(Caller.class).getMethodCallsFromSelf();
assertThat(filterOriginByName(calls, "call")).extracting(JavaMethodCall::getTarget).areExactly(1, targetCodeUnit("target", String.class)).areExactly(1, targetCodeUnit("target", int.class)).hasSize(2);
}
Aggregations