SpringProfileActivationStrategy extends AbstractTokenizedActivationStrategy { @Override public boolean isActive(FeatureState featureState, FeatureUser user, List<Token> tokens) { ApplicationContext applicationContext = ContextClassLoaderApplicationContextHolder.get(); if (applicationContext == null) { throw new IllegalStateException("ApplicationContext could not be found, which can occur if there is no " + "bean for TogglzApplicationContextBinderApplicationListener when TogglzAutoConfiguration is not " + "being used"); } List<String> activeProfileNames = getActiveProfileNames(applicationContext); for (Token token : tokens) { if (activeProfileNames.contains(token.getValue()) != token.isNegated()) { return true; } } return false; }  @Override String getId(); @Override String getName(); @Override boolean isActive(FeatureState featureState, FeatureUser user, List<Token> tokens); @Override Parameter[] getParameters(); @Override String getTokenParameterName(); @Override TokenTransformer getTokenParameterTransformer(); static final String ID; static final String PARAM_PROFILES; }
@Test void testIsActiveThrowsWhenNoApplicationContext() { FeatureState featureState = new FeatureState(TestFeatures.FEATURE_ONE, true); ContextClassLoaderApplicationContextHolder.release(); assertThrows(IllegalStateException.class, () -> strategy.isActive(featureState, null)); }