@SuppressWarnings("unchecked")
@Test
public void shouldResolveTheInstanceOfACdiBean() throws Exception {

    final BeanManager beanManager = mock(BeanManager.class);
    final Bean bean = mock(Bean.class);
    final Set<Bean<?>> beans = newHashSet(bean);
    final CreationalContext<?> context = mock(CreationalContext.class);
    final DummyCdiBean systemCommandScanner = new DummyCdiBean();
    final Class<DummyCdiBean> beanClass = DummyCdiBean.class;
    when(beanManager.getBeans(beanClass)).thenReturn(beans);
    when(beanManager.resolve(beans)).thenReturn(bean);
    when(beanManager.createCreationalContext(bean)).thenReturn(context);
    when(beanManager.getReference(
            bean,
            beanClass,
            context)).thenReturn(systemCommandScanner);
    assertThat(cdiInstanceResolver.getInstanceOf(beanClass, beanManager), is(systemCommandScanner));
}