This is the heart of Morphia and takes care of mapping from/to POJOs/DBObjects
This class is thread-safe and keeps various "cached" data which should speed up processing.
4344454647484950515253
@Test public void shouldNotValidateIfEntityHasNoIdField() { // given ArrayList<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>(); // when boolean validationApplied = EntityTypeAndIdValueValidator.getInstance().apply(new Mapper(), EntityWithNoId.class, "some non-null value", validationFailures); // then assertThat(validationApplied, is(false));
1112131415161718192021
public class MappedFieldTypeValidatorTest { @Test public void shouldAllowArraysOfNumbers() { // given MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper()); MappedField mappedField = mappedClass.getMappedField("arrayOfInts"); // expect assertThat(MappedFieldTypeValidator.isArrayOfNumbers(mappedField), is(true)); }
2122232425262728293031
} @Test public void shouldRejectArraysOfStrings() { // given MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper()); MappedField mappedField = mappedClass.getMappedField("arrayOfStrings"); // expect assertThat(MappedFieldTypeValidator.isArrayOfNumbers(mappedField), is(false)); }
3132333435363738394041
} @Test public void shouldAllowAListThatDoesNotContainNumbers() { // given MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper()); MappedField mappedField = mappedClass.getMappedField("listOfIntegers"); // expect assertThat(MappedFieldTypeValidator.isIterableOfNumbers(mappedField), is(true)); }
4142434445464748495051
} @Test public void shouldRejectAListThatDoesNotContainNumbers() { // given MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper()); MappedField mappedField = mappedClass.getMappedField("listOfStrings"); // expect assertThat(MappedFieldTypeValidator.isIterableOfNumbers(mappedField), is(false)); }