use of com.tngtech.archunit.core.domain.JavaClass 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.JavaClass 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.JavaClass in project SORMAS-Project by hzi-braunschweig.
the class DatabaseExportServiceTest method test_all_entities_have_export_configuration.
@Test
public void test_all_entities_have_export_configuration() {
Collection<String> exportableTables = DatabaseExportService.EXPORT_CONFIGS.values();
Set<String> missingEntities = new HashSet<>();
Set<String> exportedButNotWanted = new HashSet<>();
JavaClasses classes = new ClassFileImporter().importPackages("de.symeda.sormas.backend");
for (JavaClass clazz : classes) {
if (clazz.isAnnotatedWith(Entity.class)) {
Entity entityAnnotation = clazz.getAnnotationOfType(Entity.class);
String tableName = entityAnnotation.name();
if (StringUtils.isBlank(tableName)) {
tableName = clazz.getSimpleName().toLowerCase();
}
if (!exportableTables.contains(tableName)) {
missingEntities.add(clazz.getSimpleName());
} else if (NOT_EXPORTED_ENTITIES.contains(clazz.reflect())) {
exportedButNotWanted.add(clazz.getSimpleName());
}
}
}
// remove not exported entities from the list of missing ones
NOT_EXPORTED_ENTITIES.forEach(e -> missingEntities.remove(e.getSimpleName()));
assertThat("Missing export configuration for entities [" + String.join(", ", missingEntities) + "]", missingEntities, hasSize(0));
assertThat("Export configuration not wanted for entities [" + String.join(", ", exportedButNotWanted) + "]", exportedButNotWanted, hasSize(0));
}
use of com.tngtech.archunit.core.domain.JavaClass 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);
}
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ArchitecturesTest method onion_architecture_with_overwritten_description_retains_ignored_dependencies.
@Test
public void onion_architecture_with_overwritten_description_retains_ignored_dependencies() {
ArchRule onionIgnoringOriginApplicationLayerClass = getTestOnionArchitecture().ignoreDependency(equivalentTo(ApplicationLayerClass.class), DescribedPredicate.<JavaClass>alwaysTrue()).because("some reason causing description to be overwritten");
JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
EvaluationResult result = onionIgnoringOriginApplicationLayerClass.evaluate(classes);
ExpectedOnionViolations expectedViolations = getExpectedOnionViolations().withoutViolationsWithOrigin(ApplicationLayerClass.class);
assertPatternMatches(result.getFailureReport().getDetails(), expectedViolations.toPatterns());
}
Aggregations