MentaContainer

Compare Revisions

Ignore whitespace Rev 19 → Rev 20

/trunk/src/test/java/org/mentacontainer/impl/MentaContainerTest.java
6,98 → 6,86
import org.mentacontainer.Container;
 
public class MentaContainerTest {
@Test
public void testSimpleGet() {
Container c = new MentaContainer();
c.ioc("myStr", String.class);
Assert.assertEquals("", c.get("myStr"));
String s1 = (String) c.get("myStr");
String s2 = (String) c.get("myStr");
Assert.assertTrue(s1 != s2);
Assert.assertTrue(s1.equals(s2));
}
@Test
public void testConstructorInit() {
Container c = new MentaContainer();
c.ioc("myStr", String.class);
c.init("myStr", "hello");
Assert.assertEquals("hello", c.get("myStr"));
String s1 = (String) c.get("myStr");
String s2 = (String) c.get("myStr");
Assert.assertTrue(s1 != s2);
Assert.assertTrue(s1.equals(s2));
c.ioc("anotherStr", String.class);
c.init("anotherStr", "hi");
String s3 = (String) c.get("anotherStr");
Assert.assertTrue(s1 != s3);
Assert.assertFalse(s1.equals(s3));
}
@Test
public void testSingleton() {
Container c = new MentaContainer();
c.ioc("myStr", String.class, true);
c.init("myStr", "hello");
Assert.assertEquals("hello", c.get("myStr"));
String s1 = (String) c.get("myStr");
String s2 = (String) c.get("myStr");
Assert.assertTrue(s1 == s2);
Assert.assertTrue(s1.equals(s2));
}
@Test(expected = RuntimeException.class)
public void testAddingComponentTwice() {
Container c = new MentaContainer();
c.ioc("myStr", String.class).ioc("myStr", String.class);
}
@Test(expected = RuntimeException.class)
public void testSettingWiringTwice() {
Container c = new MentaContainer();
c.autowire("myThread", Runnable.class);
c.autowire("myThread", Runnable.class);
}
@Test(expected = RuntimeException.class)
public void testAddingWiringNoInterface() {
Container c = new MentaContainer();
c.autowire("myThread", Thread.class);
}
 
@Test
public void testSimpleGet() {
 
Container c = new MentaContainer();
 
c.ioc("myStr", String.class);
 
Assert.assertEquals("", c.get("myStr"));
 
String s1 = (String) c.get("myStr");
 
String s2 = (String) c.get("myStr");
 
Assert.assertTrue(s1 != s2);
 
Assert.assertTrue(s1.equals(s2));
}
 
@Test
public void testConstructorInit() {
 
Container c = new MentaContainer();
 
c.ioc("myStr", String.class).addInitValue("hello");
 
Assert.assertEquals("hello", c.get("myStr"));
 
String s1 = (String) c.get("myStr");
 
String s2 = (String) c.get("myStr");
 
Assert.assertTrue(s1 != s2);
 
Assert.assertTrue(s1.equals(s2));
 
c.ioc("anotherStr", String.class).addInitValue("hi");
 
String s3 = (String) c.get("anotherStr");
 
Assert.assertTrue(s1 != s3);
 
Assert.assertFalse(s1.equals(s3));
}
 
@Test
public void testSingleton() {
 
Container c = new MentaContainer();
 
c.ioc("myStr", String.class, true).addInitValue("hello");
 
Assert.assertEquals("hello", c.get("myStr"));
 
String s1 = (String) c.get("myStr");
 
String s2 = (String) c.get("myStr");
 
Assert.assertTrue(s1 == s2);
 
Assert.assertTrue(s1.equals(s2));
}
 
@Test(expected = RuntimeException.class)
public void testAddingComponentTwice() {
 
Container c = new MentaContainer();
 
c.ioc("myStr", String.class);
c.ioc("myStr", String.class);
}
 
@Test(expected = RuntimeException.class)
public void testSettingWiringTwice() {
 
Container c = new MentaContainer();
 
c.autowire("myThread", Runnable.class);
 
c.autowire("myThread", Runnable.class);
}
}