MentaContainer

Compare Revisions

Ignore whitespace Rev 20 → Rev 24

/trunk/src/test/java/org/mentacontainer/impl/MentaDependencyTest.java
New file
0,0 → 1,50
package org.mentacontainer.impl;
 
import java.lang.reflect.Method;
 
import junit.framework.Assert;
 
import org.junit.Test;
import org.mentacontainer.Dependency;
 
public class MentaDependencyTest {
private static class User {
private String username;
public User() { }
public User(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
@Test
public void testDependency() {
Dependency d = new MentaDependency("username", String.class, "theUsername");
Assert.assertEquals("username", d.getTarget());
Assert.assertEquals(String.class, d.getType());
Assert.assertEquals("theUsername", d.getSource());
Method m = d.check(User.class);
Assert.assertNotNull(m);
Assert.assertEquals("setUsername", m.getName());
Assert.assertEquals(String.class, m.getParameterTypes()[0]);
}
}
/trunk/src/test/java/org/mentacontainer/impl/MentaComponentTest.java
New file
0,0 → 1,59
package org.mentacontainer.impl;
 
import junit.framework.Assert;
 
import org.junit.Test;
import org.mentacontainer.Component;
 
public class MentaComponentTest {
private static class User {
private String username;
public User() { }
public User(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
@Test
public void testComponent() throws Exception {
Component c1 = new MentaComponent("user1", User.class).addInitValue("saoj");
Component c2 = new MentaComponent("user2", User.class).addProperty("username", "soliveira");
User u1 = (User) c1.getInstance();
User u2 = (User) c2.getInstance();
Assert.assertTrue(u1 != u2);
Assert.assertTrue(!u1.getUsername().equals(u2.getUsername()));
}
@Test
public void testSingleton() throws Exception {
Component c1 = new MentaComponent("user", User.class, true).addInitValue("saoj");
User u1 = (User) c1.getInstance();
User u2 = (User) c1.getInstance();
Assert.assertTrue(u1 == u2);
Assert.assertTrue(u1.getUsername().equals(u2.getUsername()));
}
}