MentaContainer

Compare Revisions

Ignore whitespace Rev 27 → Rev 28

/trunk/src/test/java/org/mentacontainer/impl/MentaContainerTest.java
143,14 → 143,19
public Object getSomething() {
// use the connection to get something...
// use the connection to do something...
return conn.toString(); // it cannot be null!
Assert.assertNotNull(conn); // it cannot be null!
// also test if the connection also received the myDep dependency...
Assert.assertNotNull(conn.getMyDep());
return conn.toString();
}
}
@Test
public void testAutoWiring() {
private Container getConfiguredContainer() {
Container c = new MentaContainer();
168,6 → 173,14
SomeDependency.class /* the type - it could be an interface for better decoupling */,
"aDependency" /* again this is the name of the bean/component inside the container */);
return c;
}
@Test
public void testAutoWiring() {
Container c = getConfiguredContainer();
MyDAO myDAO = (MyDAO) c.get("myDAO");
// check implementation...
192,4 → 205,40
Assert.assertNotNull(myDAO.getSomething());
}
public static class SomeAction {
private MyDAO myDAO = null;
public void setMyDAO(MyDAO myDAO) {
this.myDAO = myDAO;
}
public MyDAO getMyDAO() { return myDAO; }
}
public void testPopulate() throws Exception {
Container c = getConfiguredContainer();
SomeAction a = new SomeAction();
c.populate(a); // great... properties of SomeAction were populated by container...
// let's check if myDAO was injected...
Assert.assertNotNull(a.getMyDAO());
// also check if myDAO was corrected wired...
Connection conn = ((JdbcMyDAO) a.getMyDAO()).getConn();
Assert.assertNotNull(conn);
// check if conn was also wired...
Assert.assertNotNull(conn.getMyDep());
}
}