Well, you could do something like this:
public static class StringHolder {
@Inject String held;
}
public class BuilderTest implements Module {
@Inject @Unit Provider<StringHolder> subject;
@Inject StringBuilder builder;
public void configure(Binder b) {
final StringBuilder builder = new StringBuilder();
builder.append("in configure | ");
b.bind(StringBuilder.class).toInstance(builder);
b.bind(String.class).toProvider(new Provider<String>() {
public String get() {
return builder.toString();
}
});
}
@Test
public void testMethod() {
builder.append("in test method");
StringHolder sh = subject.get();
System.out.println(sh.held); // prints "in configure | in test method"
}
}
Substitute your mock's interface for String and your mock builder for StringBuilder.
That's pretty onerous unless your builders all implement an interface that you can use to make a generic provider class. And the subject.get() is a little bit annoying.
--Logan