SelectorManagerImpl extends StateGuardLifecycleSupport implements SelectorManager, EventAware { @Override @Guarded(by = STARTED) public Optional<SelectorConfiguration> findByName(final String name) { return browse().stream().filter(selector -> StringUtils.equals(name, selector.getName())).findFirst(); } @Inject  SelectorManagerImpl(final SelectorConfigurationStore store,
                             final SecuritySystem securitySystem,
                             final SelectorFactory selectorFactory); @Override @Guarded(by = STARTED) List<SelectorConfiguration> browse(); @Override @Guarded(by = STARTED) List<SelectorConfiguration> browse(final String selectorType); @Override @Guarded(by = STARTED) SelectorConfiguration read(final EntityId entityId); @Override @Guarded(by = STARTED) SelectorConfiguration readByName(final String name); @Override @Guarded(by = STARTED) Optional<SelectorConfiguration> findByName(final String name); @Override @Guarded(by = STARTED) void create(final SelectorConfiguration configuration); @Override void create(
      final String name,
      final String type,
      final String description,
      final Map<String, String> attributes); @Override @Guarded(by = STARTED) void update(final SelectorConfiguration configuration); @Override @Guarded(by = STARTED) void delete(final SelectorConfiguration configuration); @Subscribe @AllowConcurrentEvents void on(final SelectorConfigurationEvent event); @Override @Guarded(by = STARTED) boolean evaluate(final SelectorConfiguration selectorConfiguration, final VariableSource variableSource); @Override void toSql(final SelectorConfiguration selectorConfiguration, final SelectorSqlBuilder sqlBuilder); @Override @Guarded(by = STARTED) List<SelectorConfiguration> browseActive(final List<String> repositoryNames, final List<String> formats); @Override SelectorConfiguration newSelectorConfiguration(); @Override SelectorConfiguration newSelectorConfiguration(
      String name,
      String type,
      String description,
      Map<String, ?> attributes);  }
@Test public void findByNameReturnsEmptyOptional() throws Exception { Optional<SelectorConfiguration> configuration = manager.findByName("invalidSelectorName"); assertThat(configuration.isPresent(), is(false)); }
@Test public void findByNameReturnsExpectedSelector() throws Exception { SelectorConfiguration expectedSelector = getSelectorConfiguration(CselSelector.TYPE, "bar"); List<SelectorConfiguration> configs = asList(expectedSelector); selectorConfigurations.addAll(configs); Optional<SelectorConfiguration> configuration = manager.findByName(expectedSelector.getName()); assertThat(configuration.get(), is(expectedSelector)); }