下面列出了怎么用org.junit.jupiter.api.DynamicNode的API类实例代码及写法,或者点击链接到github查看源代码。
@TestFactory
@DisplayName("Objects")
Stream<DynamicNode> objects() {
Map<String, Map<String, Object>> supportedTypes = new HashMap<>();
supportedTypes.put("CypherTypes", CYPHER_TYPES);
supportedTypes.put("AdditionalTypes", ADDITIONAL_TYPES);
supportedTypes.put("SpatialTypes", SPATIAL_TYPES);
return supportedTypes.entrySet().stream()
.map(types -> {
DynamicContainer reads = DynamicContainer.dynamicContainer("read", types.getValue().entrySet().stream()
.map(a -> dynamicTest(a.getKey(),
() -> Neo4jConversionsIT.assertRead(types.getKey(), a.getKey(), a.getValue()))));
DynamicContainer writes = DynamicContainer.dynamicContainer("write", types.getValue().entrySet().stream()
.map(a -> dynamicTest(a.getKey(),
() -> Neo4jConversionsIT.assertWrite(types.getKey(), a.getKey(), a.getValue()))));
return DynamicContainer.dynamicContainer(types.getKey(), Arrays.asList(reads, writes));
});
}
@TestFactory
Collection<DynamicNode> compressedChunkedDatasetReadTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
dynamicTest("float32", createTest(earliestHdfFile,"/float/float32")),
dynamicTest("float64", createTest(earliestHdfFile,"/float/float64")),
dynamicTest("int8", createTest(earliestHdfFile,"/int/int8")),
dynamicTest("int16", createTest(earliestHdfFile,"/int/int16")),
dynamicTest("int32", createTest(earliestHdfFile,"/int/int32")))),
dynamicContainer(HDF5_TEST_LATEST_FILE_NAME, Arrays.asList(
dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
dynamicTest("float64", createTest(latestHdfFile,"/float/float64")),
dynamicTest("int8", createTest(latestHdfFile,"/int/int8")),
dynamicTest("int16", createTest(latestHdfFile,"/int/int16")),
dynamicTest("int32", createTest(latestHdfFile,"/int/int32")))));
}
@TestFactory
Collection<DynamicNode> compressedChunkedDatasetReadTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
dynamicTest("float32", createTest(earliestHdfFile,"/float/float32")),
dynamicTest("float64", createTest(earliestHdfFile,"/float/float64")),
dynamicTest("int8", createTest(earliestHdfFile,"/int/int8")),
dynamicTest("int16", createTest(earliestHdfFile,"/int/int16")),
dynamicTest("int32", createTest(earliestHdfFile,"/int/int32")))),
dynamicContainer(HDF5_TEST_LATEST_FILE_NAME, Arrays.asList(
dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
dynamicTest("float64", createTest(latestHdfFile,"/float/float64")),
dynamicTest("int8", createTest(latestHdfFile,"/int/int8")),
dynamicTest("int16", createTest(latestHdfFile,"/int/int16")),
dynamicTest("int32", createTest(latestHdfFile,"/int/int32")))));
}
@TestFactory
Collection<DynamicNode> chunkedDatasetReadTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
dynamicTest("float16", createTest(earliestHdfFile, "/float/float16")),
dynamicTest("float32", createTest(earliestHdfFile, "/float/float32")),
dynamicTest("float64", createTest(earliestHdfFile, "/float/float64")),
dynamicTest("int8", createTest(earliestHdfFile, "/int/int8")),
dynamicTest("int16", createTest(earliestHdfFile, "/int/int16")),
dynamicTest("int32", createTest(earliestHdfFile, "/int/int32")))),
dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
dynamicTest("float16", createTest(latestHdfFile, "/float/float16")),
dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
dynamicTest("float64", createTest(latestHdfFile, "/float/float64")),
dynamicTest("int8", createTest(latestHdfFile, "/int/int8")),
dynamicTest("int16", createTest(latestHdfFile, "/int/int16")),
dynamicTest("int32", createTest(latestHdfFile, "/int/int32"))))
);
}
@TestFactory
Collection<DynamicNode> specialFloatValuesTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer("earliest", Arrays.asList(
dynamicTest("float16",
testFloat(earliestHdfFile, "float16")),
dynamicTest("float32",
testFloat(earliestHdfFile, "float32")),
dynamicTest("float64",
testDouble(earliestHdfFile, "float64")))),
dynamicContainer("latest", Arrays.asList(
dynamicTest("float16",
testFloat(latestHdfFile, "float16")),
dynamicTest("float32",
testFloat(latestHdfFile, "float32")),
dynamicTest("float64",
testDouble(latestHdfFile, "float64")))));
}
@TestFactory
Collection<DynamicNode> stringDataset1DTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer("earliest", Arrays.asList(
dynamicTest("fixed ASCII",
createTest(earliestHdfFile, "/fixed_length_ascii")),
dynamicTest("fixed ASCII 1 char",
createTest(earliestHdfFile, "/fixed_length_ascii_1_char")),
dynamicTest("variable ASCII",
createTest(earliestHdfFile, "/variable_length_ascii")),
dynamicTest("variable UTF8",
createTest(earliestHdfFile, "/variable_length_utf8")))),
dynamicContainer("latest", Arrays.asList(
dynamicTest("fixed ASCII",
createTest(latestHdfFile, "/fixed_length_ascii")),
dynamicTest("fixed ASCII 1 char",
createTest(latestHdfFile, "/fixed_length_ascii_1_char")),
dynamicTest("variable ASCII",
createTest(latestHdfFile, "/variable_length_ascii")),
dynamicTest("variable UTF8",
createTest(latestHdfFile, "/variable_length_utf8")))));
}
@TestFactory
Stream<DynamicNode> allHdf5TestFiles() throws IOException, URISyntaxException {
// Auto discover the test files assuming they exist in under the directory
// containing test_file.hdf5
URL resource = this.getClass().getResource("/hdf5/");
Path path = Paths.get(resource.toURI()).getParent();
List<Path> files = Files.walk(path).filter(HDF5::matches).collect(Collectors.toList());
// Check at least some files have been discovered
assertThat("Less than 3 HDF5 test files discovered searched paths below: " + path.toAbsolutePath(),
files.size(), is(greaterThan(2)));
// Make a test for each file
return files.stream().map(this::createTest);
}
@TestFactory
Collection<DynamicNode> scalarDatasetTests() {
// List of all the datasetPaths
return Collections.singletonList(
dynamicContainer("earliest", Arrays.asList(
dynamicTest("fixed ASCII",
createTest(earliestHdfFile, 800)),
dynamicTest("fixed ASCII 1 char",
createTest(earliestHdfFile, 1400)),
dynamicTest("variable ASCII",
createTest(earliestHdfFile, 1672)),
dynamicTest("variable UTF8",
createTest(earliestHdfFile, 6654)))));
}
@TestFactory
Collection<DynamicNode> compressedChunkedDatasetReadTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
dynamicTest("8D_int16", createTest(earliestHdfFile, "/8D_int16")),
dynamicTest("1D_int16", createTest(earliestHdfFile, "/1D_int16")))),
dynamicContainer(HDF5_TEST_LATEST_FILE_NAME, Arrays.asList(
dynamicTest("8D_int16", createTest(latestHdfFile, "/8D_int16")),
dynamicTest("1D_int16", createTest(latestHdfFile, "/1D_int16"))))
);
}
@TestFactory
Stream<DynamicNode> verifyDatasets() {
List<Dataset> datasets = new ArrayList<>();
getAllDatasets(hdfFile, datasets);
return datasets.stream().map(this::verifyDataset);
}
@TestFactory
Collection<DynamicNode> fillValueTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer("earliest", Arrays.asList(
dynamicTest("float32",
createTest(earliestHdfFile, "float/float32", float.class, 33.33f)),
dynamicTest("float64",
createTest(earliestHdfFile, "float/float64", double.class, 123.456)),
dynamicTest("int8",
createTest(earliestHdfFile, "int/int8", byte.class, (byte) 8)),
dynamicTest("int16",
createTest(earliestHdfFile, "int/int16", short.class, (short) 16)),
dynamicTest("int32",
createTest(earliestHdfFile, "int/int32", int.class, 32)),
dynamicTest("int64",
createTest(earliestHdfFile, "no_fill", byte.class, null)))),
dynamicContainer("latest", Arrays.asList(
dynamicTest("float32",
createTest(latestHdfFile, "float/float32", float.class, 33.33f)),
dynamicTest("float64",
createTest(latestHdfFile, "float/float64", double.class, 123.456)),
dynamicTest("int8",
createTest(latestHdfFile, "int/int8", byte.class, (byte) 8)),
dynamicTest("int16",
createTest(latestHdfFile, "int/int16", short.class, (short) 16)),
dynamicTest("int32",
createTest(latestHdfFile, "int/int32", int.class, 32)),
dynamicTest("int64",
createTest(latestHdfFile, "no_fill", byte.class, null)))));
}
@TestFactory
Collection<DynamicNode> compressedChunkedDatasetReadTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
dynamicTest("float32", createTest(earliestHdfFile,"vlen_float32_data")),
dynamicTest("float32 - chunked", createTest(earliestHdfFile,"vlen_float32_data_chunked")),
dynamicTest("float64", createTest(earliestHdfFile,"vlen_float64_data")),
dynamicTest("float64 - chunked", createTest(earliestHdfFile,"vlen_float64_data_chunked")),
dynamicTest("uint8", createTest(earliestHdfFile,"vlen_uint8_data")),
dynamicTest("uint8 - chunked", createTest(earliestHdfFile,"vlen_uint8_data_chunked")),
dynamicTest("uint16", createTest(earliestHdfFile,"vlen_uint16_data")),
dynamicTest("uint16 - chunked", createTest(earliestHdfFile,"vlen_uint16_data_chunked")),
dynamicTest("uint32", createTest(earliestHdfFile,"vlen_uint32_data")),
dynamicTest("uint32 - chunked", createTest(earliestHdfFile,"vlen_uint32_data_chunked")),
dynamicTest("uint64", createTest(earliestHdfFile,"vlen_uint64_data")),
dynamicTest("uint64 - chunked", createTest(earliestHdfFile,"vlen_uint64_data_chunked")))),
dynamicContainer(HDF5_TEST_LATEST_FILE_NAME, Arrays.asList(
dynamicTest("float32", createTest(latestHdfFile,"vlen_float32_data")),
dynamicTest("float32 - chunked", createTest(latestHdfFile,"vlen_float32_data_chunked")),
dynamicTest("float64", createTest(latestHdfFile,"vlen_float64_data")),
dynamicTest("float64 - chunked", createTest(latestHdfFile,"vlen_float64_data_chunked")),
dynamicTest("uint8", createTest(latestHdfFile,"vlen_uint8_data")),
dynamicTest("uint8 - chunked", createTest(latestHdfFile,"vlen_uint8_data_chunked")),
dynamicTest("uint16", createTest(latestHdfFile,"vlen_uint16_data")),
dynamicTest("uint16 - chunked", createTest(latestHdfFile,"vlen_uint16_data_chunked")),
dynamicTest("uint32", createTest(latestHdfFile,"vlen_uint32_data")),
dynamicTest("uint32 - chunked", createTest(latestHdfFile,"vlen_uint32_data_chunked")),
dynamicTest("uint64", createTest(latestHdfFile,"vlen_uint64_data")),
dynamicTest("uint64 - chunked", createTest(latestHdfFile,"vlen_uint64_data_chunked")))));
}
@TestFactory
Stream<DynamicNode> earliest() {
List<Dataset> datasets = new ArrayList<>();
getAllDatasets(earliestHdfFile, datasets);
return datasets.stream().map(this::verifyDataset);
}
@TestFactory
Stream<DynamicNode> latest() {
List<Dataset> datasets = new ArrayList<>();
getAllDatasets(latestHdfFile, datasets);
return datasets.stream().map(this::verifyDataset);
}
private DynamicNode createTest(Path path) {
return dynamicTest(path.getFileName().toString(), () -> {
try (HdfFile hdfFile = new HdfFile(path.toFile())) {
verifyAttributes(hdfFile);
recurseGroup(hdfFile);
}
});
}
@TestFactory
Stream<DynamicNode> datasetReadTests() {
return Stream.of(
dynamicTest("Signed Byte", createTest(byteBuffer, byteDataType, dims, byteResult)),
dynamicTest("Unsigned Byte", createTest(byteBuffer, unsignedByteDataType, dims, unsignedByteResult)),
dynamicTest("Signed Short", createTest(shortBuffer, shortDataType, dims, shortResult)),
dynamicTest("Unsigned Short", createTest(shortBuffer, unsignedShortDataType, dims, unsignedShortResult)),
dynamicTest("Signed Int", createTest(intBuffer, intDataType, dims, intResult)),
dynamicTest("Unsigned Int", createTest(intBuffer, unsignedIntDataType, dims, unsignedIntResult)),
dynamicTest("Signed Long", createTest(longBuffer, longDataType, dims, longResult)),
dynamicTest("Unsigned Long", createTest(longBuffer, unsignedLongDataType, dims, unsignedLongResult)));
}
@TestFactory
Stream<DynamicNode> dynamicTestsWithContainers() {
return Stream
.of("A", "B", "C").map(
input -> dynamicContainer("Container " + input, Stream
.of(dynamicTest("not null", () -> assertNotNull(input)),
dynamicContainer("properties",
Stream.of(
dynamicTest("length > 0",
() -> assertTrue(input
.length() > 0)),
dynamicTest("not empty",
() -> assertFalse(input
.isEmpty())))))));
}
@TestFactory
Stream<DynamicNode> should_DetectCorpusChristiAsHoliday_When_CorpusChristiIsEnabled() {
WorkingDaysToDaysConverter converter = new WorkingDaysToDaysConverter(true, true);
DynamicTest year1980 =
DynamicTest.dynamicTest(
"year 1980",
() -> assertThat(converter.isGermanHoliday(LocalDate.parse("1980-06-05"))).isTrue());
DynamicTest year2020 =
DynamicTest.dynamicTest(
"year 2020",
() -> assertThat(converter.isGermanHoliday(LocalDate.parse("2020-06-11"))).isTrue());
return Stream.of(year1980, year2020);
}
private static void persistDynamicContainerChildren(
Iterable<DynamicNode> nodes, Map<String, List<DynamicNode>> childrenMap) {
nodes.forEach(
node -> {
if (node instanceof DynamicContainer) {
DynamicContainer container = (DynamicContainer) node;
List<DynamicNode> children = container.getChildren().collect(Collectors.toList());
childrenMap.put(container.hashCode() + container.getDisplayName(), children);
persistDynamicContainerChildren(children, childrenMap);
}
});
}
private static DynamicNode duplicateDynamicNode(
DynamicNode node, Map<String, List<DynamicNode>> lookupMap) {
if (node instanceof DynamicContainer) {
DynamicContainer container = (DynamicContainer) node;
Stream<DynamicNode> children =
lookupMap.get(node.hashCode() + node.getDisplayName()).stream()
.map(x -> duplicateDynamicNode(x, lookupMap));
return DynamicContainer.dynamicContainer(container.getDisplayName(), children);
}
return node;
}
@TestFactory
Stream<DynamicNode> ratings() {
return Stream.of(Rating.values())
.map(rating -> dynamicContainer(rating.getCode(), Stream.of(
dynamicContainer("is better than", betterThan(rating)),
dynamicContainer("is worse than", worseThan(rating)))));
}
@TestFactory
Stream<DynamicNode> conditions() {
return Stream.of(new BorrowerIncomeConditionSpec(), new BorrowerRegionConditionSpec(),
new LoanPurposeConditionSpec(), new LoanRatingEnumeratedConditionSpec(),
new HealthConditionSpec())
.map(spec -> dynamicContainer(spec.getImplementation()
.getClass()
.getSimpleName(), forSpec(spec)));
}
private static DynamicNode generateTestTreeFor(
ArithmeticNode arithmeticNode, ArithmeticTreeTestData treeTestData) {
var testForNode = generateTestFor(arithmeticNode, treeTestData);
if (arithmeticNode.operands().isEmpty())
return testForNode;
else {
var testsForChildren = generateTestsFor(arithmeticNode.operands(), treeTestData);
var expected = treeTestData.resultFor(arithmeticNode);
var testName = arithmeticNode + " should evaluate to " + expected + " (ops '+3' and '*10' fail)";
return dynamicContainer(testName, concat(of(testForNode), testsForChildren));
}
}
@TestFactory
Stream<DynamicNode> conversionsShouldBeAppliedToEntities() {
Map<String, Map<String, Object>> supportedTypes = new HashMap<>();
supportedTypes.put("CypherTypes", CYPHER_TYPES);
supportedTypes.put("AdditionalTypes", ADDITIONAL_TYPES);
supportedTypes.put("SpatialTypes", SPATIAL_TYPES);
supportedTypes.put("CustomTypes", CUSTOM_TYPES);
return supportedTypes.entrySet().stream()
.map(entry -> {
Object thing;
Object copyOfThing;
switch (entry.getKey()) {
case "CypherTypes":
ThingWithAllCypherTypes hlp = cypherTypesRepository.findById(ID_OF_CYPHER_TYPES_NODE).get();
copyOfThing = cypherTypesRepository.save(hlp.withId(null));
thing = hlp;
break;
case "AdditionalTypes":
ThingWithAllAdditionalTypes hlp2 = additionalTypesRepository
.findById(ID_OF_ADDITIONAL_TYPES_NODE).get();
copyOfThing = additionalTypesRepository.save(hlp2.withId(null));
thing = hlp2;
break;
case "SpatialTypes":
ThingWithAllSpatialTypes hlp3 = spatialTypesRepository.findById(ID_OF_SPATIAL_TYPES_NODE)
.get();
copyOfThing = spatialTypesRepository.save(hlp3.withId(null));
thing = hlp3;
break;
case "CustomTypes":
ThingWithCustomTypes hlp4 = customTypesRepository.findById(ID_OF_CUSTOM_TYPE_NODE)
.get();
copyOfThing = customTypesRepository.save(hlp4.withId(null));
thing = hlp4;
break;
default:
throw new UnsupportedOperationException("Unsupported types: " + entry.getKey());
}
DynamicContainer reads = DynamicContainer.dynamicContainer("read", entry.getValue().entrySet().stream()
.map(a -> dynamicTest(a.getKey(),
() -> assertThat(ReflectionTestUtils.getField(thing, a.getKey())).isEqualTo(a.getValue()))));
DynamicContainer writes = DynamicContainer
.dynamicContainer("write", entry.getValue().entrySet().stream()
.map(a -> dynamicTest(a.getKey(),
() -> assertWrite(copyOfThing, a.getKey(), defaultConversionService))));
return DynamicContainer.dynamicContainer(entry.getKey(), Arrays.asList(reads, writes));
});
}
@TestFactory
Collection<DynamicNode> scalarDatasetTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer("earliest", Arrays.asList(
dynamicTest("float32",
createTest(earliestHdfFile, "scalar_float_32", 123.45f)),
dynamicTest("float64",
createTest(earliestHdfFile, "scalar_float_64", 123.45d)),
dynamicTest("int8",
createTest(earliestHdfFile, "scalar_int_8", (byte) 123)),
dynamicTest("int16",
createTest(earliestHdfFile, "scalar_int_16", (short) 123)),
dynamicTest("int32",
createTest(earliestHdfFile, "scalar_int_32", 123)),
dynamicTest("int64",
createTest(earliestHdfFile, "scalar_int_64", (long) 123)),
dynamicTest("uint8",
createTest(earliestHdfFile, "scalar_uint_8", 123)),
dynamicTest("uint16",
createTest(earliestHdfFile, "scalar_uint_16", 123)),
dynamicTest("uint32",
createTest(earliestHdfFile, "scalar_uint_32", (long) 123)),
dynamicTest("uint64",
createTest(earliestHdfFile, "scalar_uint_64", BigInteger.valueOf(123))),
dynamicTest("string",
createTest(earliestHdfFile, "scalar_string", "hello")))),
dynamicContainer("latest", Arrays.asList(
dynamicTest("float32",
createTest(latestHdfFile, "scalar_float_32", 123.45f)),
dynamicTest("float64",
createTest(latestHdfFile, "scalar_float_64", 123.45d)),
dynamicTest("int8",
createTest(latestHdfFile, "scalar_int_8", (byte) 123)),
dynamicTest("int16",
createTest(latestHdfFile, "scalar_int_16", (short) 123)),
dynamicTest("int32",
createTest(latestHdfFile, "scalar_int_32", 123)),
dynamicTest("int64",
createTest(latestHdfFile, "scalar_int_64", (long) 123)),
dynamicTest("uint8",
createTest(latestHdfFile, "scalar_uint_8", 123)),
dynamicTest("uint16",
createTest(latestHdfFile, "scalar_uint_16", 123)),
dynamicTest("uint32",
createTest(latestHdfFile, "scalar_uint_32", (long) 123)),
dynamicTest("uint64",
createTest(latestHdfFile, "scalar_uint_64", BigInteger.valueOf(123))),
dynamicTest("string",
createTest(latestHdfFile, "scalar_string", "hello")))));
}
@TestFactory
Collection<DynamicNode> emptyDatasetTests() {
// List of all the datasetPaths
return Arrays.asList(
dynamicContainer("earliest", Arrays.asList(
dynamicTest("float32",
createTest(earliestHdfFile, "empty_float_32", Float.class)),
dynamicTest("float64",
createTest(earliestHdfFile, "empty_float_64", Double.class)),
dynamicTest("int8",
createTest(earliestHdfFile, "empty_int_8", Byte.class)),
dynamicTest("int16",
createTest(earliestHdfFile, "empty_int_16", Short.class)),
dynamicTest("int32",
createTest(earliestHdfFile, "empty_int_32", Integer.class)),
dynamicTest("int64",
createTest(earliestHdfFile, "empty_int_64", Long.class)),
dynamicTest("uint8",
createTest(earliestHdfFile, "empty_uint_8", Integer.class)),
dynamicTest("uint16",
createTest(earliestHdfFile, "empty_uint_16", Integer.class)),
dynamicTest("uint32",
createTest(earliestHdfFile, "empty_uint_32", Long.class)),
dynamicTest("uint64",
createTest(earliestHdfFile, "empty_uint_64", BigInteger.class)),
dynamicTest("string",
createTest(earliestHdfFile, "empty_string", String.class)))),
dynamicContainer("latest", Arrays.asList(
dynamicTest("float32",
createTest(latestHdfFile, "empty_float_32", Float.class)),
dynamicTest("float64",
createTest(latestHdfFile, "empty_float_64", Double.class)),
dynamicTest("int8",
createTest(latestHdfFile, "empty_int_8", Byte.class)),
dynamicTest("int16",
createTest(latestHdfFile, "empty_int_16", Short.class)),
dynamicTest("int32",
createTest(latestHdfFile, "empty_int_32", Integer.class)),
dynamicTest("int64",
createTest(latestHdfFile, "empty_int_64", Long.class)),
dynamicTest("uint8",
createTest(latestHdfFile, "empty_uint_8", Integer.class)),
dynamicTest("uint16",
createTest(latestHdfFile, "empty_uint_16", Integer.class)),
dynamicTest("uint32",
createTest(latestHdfFile, "empty_uint_32", Long.class)),
dynamicTest("uint64",
createTest(latestHdfFile, "empty_uint_64", BigInteger.class)),
dynamicTest("string",
createTest(latestHdfFile, "empty_string", String.class)))));
}
@TestFactory
Collection<DynamicNode> datasetReadTests() {
return Arrays.asList(dynamicTest("earliest", createTest("test_large_group_earliest.hdf5")),
dynamicTest("latest", createTest("test_large_group_latest.hdf5")));
}
@TestFactory
Stream<DynamicNode> datasetReadTests() {
return Stream.of(
dynamicTest("Float", createTest(floatBuffer, floatDataType, dims, floatResult)),
dynamicTest("Double", createTest(doubleBuffer, doubleDataType, dims, doubleResult)));
}
@TestFactory
Collection<DynamicNode> datasetReadTests() {
return Arrays.asList(
dynamicTest("Reference8", createTest(longBuffer, referenceDataType, dims, longResult)),
dynamicTest("Reference4", createTest(referenceIntBuffer, referenceDataTypeSmall, dims, referenceIntLongResult)));
}
@Override
@SuppressWarnings("unchecked")
public <T> T interceptTestFactoryMethod(
Invocation<T> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) {
WithAccessIds annotation = invocationContext.getExecutable().getAnnotation(WithAccessIds.class);
if (annotation != null) {
// our goal is to run each test returned from the test factory X times. X is the amount of
// WithAccessId annotations. In order to achieve this we are wrapping the result from the
// factory (the returning tests) in a dynamicContainer for each accessId. Since we don't know
// what the factory will return we have to check for every possible return type. All possible
// return types can be found here:
// https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests
// After checking each return type we abuse the return type of T and hardly change it to
// Stream<DynamicContainer> no matter what the factory returns. This return type is allowed
// per definition (See link above), but is not the type T. Hence we have an unchecked cast at
// the end to keep the compiler happy...
// we are using the first annotation to run the factory method with.
T factoryResult = performInvocationWithAccessId(invocation, annotation.value()[0]);
Iterable<DynamicNode> newChildrenForDynamicContainer;
// TestFactory must have one of the following return types. See link above for further details
if (factoryResult instanceof DynamicNode) {
newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult);
} else if (factoryResult instanceof Stream) {
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
newChildrenForDynamicContainer = nodes.collect(Collectors.toList());
} else if (factoryResult instanceof Iterable) {
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
} else if (factoryResult instanceof Iterator) {
newChildrenForDynamicContainer = () -> (Iterator<DynamicNode>) factoryResult;
} else if (factoryResult instanceof DynamicNode[]) {
newChildrenForDynamicContainer = Arrays.asList((DynamicNode[]) factoryResult);
} else {
throw new SystemException(
String.format(
"Testfactory '%s' did not return a proper type",
invocationContext.getExecutable().getName()));
}
// Currently a DynamicContainer has children from this type: Stream<DynamicNode>
// Because of this the children can only be extracted once (Streams can only be operated
// once). This is obviously not ok since we want to execute each node X times. So we have to
// manually persist all children recursively to extract them X times...
Map<String, List<DynamicNode>> childrenMap = new HashMap<>();
persistDynamicContainerChildren(newChildrenForDynamicContainer, childrenMap);
Function<WithAccessId, DynamicContainer> wrapTestsInDynamicContainer =
accessId ->
DynamicContainer.dynamicContainer(
getDisplayNameForAccessId(accessId),
StreamSupport.stream(newChildrenForDynamicContainer.spliterator(), false)
.map(x -> duplicateDynamicNode(x, childrenMap)));
Store store = getStore(extensionContext);
return (T)
Stream.of(annotation.value())
.peek(a -> store.put(ACCESS_IDS_STORE_KEY, a))
.map(wrapTestsInDynamicContainer);
}
return extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}