Exemplo n.º 1
0
  @Test
  public void testOne() {
    PetiteContainer pc = new PetiteContainer();
    pc.registerBean(DefaultBizImpl.class);
    assertEquals(1, pc.getTotalBeans());

    Object bizI = pc.getBean("biz");
    assertTrue(bizI instanceof Biz);
    assertTrue(bizI instanceof DefaultBizImpl);

    pc = new PetiteContainer();
    pc.registerBean(DefaultBizImpl.class);
    pc.registerBean(DefaultBiz.class); // override!
    assertEquals(1, pc.getTotalBeans());
    pc.registerBean(Foo.class);
    pc.registerPropertyInjectionPoint("biz", "foo");
    pc.registerInitMethods("biz", "init", "init2");

    assertEquals(2, pc.getTotalBeans());
    bizI = pc.getBean("biz");
    assertTrue(bizI instanceof Biz);
    assertFalse(bizI instanceof DefaultBizImpl);
    assertTrue(bizI instanceof DefaultBiz);

    assertNotNull(((DefaultBiz) bizI).getFoo());
    assertEquals(2, ((DefaultBiz) bizI).initCount);
  }
Exemplo n.º 2
0
  @Test
  public void testTwo() {
    PetiteContainer pc = new PetiteContainer();
    pc.registerBean(DefaultBizImpl.class);
    assertEquals(1, pc.getTotalBeans());

    Object bizI = pc.getBean("biz");
    assertTrue(bizI instanceof Biz);
    assertFalse(bizI instanceof DefaultBiz);
    assertTrue(bizI instanceof DefaultBizImpl);

    // pc = new PetiteContainer();			// same container!!!
    pc.registerBean(DefaultBiz.class); // override! instance will be removed from the scope
    assertEquals(1, pc.getTotalBeans());
    bizI = pc.getBean("biz");
    assertTrue(bizI instanceof Biz);
    assertFalse(bizI instanceof DefaultBizImpl);
    assertTrue(bizI instanceof DefaultBiz);
  }