Search in sources :

Example 1 with ServiceLocatorFactoryBean

use of cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean in project today-infrastructure by TAKETODAY.

the class ServiceLocatorFactoryBeanTests method testWhenServiceLocatorExceptionClassIsNotAnExceptionSubclass.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testWhenServiceLocatorExceptionClassIsNotAnExceptionSubclass() throws Exception {
    ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
    assertThatIllegalArgumentException().isThrownBy(() -> factory.setServiceLocatorExceptionClass((Class) getClass()));
// should throw, bad (non-Exception-type) serviceLocatorException class supplied
}
Also used : ServiceLocatorFactoryBean(cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceLocatorFactoryBean

use of cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean in project today-infrastructure by TAKETODAY.

the class ServiceLocatorFactoryBeanTests method testWhenServiceLocatorExceptionClassToExceptionTypeWithOnlyNoArgCtor.

@Test
public void testWhenServiceLocatorExceptionClassToExceptionTypeWithOnlyNoArgCtor() throws Exception {
    ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
    assertThatIllegalArgumentException().isThrownBy(() -> factory.setServiceLocatorExceptionClass(ExceptionClassWithOnlyZeroArgCtor.class));
// should throw, bad (invalid-Exception-type) serviceLocatorException class supplied
}
Also used : ServiceLocatorFactoryBean(cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceLocatorFactoryBean

use of cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean in project today-infrastructure by TAKETODAY.

the class ServiceLocatorFactoryBeanTests method testWhenServiceLocatorMethodCalledWithTooManyParameters.

@Test
public void testWhenServiceLocatorMethodCalledWithTooManyParameters() throws Exception {
    ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
    factory.setServiceLocatorInterface(ServiceLocatorInterfaceWithExtraNonCompliantMethod.class);
    factory.afterPropertiesSet();
    ServiceLocatorInterfaceWithExtraNonCompliantMethod locator = (ServiceLocatorInterfaceWithExtraNonCompliantMethod) factory.getObject();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> locator.getTestService("not", "allowed"));
}
Also used : ServiceLocatorFactoryBean(cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceLocatorFactoryBean

use of cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean in project today-framework by TAKETODAY.

the class ServiceLocatorFactoryBeanTests method testRequiresListableBeanFactoryAndChokesOnAnythingElse.

@Test
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
    BeanFactory beanFactory = mock(BeanFactory.class);
    try {
        ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
        factory.setBeanFactory(beanFactory);
    } catch (FatalBeanException ex) {
    // expected
    }
}
Also used : ServiceLocatorFactoryBean(cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean) BeanFactory(cn.taketoday.beans.factory.BeanFactory) FatalBeanException(cn.taketoday.beans.FatalBeanException) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceLocatorFactoryBean

use of cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean in project today-framework by TAKETODAY.

the class ServiceLocatorFactoryBeanTests method testWhenServiceLocatorInterfaceIsNotAnInterfaceType.

@Test
public void testWhenServiceLocatorInterfaceIsNotAnInterfaceType() throws Exception {
    ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
    factory.setServiceLocatorInterface(getClass());
    assertThatIllegalArgumentException().isThrownBy(factory::afterPropertiesSet);
// should throw, bad (non-interface-type) serviceLocator interface supplied
}
Also used : ServiceLocatorFactoryBean(cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceLocatorFactoryBean (cn.taketoday.beans.factory.config.ServiceLocatorFactoryBean)10 Test (org.junit.jupiter.api.Test)10 FatalBeanException (cn.taketoday.beans.FatalBeanException)2 BeanFactory (cn.taketoday.beans.factory.BeanFactory)2