BlacklistedCommandsScanner { public Set<SystemCommand> scanForBlacklistedCommands(final Set<Bean<?>> cdiBeans, final BeanManager beanManager) { return cdiBeans.stream() .filter(this::isInstanceOfBlacklistedCommands) .map(bean -> asSystemCommandsList(bean, beanManager)) .flatMap(Collection::stream) .collect(toSet()); } BlacklistedCommandsScanner(final CdiInstanceResolver cdiInstanceResolver); Set<SystemCommand> scanForBlacklistedCommands(final Set<Bean<?>> cdiBeans, final BeanManager beanManager);  }
@SuppressWarnings("unchecked") @Test public void shouldGetTheUniqueListOfBlackListedSystemCommandsByInstantiatingBlacklistedCommandsObjects() throws Exception { final BeanManager beanManager = mock(BeanManager.class); final Bean bean_1 = mock(Bean.class); final Bean bean_2 = mock(Bean.class); final Bean blacklistedCommandsBean_1 = mock(Bean.class); final Bean blacklistedCommandsBean_2 = mock(Bean.class); final Set<Bean<?>> cdiBeans = newHashSet(bean_1, blacklistedCommandsBean_1, bean_2, blacklistedCommandsBean_2); when(bean_1.getBeanClass()).thenReturn(Object.class); when(bean_2.getBeanClass()).thenReturn(Object.class); when(blacklistedCommandsBean_1.getBeanClass()).thenReturn(BlacklistedCommands_1.class); when(blacklistedCommandsBean_2.getBeanClass()).thenReturn(BlacklistedCommands_2.class); when(cdiInstanceResolver.getInstanceOf(BlacklistedCommands_1.class, beanManager)).thenReturn(new BlacklistedCommands_1()); when(cdiInstanceResolver.getInstanceOf(BlacklistedCommands_2.class, beanManager)).thenReturn(new BlacklistedCommands_2()); final Set<SystemCommand> blacklistedCommands = blacklistedCommandsScanner.scanForBlacklistedCommands(cdiBeans, beanManager); assertThat(blacklistedCommands.size(), is(3)); assertThat(blacklistedCommands, hasItem(new SystemCommand_1())); assertThat(blacklistedCommands, hasItem(new SystemCommand_2())); assertThat(blacklistedCommands, hasItem(new SystemCommand_3())); }