TableTypeFactory { public <T> TableType create(final Class<T> fromClass) { final TableDef tableDef = fromClass.getAnnotation(TableDef.class); if (tableDef == null) { throw new IllegalArgumentException("Expected @TableDef on class '" + fromClass.getCanonicalName() + "'"); } return createTableType(fromClass, tableDef); }  TableType create(final Class<T> fromClass);  }
@Test public void createOfMyTable_should_returnTableStructure() { final TableType tableType = factory.create(MyTable.class); final TableType expected = new TableTypeImpl("MY_TABLE", new FieldTypeImpl("ID", DataType.INTEGER, Optional.<TemplateValue>absent(), MyTable.ID)); assertThat(tableType, is(expected)); }
@Test(expected = IllegalArgumentException.class) public void createWithoutAnnotation_should_fail() { factory.create(WithoutAnnotation.class); }
@Test(expected = IllegalArgumentException.class) public void createWithoutPropertyDefs_should_fail() { factory.create(WithoutPropertyDefs.class); }