use of javax.enterprise.inject.Instance in project ART-TIME by Artezio.
the class CDIUtilsTest method testGetBean.
@Test
public void testGetBean() {
CDI cdi = createMock(CDI.class);
Instance instance = createMock(Instance.class);
ProjectsBean projectsBean = createMock(ProjectsBean.class);
PowerMock.mockStatic(CDI.class);
expect(CDI.current()).andReturn(cdi);
expect(cdi.select(ProjectsBean.class)).andReturn(instance);
expect(instance.get()).andReturn(projectsBean);
PowerMock.replayAll(CDI.class, cdi, instance);
ProjectsBean actual = CDIUtils.getBean(ProjectsBean.class);
PowerMock.verifyAll();
}
use of javax.enterprise.inject.Instance in project kernel by exoplatform.
the class WeldContainer method getComponentAdapter.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <T> ComponentAdapter<T> getComponentAdapter(final Object componentKey, Class<T> bindType, boolean autoRegistration) {
ComponentAdapter<T> result = super.getComponentAdapter(componentKey, bindType, autoRegistration);
if (weld != null && result == null) {
if (componentKey instanceof Class<?> && !((Class<?>) componentKey).isAnnotation()) {
return getAdapterOfType((Class<T>) componentKey);
} else if (componentKey instanceof String) {
Set<Bean<?>> beans = container.getBeanManager().getBeans(bindType, createNamed((String) componentKey));
if (beans != null && !beans.isEmpty()) {
return createComponentAdapter(bindType, (Instance<T>) container.instance().select(beans.iterator().next().getBeanClass()));
}
} else if (componentKey instanceof Class<?>) {
final Class<? extends Annotation> annotationType = (Class<? extends Annotation>) componentKey;
Annotation annotation = createAnnotation(annotationType);
Set<Bean<?>> beans = container.getBeanManager().getBeans(bindType, annotation);
if (beans != null && !beans.isEmpty()) {
return createComponentAdapter(bindType, (Instance<T>) container.instance().select(beans.iterator().next().getBeanClass()));
}
}
}
return result;
}
use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.
the class DataObjectBrowserViewImplTest method addPropertyTypeBrowseColumn.
@Test
public void addPropertyTypeBrowseColumn() {
FieldMetadataProvider fieldMetadataProvider = objectProperty -> {
if ("testField".equals(objectProperty.getName())) {
ImageWrapper imageWrapper = new ImageWrapper("testUri", "testDescription");
FieldMetadata fieldMetadata = new FieldMetadata(imageWrapper);
return Optional.of(fieldMetadata);
}
return Optional.empty();
};
Instance<FieldMetadataProvider> fieldMetadataProviderInstance = new MockInstanceImpl<>(fieldMetadataProvider);
view = new DataObjectBrowserViewImpl(validationPopup, fieldMetadataProviderInstance);
Column<ObjectProperty, List<ImageWrapper>> column = view.createPropertyTypeBrowseColumn();
ObjectProperty matchingObjectProperty = new ObjectPropertyImpl("testField", "className", false);
List<ImageWrapper> imageWrapperList = column.getValue(matchingObjectProperty);
assertEquals(1, imageWrapperList.size());
ObjectProperty nonMatchingObjectProperty = new ObjectPropertyImpl("nonMatchingTestField", "className", false);
imageWrapperList = column.getValue(nonMatchingObjectProperty);
assertEquals(0, imageWrapperList.size());
}
use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.
the class VerifierWebWorkerRegistryTest method wrongId.
@Test
public void wrongId() throws Exception {
final Instance verifierWebWorkerProviders = mock(Instance.class);
final ArrayList<Object> webWorkerProviders = new ArrayList<>();
webWorkerProviders.add(getWebWorkerProvider("somethingElse"));
doReturn(webWorkerProviders.iterator()).when(verifierWebWorkerProviders).iterator();
assertFalse(new VerifierWebWorkerRegistry(verifierWebWorkerProviders).get("something").isPresent());
}
use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.
the class VerifierWebWorkerRegistryTest method correctId.
@Test
public void correctId() throws Exception {
final Instance verifierWebWorkerProviders = mock(Instance.class);
final ArrayList<Object> webWorkerProviders = new ArrayList<>();
webWorkerProviders.add(getWebWorkerProvider("something"));
doReturn(webWorkerProviders.iterator()).when(verifierWebWorkerProviders).iterator();
assertTrue(new VerifierWebWorkerRegistry(verifierWebWorkerProviders).get("something").isPresent());
}
Aggregations