@Test
public void testInvalidListRange() throws Exception {

    final String rootDir = "root_dir";
    final String stringDir = "string_dir";
    final String longConstDir = "long_const_dir";
    KeySpaceDirectory dirA = new KeySpaceDirectory(rootDir, KeyType.LONG, random.nextLong())
            .addSubdirectory(new KeySpaceDirectory(stringDir, KeyType.STRING))
            .addSubdirectory(new KeySpaceDirectory(longConstDir, KeyType.LONG, 100));
    KeySpace root = new KeySpace(dirA);
    final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
    try (FDBRecordContext context = database.openContext()) {
        // Positive example.
        root.path(rootDir)
                .listSubdirectory(context, stringDir,
                        new ValueRange<>("A", "B", EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE),
                        null,
                        ScanProperties.FORWARD_SCAN);
        // The range value should be in the same type.
        assertThrows(RecordCoreArgumentException.class, () ->
                root.path(rootDir).listSubdirectory(
                        context,
                        stringDir,
                        new ValueRange<>(100, 200, EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE),
                        null,
                        ScanProperties.FORWARD_SCAN)
        );
        // PREFIX_STRING should not be used as a endpoint type.
        assertThrows(RecordCoreArgumentException.class, () ->
                root.path(rootDir).listSubdirectory(
                        context,
                        stringDir,
                        new ValueRange<>("A", "B", EndpointType.PREFIX_STRING, EndpointType.RANGE_EXCLUSIVE),
                        null,
                        ScanProperties.FORWARD_SCAN)
        );
        // Range should be null when the subdirectory has a value.
        assertThrows(RecordCoreArgumentException.class, () ->
                root.path(rootDir).listSubdirectory(
                        context,
                        longConstDir,
                        new ValueRange<>(100, 200, EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE),
                        null,
                        ScanProperties.FORWARD_SCAN)
        );
    }
}