use of org.eclipse.elk.alg.test.framework.annotations.Algorithm in project elk by eclipse.
the class TestAlgorithm method fromTestClass.
/**
* Loads the test layout algorithms defined in the test class.
*
* @param testClass
* the test class.
* @param errors
* list of error conditions encountered while evaluating the layout algorithms.
* @return a list of layout algorithms to use during the test.
*/
public static List<TestAlgorithm> fromTestClass(final TestClass testClass, final List<Throwable> errors) {
List<LayoutAlgorithmData> algorithmData = new ArrayList<>();
// Obtain annotations
Algorithm[] algorithmAnnotations = testClass.getJavaClass().getAnnotationsByType(Algorithm.class);
AllAlgorithms allAlgorithmsAnnotation = testClass.getAnnotation(AllAlgorithms.class);
LayoutMetaDataService service = LayoutMetaDataService.getInstance();
if (algorithmAnnotations.length != 0 && allAlgorithmsAnnotation != null) {
// Only one of the two may be specified
errors.add(new Exception("If @AllAlgorithms is specified, @Algorithm cannot be used anymore."));
} else if (allAlgorithmsAnnotation != null) {
// Simply add all known algorithm IDs
algorithmData.addAll(service.getAlgorithmData());
} else {
// Add all specifically supplied IDs as long as they refer to known layout algorithms
for (Algorithm algAnnotation : algorithmAnnotations) {
LayoutAlgorithmData algData = service.getAlgorithmData(algAnnotation.value());
if (algData != null) {
algorithmData.add(algData);
} else {
errors.add(new Exception("Unknown layout algorithm: " + algAnnotation.value()));
}
}
}
// Produce the list of algorithms
List<TestAlgorithm> algorithms = new ArrayList<>();
algorithmData.stream().sorted((data1, data2) -> data1.getId().compareTo(data2.getId())).map(algData -> new TestAlgorithm(algData)).forEach(strategy -> algorithms.add(strategy));
return algorithms;
}
Aggregations