package org.nutz.ioc; import static org.junit.Assert.*; import org.junit.Test; import org.nutz.ioc.impl.NutIoc; import org.nutz.ioc.loader.annotation.AnnotationIocLoader; import org.nutz.ioc.meta.issue348.DogMaster; import org.nutz.ioc.meta.issue399.Issue399Service; public class SimpleIocTest { @Test(expected=IocException.class) public void test_error_bean() { Ioc ioc = new NutIoc(new AnnotationIocLoader(DogMaster.class.getPackage().getName())); try { ioc.get(DogMaster.class); fail("Never Success"); } catch (IocException e) {} ioc.get(DogMaster.class); ioc.depose(); } @Test public void test_no_singleton_depose() { Issue399Service.CreateCount = 0; Issue399Service.DeposeCount = 0; Ioc ioc = new NutIoc(new AnnotationIocLoader(Issue399Service.class.getPackage().getName())); for (int i = 0; i < 100; i++) { ioc.get(Issue399Service.class); } assertEquals(1, ioc.getNamesByType(Issue399Service.class).length); ioc.getByType(Issue399Service.class); ioc.depose(); System.gc(); assertEquals(101, Issue399Service.CreateCount); assertEquals(0, Issue399Service.DeposeCount); } @Test(expected=IocException.class) public void test_issue_1232() { Ioc ioc = null; try { ioc = new NutIoc(new AnnotationIocLoader("org.nutz.ioc.meta.issue1232")); assertEquals(3, ioc.getNames().length); ioc.get(null, "a"); } catch (IocException e) { e.printStackTrace(); throw e; } finally { if (ioc != null) ioc.depose(); } } }