### Question:
PostgreSqlSchemaParser extends DefaultJdbcSchemaParser { @Nonnull @Override public List<JdbcCatalog> listCatalogs(@Nonnull final Connection connection, @Nullable final String pattern, @Nullable final Pageable pageable) throws SQLException { if (StringUtils.equals(connection.getCatalog(), POSTGRES)) { try (final Statement statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery("SELECT datname AS TABLE_CAT FROM pg_database")) { return JdbcUtil.transformResults(resultSet, DefaultJdbcCatalog.fromResultSet()); } } else { return Collections.emptyList(); } }  @Override boolean acceptsURL(@Nonnull final String url); @Nonnull @Override List<JdbcCatalog> listCatalogs(@Nonnull final Connection connection, @Nullable final String pattern, @Nullable final Pageable pageable); @Nonnull @Override DataSourceProperties prepareDataSource(@Nonnull final DataSourceProperties properties, @Nullable final String catalog);  }### Answer:
@Test public void listCatalogsWithPostgres() throws SQLException { try (final Connection h2c = DriverManager.getConnection("jdbc:h2:mem:postgresql")) { final Statement h2s = h2c.createStatement(); h2s.execute("CREATE TABLE pg_database (datname VARCHAR(16))"); h2s.execute("INSERT INTO pg_database VALUES ('kylo'), ('postgres'), ('test')"); final Connection connection = Mockito.mock(Connection.class); Mockito.when(connection.createStatement()).thenReturn(h2c.createStatement()); Mockito.when(connection.getCatalog()).thenReturn("postgres"); final JdbcSchemaParser parser = new PostgreSqlSchemaParser(); final List<JdbcCatalog> catalogs = parser.listCatalogs(connection, null, null); Assert.assertEquals("kylo", catalogs.get(0).getCatalog()); Assert.assertEquals("postgres", catalogs.get(1).getCatalog()); Assert.assertEquals("test", catalogs.get(2).getCatalog()); Assert.assertEquals(3, catalogs.size()); } }
@Test public void listCatalogsWithOther() throws SQLException { final Connection connection = Mockito.mock(Connection.class); Mockito.when(connection.getCatalog()).thenReturn("kylo"); final JdbcSchemaParser parser = new PostgreSqlSchemaParser(); final List<JdbcCatalog> catalogs = parser.listCatalogs(connection, null, null); Assert.assertEquals(Collections.emptyList(), catalogs); }