use of com.tngtech.archunit.core.domain.JavaMethod in project gradle by gradle.
the class ArchUnitFixtureTest method checkThatMethodHasOnlyAllowedArgumentTypesOrReturnTypes.
@Nonnull
private ConditionEvent checkThatMethodHasOnlyAllowedArgumentTypesOrReturnTypes(String methodName, Class<?>... arguments) {
ArchCondition<JavaMethod> archCondition = haveOnlyArgumentsOrReturnTypesThatAre(resideInAnyPackage("java.lang").or(primitive).or(resideInAnyPackage("java.util")).as("allowed"));
JavaClass javaClass = new ClassFileImporter().importClass(AllowedMethodTypesClass.class);
JavaMethod validMethod = javaClass.getMethod(methodName, arguments);
ConditionEvents events = new ConditionEvents();
archCondition.check(validMethod, events);
assertThat(events).hasSize(1);
return events.iterator().next();
}
use of com.tngtech.archunit.core.domain.JavaMethod in project gradle by gradle.
the class ProviderMigrationArchitectureTest method hasSetter.
private static boolean hasSetter(JavaMethod input) {
PropertyAccessorType accessorType = PropertyAccessorType.fromName(input.getName());
String propertyNameFromGetter = accessorType.propertyNameFor(input.getName());
return input.getOwner().getAllMethods().stream().filter(method -> PropertyAccessorType.fromName(method.getName()) == PropertyAccessorType.SETTER).anyMatch(method -> PropertyAccessorType.SETTER.propertyNameFor(method.getName()).equals(propertyNameFromGetter));
}
use of com.tngtech.archunit.core.domain.JavaMethod in project opentelemetry-java by open-telemetry.
the class SdkDesignTest method implementOrOverride.
static DescribedPredicate<? super JavaMethod> implementOrOverride() {
return new DescribedPredicate<>("implement or override a method") {
@Override
public boolean apply(JavaMethod input) {
List<JavaClass> params = input.getRawParameterTypes();
Class<?>[] paramsType = new Class<?>[params.size()];
for (int i = 0, n = params.size(); i < n; i++) {
paramsType[i] = params.get(i).reflect();
}
String name = input.getName();
List<JavaClass> parents = new ArrayList<>(input.getOwner().getAllRawSuperclasses());
parents.addAll(input.getOwner().getAllRawInterfaces());
for (JavaClass parent : parents) {
Optional<JavaMethod> found = parent.tryGetMethod(name, paramsType);
if (found.isPresent()) {
return true;
}
}
return false;
}
};
}
use of com.tngtech.archunit.core.domain.JavaMethod in project flink by splunk.
the class Conditions method haveLeafExceptionTypes.
/**
* Tests leaf exception types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafExceptionTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf exception types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
final List<JavaClass> leafArgumentTypes = method.getExceptionTypes().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: Exception leaf type %s does not satisfy: %s", method.getFullName(), leafType.getName(), typePredicate.getDescription());
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
use of com.tngtech.archunit.core.domain.JavaMethod in project ArchUnit by TNG.
the class GivenThatIsTestedConsistentlyTest method classes_that_tests_all_relevant_methods.
@Test
public void classes_that_tests_all_relevant_methods() {
JavaClasses classes = importClassesWithContext(GivenClassesThatTest.class, ClassesThat.class);
JavaClass test = classes.get(GivenClassesThatTest.class);
for (JavaMethod method : classes.get(ClassesThat.class).getMethods()) {
assertAccessFrom(test, method);
}
}
Aggregations