ResolveByNameIocStrategy implements IResolveDependencyStrategy { @Override public <T> T resolve(final Object... args) throws ResolveDependencyStrategyException { try { IKey result = storage.get((String) args[0]); if (null == result) { result = new Key((String) args[0]); storage.put((String) args[0], result); } return (T) result; } catch (Exception e) { throw new ResolveDependencyStrategyException("Object resolution failed.", e); } } ResolveByNameIocStrategy(); @Override T resolve(final Object... args);  }
@Test public void checkStrategyResolution() throws Exception{ IResolveDependencyStrategy strategy = new ResolveByNameIocStrategy(); IKey key1 = strategy.resolve("unique_key"); assertNotNull(key1); IKey key2 = strategy.resolve("unique_key"); assertNotNull(key2); assertEquals(key1, key2); IKey key3 = strategy.resolve("unique_key_other"); assertNotEquals(key1, key3); }
@Test (expected = ResolveDependencyStrategyException.class) public void checkStrategyResolutionException() throws Exception { IResolveDependencyStrategy strategy = new ResolveByNameIocStrategy(); strategy.resolve(null); }