use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class SessionBeanRulesTest method haveAUniqueImplementation.
private static ArchCondition<JavaClass> haveAUniqueImplementation() {
return new ArchCondition<JavaClass>("have a unique implementation") {
@Override
public void check(JavaClass businessInterface, ConditionEvents events) {
events.add(new SimpleConditionEvent(businessInterface, businessInterface.getAllSubclasses().size() <= 1, describe(businessInterface)));
}
private String describe(JavaClass businessInterface) {
return String.format("%s is implemented by %s", businessInterface.getSimpleName(), joinNamesOf(businessInterface.getAllSubclasses()));
}
private String joinNamesOf(Set<JavaClass> implementations) {
if (implementations.isEmpty()) {
return "";
}
Deque<JavaClass> toJoin = new LinkedList<>(implementations);
StringBuilder sb = new StringBuilder(toJoin.pollFirst().getSimpleName());
for (JavaClass javaClass : toJoin) {
sb.append(", ").append(javaClass.getSimpleName());
}
return sb.toString();
}
};
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassCacheTest method filters_urls.
@Test
public void filters_urls() {
JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, new TestAnalysisRequest().withImportOptions(TestFilterForJUnitJars.class));
assertThat(classes).isNotEmpty();
for (JavaClass clazz : classes) {
assertThat(clazz.getPackageName()).doesNotContain("tngtech");
assertThat(clazz.getPackageName()).contains("junit");
}
}
use of com.tngtech.archunit.core.domain.JavaClass 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.core.domain.JavaClass in project flink by apache.
the class Conditions method haveLeafReturnTypes.
/**
* Tests leaf return types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafReturnTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf return types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
for (JavaClass leafType : getLeafTypes(method.getReturnType())) {
if (!isJavaClass(leafType)) {
continue;
}
if (!typePredicate.apply(leafType)) {
final String message = String.format("%s: Returned 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.JavaClass 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));
}
}
}
};
}
Aggregations