### Question:
JdbcMetadataBuilder implements MetadataBuilder<Connection>,
        ParametrizedMetadataBuilder<Connection, PartialMetadataOptions> { protected List<DataSourceTableDescriptor> parseAndFilterValidSchemas(List<DataSourceTableDescriptor> dataSourceTableDescriptors, List<String> schemas, DatabaseMetaData databaseMetaData, String databaseProductName){ List<DataSourceTableDescriptor> result = new ArrayList<DataSourceTableDescriptor>(); for (DataSourceTableDescriptor dataSourceTableDescriptor : dataSourceTableDescriptors) { if(dataSourceTableDescriptor != null){ if(dataSourceTableDescriptor.getSchemaName() != null && !schemas.isEmpty()){ if(schemas.contains(dataSourceTableDescriptor.getSchemaName()) || (characterEscape != null && schemas.contains(characterEscape.escape(dataSourceTableDescriptor.getSchemaName(), databaseMetaData, databaseProductName)))){ result.add(dataSourceTableDescriptor); } } else if (dataSourceTableDescriptor.getSchemaName() == null && dataSourceTableDescriptor.getDatasourceTableName() != null && !schemas.isEmpty()) { } else { result.add(dataSourceTableDescriptor); } } } return result; }  @Override SchemaElement build(Connection connection, PartialMetadataOptions options); SchemaElement build(Connection connection, Map<String, String[]> options); void setCharacterEscape(SpecialCharacterEscape characterEscape); static final String GROUP_KIND_SCHEMA; static final String GROUP_KIND_DATASOURCE; }### Answer:
@Test public void parseAndFilterValidSchema() throws Exception { List<DataSourceTableDescriptor> list = new ArrayList<DataSourceTableDescriptor>(); list.add(new DataSourceTableDescriptor().setSchemaName("public")); final List<DataSourceTableDescriptor> result = jdbcMetadataBuilder.parseAndFilterValidSchemas(list, new ArrayList<String>(Arrays.asList("public", "information_schema, pg_catalog")), null, "PostgreSQL"); List expectedResult = new ArrayList<DataSourceTableDescriptor>(); expectedResult.add(new DataSourceTableDescriptor().setSchemaName("public")); assertEquals(result, expectedResult); }
@Test public void parseAndFilterValidSchema_MySQLNoSchemaCase() throws Exception { List<DataSourceTableDescriptor> list = new ArrayList<DataSourceTableDescriptor>(); list.add(new DataSourceTableDescriptor().setDatasourceTableName("account")); final List<DataSourceTableDescriptor> result = jdbcMetadataBuilder.parseAndFilterValidSchemas(list, new ArrayList<String>(), null, "MySQL"); List expectedResult = new ArrayList<String[]>(); expectedResult.add(new DataSourceTableDescriptor().setDatasourceTableName("account")); assertEquals(result, expectedResult); }
@Test public void parseAndFilterValidSchema_IncludeEmptySchema() throws Exception { List<DataSourceTableDescriptor> list = new ArrayList<DataSourceTableDescriptor>(); list.add(new DataSourceTableDescriptor().setSchemaName("public")); list.add(new DataSourceTableDescriptor().setSchemaName("public").setDatasourceTableName("")); final List<DataSourceTableDescriptor> result = jdbcMetadataBuilder.parseAndFilterValidSchemas(list, new ArrayList<String>(Arrays.asList("public", "information_schema, pg_catalog")), null, "PostgreSQL"); List expectedResult = new ArrayList<String[]>(); expectedResult.add(new DataSourceTableDescriptor().setSchemaName("public")); expectedResult.add(new DataSourceTableDescriptor().setSchemaName("public").setDatasourceTableName("")); assertEquals(result, expectedResult); }