ColumnsHolder { public List<String> getColumns(final String tableName) { final List<String> tableColumns = columnsInTable.get(tableName); final List<String> result = new ArrayList<>(); result.addAll(columns); result.addAll(tableColumns != null ? tableColumns : Collections.emptyList()); return result; } ColumnsHolder(final String[] columnNames, final Function<String, String> idMapper); List<String> getColumns(final String tableName);  }
@Test public void testCreateColumnHolderForColumnNamesWithoutTableNamesOnly() { final String column1 = "col1"; final String column2 = "col2"; final ColumnsHolder columnsHolder = new ColumnsHolder(new String[] { column1, column2 }, (final String n) -> n); final List<String> columns = columnsHolder.getColumns("foo"); assertThat(columns, notNullValue()); assertThat(columns.size(), equalTo(2)); assertThat(columns, hasItem(column1)); assertThat(columns, hasItem(column2)); }
@Test public void testCreateColumnHolderForColumnNamesWithTableNamesOnly() { final String column1 = "tab.col1"; final String column2 = "tab.col2"; final ColumnsHolder columnsHolder = new ColumnsHolder(new String[] { column1, column2 }, (final String n) -> n); List<String> columns = columnsHolder.getColumns("tab"); assertThat(columns, notNullValue()); assertThat(columns.size(), equalTo(2)); assertThat(columns, hasItem(column1.substring(column1.indexOf('.') + 1))); assertThat(columns, hasItem(column2.substring(column2.indexOf('.') + 1))); columns = columnsHolder.getColumns("foo"); assertThat(columns, notNullValue()); assertThat(columns.size(), equalTo(0)); }
@Test public void testCreateColumnHolderForMixModeColumnNames() { final String column1 = "tab.col1"; final String column2 = "tab.col2"; final String column3 = "col3"; final ColumnsHolder columnsHolder = new ColumnsHolder(new String[] { column1, column2, column3 }, (final String n) -> n); List<String> columns = columnsHolder.getColumns("tab"); assertThat(columns, notNullValue()); assertThat(columns.size(), equalTo(3)); assertThat(columns, hasItem(column1.substring(column1.indexOf('.') + 1))); assertThat(columns, hasItem(column2.substring(column2.indexOf('.') + 1))); assertThat(columns, hasItem(column3)); columns = columnsHolder.getColumns("foo"); assertThat(columns, notNullValue()); assertThat(columns.size(), equalTo(1)); assertThat(columns, hasItem(column3)); }