Keys { public static IKey getOrAdd(final String keyName) throws ResolutionException { return (IKey) IOC.resolve(IOC.getKeyForKeyStorage(), keyName); } private  Keys(); static IKey getOrAdd(final String keyName);  }
@Test public void checkGetOrAdd() throws Exception { IStrategyContainer strategyContainer = mock(IStrategyContainer.class); IResolveDependencyStrategy strategy = mock(IResolveDependencyStrategy.class); IKey key = mock(IKey.class); ScopeProvider.subscribeOnCreationNewScope( scope -> { try { scope.setValue(IOC.getIocKey(), strategyContainer); } catch (Exception e) { throw new Error(e); } } ); Object scopeId = ScopeProvider.createScope(null); IScope scope = ScopeProvider.getScope(scopeId); ScopeProvider.setCurrentScope(scope); when(strategyContainer.resolve(any())).thenReturn(strategy); when(strategy.resolve("test")).thenReturn(key); IKey result = Keys.getOrAdd("test"); assertNotNull(result); assertEquals(result, key); }