/** * Test constructor to create a non-empty database. * * @throws BioException if iterator fails. */ public void testNonEmptyConstructor() throws BioException { SimpleSymbolPropertyTableDB dbInit = new SimpleSymbolPropertyTableDB(); SymbolPropertyTable t1 = new SimpleSymbolPropertyTable(ProteinTools.getAlphabet(), "protein"); SymbolPropertyTable t2 = new SimpleSymbolPropertyTable(DNATools.getDNA(), "dna"); dbInit.addTable(t1); dbInit.addTable(t2); SymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB(dbInit.tableIterator()); assertEquals("Database has wrong number of tables.", 2, db.numTables()); SymbolPropertyTableIterator iterator = db.tableIterator(); ArrayList tables = new ArrayList(2); while (iterator.hasNext()) { tables.add(iterator.nextTable()); } assertEquals("Iterator returned wrong number of tables.", 2, tables.size()); assertEquals("Iterator returned wrong table.", t1, tables.get(0)); assertEquals("Iterator returned wrong table.", t2, tables.get(1)); }
/** Test for {@link SimpleSymbolPropertyTableDB#table(String)}. */ public void testTable() { SimpleSymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB(); try { db.table(null); fail("table must throw NullPointerException."); } catch (NullPointerException e) { e.printStackTrace(); } catch (IllegalIDException e) { fail("table throwed IllegalIDException instead of NullPointerException."); } try { db.table("test"); fail("table must throw IllegalIDException."); } catch (IllegalIDException e) { e.printStackTrace(); } }
/** * Test for {@link SimpleSymbolPropertyTableDB#addTable(SymbolPropertyTable)}. * * @throws IllegalIDException if {@link SymbolPropertyTableDB#table(String)} fails. */ public void testAddTable() throws IllegalIDException { SimpleSymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB(); SymbolPropertyTable t1 = new SimpleSymbolPropertyTable(ProteinTools.getAlphabet(), "protein"); SymbolPropertyTable t2 = new SimpleSymbolPropertyTable(DNATools.getDNA(), "dna"); db.addTable(t1); assertEquals("Database has wrong number of tables.", 1, db.numTables()); db.addTable(t2); assertEquals("Database has wrong number of tables.", 2, db.numTables()); assertEquals("Database returned wrong table.", t1, db.table("protein")); assertEquals("Database returned wrong table.", t2, db.table("dna")); Set names = db.names(); assertTrue("Table is missing.", names.contains("protein")); assertTrue("Table is missing.", names.contains("dna")); assertEquals("Database has wrong number of tables.", 2, names.size()); try { db.addTable(null); fail("addTable must throw NullPointerException."); } catch (NullPointerException e) { e.printStackTrace(); } }