}
public void testMonitoringHappensBeforeAndAfterInstantiation() throws NoSuchMethodException {
final long beforeTime = System.currentTimeMillis();
Mock monitor = mock(ComponentMonitor.class);
Constructor emptyHashMapCtor = HashMap.class.getConstructor(new Class[0]);
monitor.expects(once()).method("instantiating").with(eq(emptyHashMapCtor));
Constraint startIsAfterBegin = new Constraint() {
public boolean eval(Object o) {
Long startTime = (Long) o;
return beforeTime <= startTime.longValue();
}
public StringBuffer describeTo(StringBuffer stringBuffer) {
return stringBuffer.append("The startTime wasn't after the begin of the test");
}
};
Constraint durationIsGreaterThanOrEqualToZero = new Constraint() {
public boolean eval(Object o) {
Long duration = (Long) o;
return 0 <= duration.longValue();
}
public StringBuffer describeTo(StringBuffer stringBuffer) {
return stringBuffer.append("The endTime wasn't after the startTime");
}
};
monitor.expects(once()).method("instantiated").with(eq(emptyHashMapCtor), startIsAfterBegin, durationIsGreaterThanOrEqualToZero);
ConstructorInjectionComponentAdapter cica = new ConstructorInjectionComponentAdapter(Map.class, HashMap.class,
new Parameter[0], false, (ComponentMonitor) monitor.proxy());
cica.getComponentInstance(null);
}