Package org.springframework.test

Examples of org.springframework.test.AssertThrows


    PropertyEditor urlEditor = new URLEditor();
    assertEquals("", urlEditor.getAsText());
  }

  public void testCtorWithNullResourceEditor() throws Exception {
    new AssertThrows(IllegalArgumentException.class) {
      public void test() throws Exception {
        new URLEditor(null);
      }
    }.runTest();
  }
View Full Code Here


    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestService2Locator.class));
    ctx.registerSingleton("factory3", ServiceLocatorFactoryBean.class, mpv);
    ctx.refresh();

    final TestServiceLocator factory = (TestServiceLocator) ctx.getBean("factory");
    new AssertThrows(NoSuchBeanDefinitionException.class, "Must fail on more than one matching type") {
      public void test() throws Exception {
        factory.getTestService();
      }
    }.runTest();

    final TestServiceLocator2 factory2 = (TestServiceLocator2) ctx.getBean("factory2");
    new AssertThrows(NoSuchBeanDefinitionException.class, "Must fail on more than one matching type") {
      public void test() throws Exception {
        factory2.getTestService(null);
      }
    }.runTest();
    final TestService2Locator factory3 = (TestService2Locator) ctx.getBean("factory3");
    new AssertThrows(NoSuchBeanDefinitionException.class, "Must fail on no matching types") {
      public void test() throws Exception {
        factory3.getTestService();
      }
    }.runTest();
  }
View Full Code Here

    }
    catch (CustomServiceLocatorException2 expected) {
      assertTrue(expected.getCause() instanceof NoSuchBeanDefinitionException);
    }
    final TestService2Locator factory3 = (TestService2Locator) ctx.getBean("factory3");
    new AssertThrows(CustomServiceLocatorException3.class, "Must fail on no matching types") {
      public void test() throws Exception {
        factory3.getTestService();
      }
    }.runTest();
  }
View Full Code Here

    final TestServiceLocator2 factory = (TestServiceLocator2) ctx.getBean("factory");
    TestService testBean = factory.getTestService(null);
    // now test with explicit id
    testBean = factory.getTestService("testService");
    // now verify failure on bad id
    new AssertThrows(NoSuchBeanDefinitionException.class, "Illegal operation allowed") {
      public void test() throws Exception {
        factory.getTestService("bogusTestService");
      }
    }.runTest();
  }
View Full Code Here

    assertFalse(testBean3 instanceof ExtendedTestService);
    assertTrue(testBean4 instanceof ExtendedTestService);
  }

  public void testNoServiceLocatorInterfaceSupplied() throws Exception {
    new AssertThrows(IllegalArgumentException.class, "No serviceLocator interface supplied") {
      public void test() throws Exception {
        new ServiceLocatorFactoryBean().afterPropertiesSet();
      }
    }.runTest();
  }
View Full Code Here

      }
    }.runTest();
  }

  public void testWhenServiceLocatorInterfaceIsNotAnInterfaceType() throws Exception {
    new AssertThrows(IllegalArgumentException.class, "Bad (non-interface-type) serviceLocator interface supplied") {
      public void test() throws Exception {
        ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
        factory.setServiceLocatorInterface(getClass());
        factory.afterPropertiesSet();
      }
View Full Code Here

      }
    }.runTest();
  }

  public void testWhenServiceLocatorExceptionClassToExceptionTypeWithOnlyNoArgCtor() throws Exception {
    new AssertThrows(IllegalArgumentException.class, "Bad (invalid-Exception-type) serviceLocatorException class supplied") {
      public void test() throws Exception {
        ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
        factory.setServiceLocatorExceptionClass(ExceptionClassWithOnlyZeroArgCtor.class);
      }
    }.runTest();
View Full Code Here

      }
    }.runTest();
  }

  public void testWhenServiceLocatorExceptionClassIsNotAnExceptionSubclass() throws Exception {
    new AssertThrows(IllegalArgumentException.class, "Bad (non-Exception-type) serviceLocatorException class supplied") {
      public void test() throws Exception {
        ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
        factory.setServiceLocatorExceptionClass(getClass());
      }
    }.runTest();
View Full Code Here

  public void testWhenServiceLocatorMethodCalledWithTooManyParameters() throws Exception {
    ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
    factory.setServiceLocatorInterface(ServiceLocatorInterfaceWithExtraNonCompliantMethod.class);
    factory.afterPropertiesSet();
    final ServiceLocatorInterfaceWithExtraNonCompliantMethod locator = (ServiceLocatorInterfaceWithExtraNonCompliantMethod) factory.getObject();
    new AssertThrows(UnsupportedOperationException.class, "Bad method (too many args, doesn't obey class contract)") {
      public void test() throws Exception {
        locator.getTestService("not", "allowed");
      }
    }.runTest();
  }
View Full Code Here

  public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
    MockControl mockBeanFactory = MockControl.createControl(BeanFactory.class);
    final BeanFactory beanFactory = (BeanFactory) mockBeanFactory.getMock();
    mockBeanFactory.replay();

    new AssertThrows(FatalBeanException.class) {
      public void test() throws Exception {
        ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
        factory.setBeanFactory(beanFactory);
      }
    }.runTest();
View Full Code Here

TOP

Related Classes of org.springframework.test.AssertThrows

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.