use of com.vaadin.flow.spring.SpringInstantiator in project flow by vaadin.
the class SpringInstantiatorTest method getOrCreateBean_multipleBeansGivenCannotInstantiate_throwsExceptionWithHint.
@Test
public void getOrCreateBean_multipleBeansGivenCannotInstantiate_throwsExceptionWithHint() {
ApplicationContext context = Mockito.mock(ApplicationContext.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(context.getBeanNamesForType(Number.class)).thenReturn(new String[] { "one", "two" });
Mockito.when(context.getAutowireCapableBeanFactory().createBean(Number.class)).thenThrow(new BeanInstantiationException(Number.class, "This is an abstract class"));
SpringInstantiator instantiator = new SpringInstantiator(null, context);
try {
instantiator.getOrCreate(Number.class);
} catch (BeanInstantiationException e) {
Assert.assertNotNull(e.getMessage());
Assert.assertTrue(e.getMessage().contains("[HINT]"));
return;
}
Assert.fail();
}
use of com.vaadin.flow.spring.SpringInstantiator in project flow by vaadin.
the class SpringInstantiatorTest method getOrCreateBean_oneBeanGiven_noException.
@Test
public void getOrCreateBean_oneBeanGiven_noException() {
ApplicationContext context = Mockito.mock(ApplicationContext.class);
Mockito.when(context.getBeanNamesForType(Number.class)).thenReturn(new String[] { "one" });
Mockito.when(context.getBean(Number.class)).thenReturn(0);
SpringInstantiator instantiator = new SpringInstantiator(null, context);
Number bean = instantiator.getOrCreate(Number.class);
Assert.assertEquals(0, bean);
}
use of com.vaadin.flow.spring.SpringInstantiator in project flow by vaadin.
the class SpringInstantiatorTest method getOrCreateBean_multipleBeansGivenButCanInstantiate_noException.
@Test
public void getOrCreateBean_multipleBeansGivenButCanInstantiate_noException() {
ApplicationContext context = Mockito.mock(ApplicationContext.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(context.getBeanNamesForType(String.class)).thenReturn(new String[] { "one", "two" });
Mockito.when(context.getAutowireCapableBeanFactory().createBean(String.class)).thenReturn("string");
SpringInstantiator instantiator = new SpringInstantiator(null, context);
String bean = instantiator.getOrCreate(String.class);
Assert.assertEquals("string", bean);
}
use of com.vaadin.flow.spring.SpringInstantiator in project flow by vaadin.
the class SpringInstantiatorTest method getOrCreateBean_noBeansGivenCannotInstantiate_throwsExceptionWithoutHint.
@Test
public void getOrCreateBean_noBeansGivenCannotInstantiate_throwsExceptionWithoutHint() {
ApplicationContext context = Mockito.mock(ApplicationContext.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(context.getBeanNamesForType(Number.class)).thenReturn(new String[] {});
Mockito.when(context.getAutowireCapableBeanFactory().createBean(Number.class)).thenThrow(new BeanInstantiationException(Number.class, "This is an abstract class"));
SpringInstantiator instantiator = new SpringInstantiator(null, context);
try {
instantiator.getOrCreate(Number.class);
} catch (BeanInstantiationException e) {
Assert.assertNotNull(e.getMessage());
Assert.assertFalse(e.getMessage().contains("[HINT]"));
return;
}
Assert.fail();
}
Aggregations