You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code demonstrates the behavior. As it is written, the test will fail with a missing invocation as expected, and "real" is printed to the console. But if the two commented lines are uncommented, the test passes and "mock" is printed to the console. Is this the expected behavior when two Injectables of the same type are within the scope of the test? I've found that it doesn't matter the type of the Injectables either; File, HashMap, and Bar have all produced this behavior.
private class Bar {
String str;
Bar(String str) {
this.str = str;
}
}
private class Foo {
Optional<ArrayList<Bar>> getList() {
Bar bar = new Bar("real");
ArrayList<Bar> list = new ArrayList<Bar>();
list.add(bar);
return Optional.of(list);
}
}
// @Injectable HashMap bar1; // Uncommenting these 2 lines
// @Injectable HashMap bar2; // causes the test to pass
@Injectable Optional<ArrayList<Bar>> optListMock;
@Test
void test() {
ArrayList<Bar> expList = new ArrayList<Bar>();
expList.add(new Bar("mock"));
new Expectations(Optional.class) {
{
optListMock.get();
result = expList;
}
};
Foo foo = new Foo();
ArrayList<Bar> list = foo.getList().get();
System.out.println(list.get(0).str);
}
The text was updated successfully, but these errors were encountered:
JMockit version: 1.30
TestNG version: 6.9.13
The following code demonstrates the behavior. As it is written, the test will fail with a missing invocation as expected, and "real" is printed to the console. But if the two commented lines are uncommented, the test passes and "mock" is printed to the console. Is this the expected behavior when two Injectables of the same type are within the scope of the test? I've found that it doesn't matter the type of the Injectables either; File, HashMap, and Bar have all produced this behavior.
The text was updated successfully, but these errors were encountered: