3,7 → 3,7 |
import junit.framework.Assert; |
|
import org.junit.Test; |
import org.mentacontainer.Interceptable; |
import org.mentacontainer.Interceptor; |
import org.mentacontainer.Factory; |
import org.mentacontainer.Container; |
import org.mentacontainer.Scope; |
400,14 → 400,19 |
|
private static class SomeObject { |
|
private boolean cleared = false; |
private boolean destroyed = false; |
private boolean created = false; |
|
public void clear() { this.cleared = true; } |
public void destroyed() { this.destroyed = true; } |
|
public boolean isCleared() { return cleared; } |
public boolean isDestroyed() { return destroyed; } |
|
public void created() { this.created = true; } |
|
public boolean isCreated() { return created; } |
} |
|
private static class SomeFactory implements Factory, Interceptable<SomeObject> { |
private static class SomeFactory implements Factory, Interceptor<SomeObject> { |
|
@Override |
public <T> T getInstance() { |
422,20 → 427,20 |
} |
|
@Override |
public void onCleared(SomeObject obj) { |
public void onDestroyed(SomeObject obj) { |
|
obj.clear(); |
obj.destroyed(); |
} |
|
@Override |
public void onCreated(SomeObject obj) { |
|
|
obj.created(); |
} |
} |
|
@Test |
public void testClearable() { |
public void testInterceptor() { |
|
Container c = new MentaContainer(); |
|
443,26 → 448,32 |
|
SomeObject o = c.get("o"); |
|
Assert.assertTrue(o.isCreated()); |
|
c.clear(Scope.SINGLETON); |
|
Assert.assertEquals(true, o.isCleared()); |
Assert.assertEquals(true, o.isDestroyed()); |
|
c.ioc("o", new SomeFactory(), Scope.THREAD); |
|
o = c.get("o"); |
|
Assert.assertTrue(o.isCreated()); |
|
c.clear(Scope.SINGLETON); |
|
Assert.assertEquals(false, o.isCleared()); |
Assert.assertEquals(false, o.isDestroyed()); |
|
c.clear(Scope.THREAD); |
|
Assert.assertEquals(true, o.isCleared()); |
Assert.assertEquals(true, o.isDestroyed()); |
|
c.ioc("o", new SomeFactory(), Scope.NONE); |
|
o = c.get("o"); |
|
Assert.assertTrue(o.isCreated()); |
|
o = c.clear("o"); |
|
Assert.assertNull(o); |
475,9 → 486,11 |
|
o = c.get("o"); |
|
Assert.assertTrue(o.isCreated()); |
|
o = c.clear("o"); |
|
Assert.assertEquals(true, o.isCleared()); |
Assert.assertEquals(true, o.isDestroyed()); |
} |
|
} |