### Question:
DatabaseTableConfigLoader { public static List<DatabaseTableConfig<?>> loadDatabaseConfigFromReader(BufferedReader reader) throws SQLException { List<DatabaseTableConfig<?>> list = new ArrayList<DatabaseTableConfig<?>>(); while (true) { DatabaseTableConfig<?> config = DatabaseTableConfigLoader.fromReader(reader); if (config == null) { break; } list.add(config); } return list; }  static List<DatabaseTableConfig<?>> loadDatabaseConfigFromReader(BufferedReader reader); static DatabaseTableConfig<T> fromReader(BufferedReader reader); static void write(BufferedWriter writer, DatabaseTableConfig<T> config);  }### Answer:
@Test public void testConfigEntriesFromStream() throws Exception { StringBuilder value = new StringBuilder(); value.append(TABLE_START); value.append("# random comment").append(LINE_SEP); value.append(LINE_SEP); value.append("dataClass=").append(Foo.class.getName()).append(LINE_SEP); String tableName = "fprwojfgopwejfw"; value.append("tableName=").append(tableName).append(LINE_SEP); value.append("# --table-fields-start--").append(LINE_SEP); value.append("# --field-start--").append(LINE_SEP); String fieldName = "weopjfwefjw"; value.append("fieldName=").append(fieldName).append(LINE_SEP); value.append("canBeNull=true").append(LINE_SEP); value.append("generatedId=true").append(LINE_SEP); value.append("# --field-end--").append(LINE_SEP); value.append("# --table-fields-end--").append(LINE_SEP); value.append(TABLE_END); List<DatabaseTableConfig<?>> tables = DatabaseTableConfigLoader.loadDatabaseConfigFromReader(new BufferedReader(new StringReader( value.toString()))); assertEquals(1, tables.size()); assertEquals(tableName, tables.get(0).getTableName()); DatabaseTableConfig<?> config = tables.get(0); List<DatabaseFieldConfig> fields = config.getFieldConfigs(); assertEquals(1, fields.size()); assertEquals(fieldName, fields.get(0).getFieldName()); }
@Test(expected = SQLException.class) public void testConfigInvalidLine() throws Exception { StringBuilder value = new StringBuilder(); value.append(TABLE_START); value.append("dataClass").append(LINE_SEP); DatabaseTableConfigLoader.loadDatabaseConfigFromReader(new BufferedReader(new StringReader(value.toString()))); }
@Test(expected = IllegalArgumentException.class) public void testConfigUnknownClass() throws Exception { StringBuilder value = new StringBuilder(); value.append(TABLE_START); value.append("dataClass=unknown.class.name.okay").append(LINE_SEP); value.append("# --table-fields-start--").append(LINE_SEP); value.append("# --field-start--").append(LINE_SEP); value.append("fieldName=xxx").append(LINE_SEP); value.append("# --field-end--").append(LINE_SEP); value.append("# --table-fields-end--").append(LINE_SEP); value.append(TABLE_END); DatabaseTableConfigLoader.loadDatabaseConfigFromReader(new BufferedReader(new StringReader(value.toString()))); }
@Test public void testQuickEndOfConfig() throws Exception { StringBuilder value = new StringBuilder(); value.append(TABLE_START); value.append("dataClass=").append(Foo.class.getName()).append(LINE_SEP); value.append("# --table-fields-start--").append(LINE_SEP); value.append("# --field-start--").append(LINE_SEP); value.append("fieldName=xxx").append(LINE_SEP); value.append("# --field-end--").append(LINE_SEP); value.append("# --field-start--").append(LINE_SEP); List<DatabaseTableConfig<?>> tables = DatabaseTableConfigLoader.loadDatabaseConfigFromReader(new BufferedReader(new StringReader( value.toString()))); assertEquals(1, tables.size()); DatabaseTableConfig<?> config = tables.get(0); List<DatabaseFieldConfig> fields = config.getFieldConfigs(); assertEquals(1, fields.size()); }