Rev 20 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package org.mentacontainer.impl;
import junit.framework.Assert;
import org.junit.Test;
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);
}
}