IntegerToEnumTypeMapper implements TypeMapper<Integer, T> { @Override public T toJavaType(Column column, Class<?> entityType, Integer value) { if (value == null) { return null; } else { if (cachedConstants.get() == null) { synchronized (cachedConstants) { if (cachedConstants.get() == null) { cachedConstants.set(constants(column, entityType)); } } } return cachedConstants.get()[value]; } } IntegerToEnumTypeMapper(); @Override String getLabel(); @Override boolean isToolApplicable(); @Override Type getJavaType(Column column); @Override TypeMapper.Category getJavaTypeCategory(Column column); @Override T toJavaType(Column column, Class<?> entityType, Integer value); @Override Integer toDatabaseType(T constant); @Inject public Injector injector; }
@Test void toJavaType() { final User.Name actual = instance.toJavaType(column, User.class, 0); assertEquals(User.Name.ZERO, actual); assertEquals(User.Name.ZERO, instance.toJavaType(column, User.class, 0)); }
@Test void toJavaTypeNull() { assertNull(instance.toJavaType(column, User.class, null)); }
@Test void toJavaTypeOutOfBounds() { assertThrows(ArrayIndexOutOfBoundsException.class, () -> instance.toJavaType(column, User.class, 43)); }