CurrencyMapper extends Mapper<Currency> { @Nullable @Override public Currency fromDb(@Nullable final Object dbValue) throws MapperException { if (dbValue == null) { return null; } if (dbValue instanceof String) { try { return Currency.getInstance((String) dbValue); } catch (final IllegalArgumentException ignored) { throw new MapperException("Invalid currency"); } } throw new MapperException("String value expected, " + "got a value of type: " + dbValue.getClass().getCanonicalName()); }  @Nullable @Override Currency fromDb(@Nullable final Object dbValue); @Nullable @Override Object toDb(@Nullable final Currency value);  }
@Test(expected = MapperException.class) public void testUnknownCurrency() throws SchemaException, MapperException { LOG.info("testUnknownCurrency"); final MapperRegistry registry = new MapperRegistry(); registry.register(new CurrencyMapper()); final CurrencyMapper mapper = registry.getMapper(CurrencyMapper.class); final String n = "NON_EXISTENT_CURRENCY"; mapper.fromDb(n); }