MentaContainer

Compare Revisions

Ignore whitespace Rev 93 → Rev 94

/trunk/src/test/java/org/mentacontainer/impl/MentaContainerTest.java
270,12 → 270,10
c.ioc("connection", Connection.class).addInitValue("A super JDBC connection!");
c.wire("conn" /* the property name that will receive the dependency */,
Connection.class /* the type of the property that will receive the dependency */,
c.autowireBySetter("conn" /* the property name that will receive the dependency */,
"connection" /* the source inside the container */);
c.wire("myDep" /* notice this is the setter of the Connection class */,
SomeDependency.class /* the type - it could be an interface for better decoupling */,
c.autowireBySetter("myDep" /* notice this is the setter of the Connection class */,
"aDependency" /* again this is the name of the bean/component inside the container */);
return c;
/trunk/src/test/java/org/mentacontainer/DependencyTest.java
5,13 → 5,14
import junit.framework.Assert;
 
import org.junit.Test;
import org.mentacontainer.Dependency;
import org.mentacontainer.SetterDependency;
 
public class DependencyTest {
private static class User {
private String username;
private String something;
public User() { }
26,17 → 27,31
public void setUsername(String username) {
this.username = username;
}
public void setSomething(String s) {
this.something = "STRING: " + s;
}
public void setSomething(Object s) {
this.something = "OBJECT: " + s;
}
public String getSomething() {
return something;
}
public void setElse(Object s) {
}
}
@Test
public void testDependency() {
Dependency d = new Dependency("username", String.class, "theUsername");
SetterDependency d = new SetterDependency("username", "theUsername", String.class);
Assert.assertEquals("username", d.getTarget());
Assert.assertEquals(String.class, d.getType());
Assert.assertEquals("theUsername", d.getSource());
Method m = d.check(User.class);
46,5 → 61,21
Assert.assertEquals("setUsername", m.getName());
Assert.assertEquals(String.class, m.getParameterTypes()[0]);
d = new SetterDependency("something", "theSomething", String.class);
m = d.check(User.class);
Assert.assertEquals("setSomething", m.getName());
Assert.assertEquals(String.class, m.getParameterTypes()[0]);
d = new SetterDependency("else", "theElse", String.class);
m = d.check(User.class);
Assert.assertEquals("setElse", m.getName());
Assert.assertEquals(Object.class, m.getParameterTypes()[0]);
}
}