FieldScanner { public <T> List<FieldType> scan(final Class<T> fromClass) { final List<FieldType> result = Lists.newArrayList( transform( filter(toDeclaredFields(fromClass), and(IS_FIELD_DEF, IS_CONSTANT)), MAP_FIELD_TO_FIELD_TYPE) ); checkResultHasFields(fromClass, result); return result; }  List<FieldType> scan(final Class<T> fromClass);  }
@Test(expected = IllegalArgumentException.class) public void scanningAClassWithoutAPropertyDef_should_fail() { scanner.scan(WithoutPropertyDefs.class); }
@Test(expected = IllegalArgumentException.class) public void scanningWithNonStatic_should_fail() { scanner.scan(WithNonStatic.class); }
@Test(expected = IllegalArgumentException.class) public void scanningWithNonFinal_should_fail() { scanner.scan(WithNonFinal.class); }
@Test public void scanningAClassWithPropertyDefs_should_extractThosePropertyDefs() { final Collection<FieldType> expected = Lists.<FieldType>newArrayList( new FieldTypeImpl("ID", DataType.INTEGER, Optional.<TemplateValue>absent(), WithPropertyDefs.ID), new FieldTypeImpl("NAME", DataType.VARCHAR, Optional.<TemplateValue>absent(), WithPropertyDefs.NAME) ); assertThat(scanner.scan(WithPropertyDefs.class), is(expected)); }
@Test public void scanningWithExplicitName_should_haveThatName() { final Collection<FieldType> expected = Lists.<FieldType>newArrayList( new FieldTypeImpl(NAME, DataType.INTEGER, Optional.<TemplateValue>absent(), WithExplicitName.ID) ); assertThat(scanner.scan(WithExplicitName.class), is(expected)); }
@Test public void scanningWithExplicitTemplate_should_haveTheTemplate() { assertThat( scanner.scan(WithExplicitTemplate.class), contains( (FieldType) new FieldTypeImpl( "NAME", DataType.VARCHAR, Optional.<TemplateValue>of(new StringTemplateValue("some template")), WithExplicitTemplate.NAME) ) ); }