ResolveByTypeStrategy implements IResolveDependencyStrategy, IAdditionDependencyStrategy { @Override public <T> T resolve(final Object... args) throws ResolveDependencyStrategyException { try { IResolveDependencyStrategy strategy = cacheStrategiesMap.get(args[0].getClass()); if (strategy == null) { for (Map.Entry<Class, IResolveDependencyStrategy> entry : resolveStrategies.entrySet()) { if (entry.getKey().isInstance(args[0])) { strategy = entry.getValue(); cacheStrategiesMap.put(args[0].getClass(), strategy); break; } } } Object result = strategy.resolve(args[0]); return (T) result; } catch (Exception e) { throw new ResolveDependencyStrategyException("Object resolution failed.", e); } } ResolveByTypeStrategy(); @Override void register(final Object key, final IResolveDependencyStrategy strategy); @Override void remove(final Object key); @Override T resolve(final Object... args);  }
@Test (expected = ResolveDependencyStrategyException.class) public void checkStrategyResolutionException() throws Exception { IResolveDependencyStrategy strategy = new ResolveByTypeStrategy(); strategy.resolve(null); }