Package org.springframework.beans

Examples of org.springframework.beans.TestBean


    this.listableBeanFactory = child;
  }

  public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
    StaticListableBeanFactory lbf = new StaticListableBeanFactory();
    lbf.addBean("t1", new TestBean());
    lbf.addBean("t2", new TestBean());
    assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
  }
View Full Code Here


    assertTrue(beans.isEmpty());
  }

  public void testFindsBeansOfTypeWithStaticFactory() {
    StaticListableBeanFactory lbf = new StaticListableBeanFactory();
    TestBean t1 = new TestBean();
    TestBean t2 = new TestBean();
    DummyFactory t3 = new DummyFactory();
    DummyFactory t4 = new DummyFactory();
    t4.setSingleton(false);
    lbf.addBean("t1", t1);
    lbf.addBean("t2", t2);
View Full Code Here

  public void testFindsBeansOfTypeWithDefaultFactory() {
    Object test3 = this.listableBeanFactory.getBean("test3");
    Object test = this.listableBeanFactory.getBean("test");

    TestBean t1 = new TestBean();
    TestBean t2 = new TestBean();
    DummyFactory t3 = new DummyFactory();
    DummyFactory t4 = new DummyFactory();
    t4.setSingleton(false);
    this.listableBeanFactory.registerSingleton("t1", t1);
    this.listableBeanFactory.registerSingleton("t2", t2);
View Full Code Here

  private TestBean otherTestBean;


  public DummyFactory() {
    this.testBean = new TestBean();
    this.testBean.setName(SINGLETON_NAME);
    this.testBean.setAge(25);
  }
View Full Code Here

  public Object getObject() throws BeansException {
    if (isSingleton()) {
      return this.testBean;
    }
    else {
      TestBean prototype = new TestBean("prototype created at " + System.currentTimeMillis(), 11);
      if (this.beanFactory != null) {
        this.beanFactory.applyBeanPostProcessorsBeforeInitialization(prototype, this.beanName);
      }
      prototypeCreated = true;
      return prototype;
View Full Code Here

  public void testErrorsAreCollated() throws Exception {
    this.reader.loadBeanDefinitions(new ClassPathResource("withErrors.xml", getClass()));
    assertEquals("Incorrect number of errors collated", 4, this.problemReporter.getErrors().length);

    TestBean bean = (TestBean) this.beanFactory.getBean("validBean");
    assertNotNull(bean);
  }
View Full Code Here

   * Roderick beans inherits from rod, overriding name only.
   */
  public void testInheritance() {
    assertTrue(getBeanFactory().containsBean("rod"));
    assertTrue(getBeanFactory().containsBean("roderick"));
    TestBean rod = (TestBean) getBeanFactory().getBean("rod");
    TestBean roderick = (TestBean) getBeanFactory().getBean("roderick");
    assertTrue("not == ", rod != roderick);
    assertTrue("rod.name is Rod", rod.getName().equals("Rod"));
    assertTrue("rod.age is 31", rod.getAge() == 31);
    assertTrue("roderick.name is Roderick", roderick.getName().equals("Roderick"));
    assertTrue("roderick.age was inherited", roderick.getAge() == rod.getAge());
  }
View Full Code Here

 
  public void testFindsValidInstance() {
    try {
      Object o = getBeanFactory().getBean("rod");
      assertTrue("Rod bean is a TestBean", o instanceof TestBean);
      TestBean rod = (TestBean) o;
      assertTrue("rod.name is Rod", rod.getName().equals("Rod"));
      assertTrue("rod.age is 31", rod.getAge() == 31);
    }
    catch (Exception ex) {
      ex.printStackTrace();
      fail("Shouldn't throw exception on getting valid instance");
    }
View Full Code Here

      fail("Shouldn't throw exception on getting valid instance");
    }
  }
 
  public void testPrototypeInstancesAreIndependent() {
    TestBean tb1 = (TestBean) getBeanFactory().getBean("kathy");
    TestBean tb2 = (TestBean) getBeanFactory().getBean("kathy");
    assertTrue("ref equal DOES NOT apply", tb1 != tb2);
    assertTrue("object equal true", tb1.equals(tb2));
    tb1.setAge(1);
    tb2.setAge(2);
    assertTrue("1 age independent = 1", tb1.getAge() == 1);
    assertTrue("2 age independent = 2", tb2.getAge() == 2);
    assertTrue("object equal now false", !tb1.equals(tb2));
  }
View Full Code Here

  public void testValidEmpty() {
    try {
      Object o = getBeanFactory().getBean("validEmpty");
      assertTrue("validEmpty bean is a TestBean", o instanceof TestBean);
      TestBean ve = (TestBean) o;
      assertTrue("Valid empty has defaults", ve.getName() == null && ve.getAge() == 0 && ve.getSpouse() == null);
    }
    catch (BeansException ex) {
      ex.printStackTrace();
      fail("Shouldn't throw exception on valid empty");
    }
View Full Code Here

TOP

Related Classes of org.springframework.beans.TestBean

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.