MentaContainer

Compare Revisions

Ignore whitespace Rev 58 → Rev 64

/trunk/src/test/java/org/mentacontainer/impl/MentaContainerTest.java
3,6 → 3,8
import junit.framework.Assert;
 
import org.junit.Test;
import org.mentacontainer.Clearable;
import org.mentacontainer.Component;
import org.mentacontainer.Container;
import org.mentacontainer.Scope;
 
282,6 → 284,7
public MyDAO getMyDAO() { return myDAO; }
}
@Test
public void testPopulate() {
Container c = getConfiguredContainer();
303,6 → 306,74
// check if conn was also wired...
Assert.assertNotNull(conn.getMyDep());
}
private static class SomeObject {
private boolean cleared = false;
public void clear() { this.cleared = true; }
public boolean isCleared() { return cleared; }
}
private static class SomeComponent implements Component, Clearable<SomeObject> {
public <T> T getInstance() {
return (T) new SomeObject();
}
public void onCleared(SomeObject obj) {
obj.clear();
}
}
@Test
public void testClearable() {
Container c = new MentaContainer();
c.ioc("o", new SomeComponent(), Scope.SINGLETON);
SomeObject o = c.get("o");
c.clear(Scope.SINGLETON);
Assert.assertEquals(true, o.isCleared());
c.ioc("o", new SomeComponent(), Scope.THREAD);
o = c.get("o");
c.clear(Scope.SINGLETON);
Assert.assertEquals(false, o.isCleared());
c.clear(Scope.THREAD);
Assert.assertEquals(true, o.isCleared());
c.ioc("o", new SomeComponent(), Scope.NONE);
o = c.get("o");
o = c.clear("o");
Assert.assertNull(o);
c.ioc("o", new SomeComponent(), Scope.THREAD);
o = c.clear("o");
Assert.assertNull(o);
o = c.get("o");
o = c.clear("o");
Assert.assertEquals(true, o.isCleared());
}
}