SimpleMapFactory implements MapFactory { @Override public void initialise(final Schema schema, final MapStoreProperties properties) { final String mapClassName = properties.get(MAP_CLASS, MAP_CLASS_DEFAULT); try { mapClass = Class.forName(SimpleClassNameIdResolver.getClassName(mapClassName)).asSubclass(Map.class); } catch (final ClassNotFoundException | ClassCastException e) { throw new IllegalArgumentException("Map Class is invalid: " + mapClassName, e); } } SimpleMapFactory(); protected  SimpleMapFactory(final ElementCloner cloner); @Override void initialise(final Schema schema, final MapStoreProperties properties); @Override Map<K, V> getMap(final String mapName, final Class<K> keyClass, final Class<V> valueClass); @Override MultiMap<K, V> getMultiMap(final String mapName, final Class<K> keyClass, final Class<V> valueClass); @Override void clear(); @Override Element cloneElement(final Element element, final Schema schema); static final String MAP_CLASS; static final String MAP_CLASS_DEFAULT; }
@Test public void shouldThrowExceptionIfMapClassIsInvalid() throws StoreException { final Class mapClass = String.class; final Schema schema = mock(Schema.class); final MapStoreProperties properties = mock(MapStoreProperties.class); final SimpleMapFactory factory = new SimpleMapFactory(); given(properties.get(SimpleMapFactory.MAP_CLASS, SimpleMapFactory.MAP_CLASS_DEFAULT)).willReturn(mapClass.getName()); try { factory.initialise(schema, properties); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); } }