NullFieldStrategySourceImpl implements NullFieldStrategySource { public NullFieldStrategy get(String name) { NullFieldStrategy result = configuration.get(name); if (result != null) return result; throw new UnknownValueException(String.format("Unrecognized name '%s' locating a null field strategy.", name), new AvailableValues("Configured null field strategies", configuration)); } NullFieldStrategySourceImpl(Map<String, NullFieldStrategy> configuration); NullFieldStrategy get(String name);  }
@Test public void success() { NullFieldStrategy strategy = mockNullFieldStrategy(); replay(); Map<String, NullFieldStrategy> configuration = Collections.singletonMap("strat", strategy); NullFieldStrategySource source = new NullFieldStrategySourceImpl(configuration); assertSame(source.get("strat"), strategy); verify(); }
@Test public void failure() { Map<String, NullFieldStrategy> configuration = CollectionFactory.newCaseInsensitiveMap(); configuration.put("fred", mockNullFieldStrategy()); configuration.put("barney", mockNullFieldStrategy()); replay(); NullFieldStrategySource source = new NullFieldStrategySourceImpl(configuration); try { source.get("wilma"); unreachable(); } catch (UnknownValueException ex) { assertEquals(ex.getMessage(), "Unrecognized name 'wilma' locating a null field strategy."); assertListsEquals(ex.getAvailableValues().getValues(), "barney", "fred"); } }