EntityMappingExtractorImpl implements EntityMappingExtractor { public Fields extractFields(Class<?> type) { if (type == null) { throw new NullPointerException("Cannot extract entity mapping, type is null!"); } final Entity entityAnnotation = type.getAnnotation(Entity.class); if (entityAnnotation == null) { throw new MappingException(type, "not annotated with @Entity, cannot extract property mapping"); } final Set<MappedField> fields = new HashSet<MappedField>(); final FieldMappingExtractorImpl fieldMappingExtractor = new FieldMappingExtractorImpl(); for (final Field field : type.getDeclaredFields()) { try { final MappedField mappedField = fieldMappingExtractor.extract(field); if (mappedField != null) { fields.add(mappedField); } } catch (final MappingException e) { e.setMappedType(type); throw e; } } return new ImmutableFields(fields); }  @Override EntityMapping extract(Class<?> type); Fields extractFields(Class<?> type);  }
@Test public void testSimpleTypeWithBasicProperties() { final Fields extract = extractor.extractFields(EntityWithPrimitiveProperties.class); assertThat(extract.isEmpty(), is(false)); assertThat(extract.getSize(), is(EntityWithPrimitiveProperties.NUMBER_OF_FIELDS)); }
@Test public void testSimpleTypeWithoutProperties() { final Fields extract = extractor.extractFields(EntityWithoutProperties.class); assertThat("Non-entites should not generate any mapped fields.", extract.isEmpty(), is(true)); }