Testing class
stream list into map, where I get atribute from an element of this list
public class MyClass {
private final Map<String, IMyInterface> map;
public MyClass(final List<IMyInterface> list) {
this.map = list.stream().collect(Collectors.toMap(IMyInterface::getUniqueName, i -> i));
}
}
Test
@RunWith(MockitoJUnitRunner.class)
public class MyClassTest {
@InjectMock
private MyClass instance;
@Spy
private ArrayList<IMyInterface> list;
@Mock
private A a;
@Mock
private B b;
@Before void setUp() throws Exception {
list.add(a);
list.add(b);
}
}
Or Test
@RunWith(MockitoJUnitRunner.class)
public class MyClassTest {
@Spy
private ArrayList<IMyInterface> list;
@Mock
private A a;
@Mock
private B b;
private class MockedClass extends MyClass {
MockedClass(List<IMyInterface> list) {
super(list);
}
}
@Before void setUp() throws Exception {
list.add(a);
list.add(b);
}
}
How to get injected Map after execute constructor? I have to test this class and use map object
EDIT:
IMyInterface::getUniqueName()
is a method in interface objects A and B implements IMyInterface
I want to collect injected list into map When I add elements into list, I got it in debugging mode in my tested class, but when debugging mode is on
list.stream().collect(Collectors.toMap(IMyInterface::getUniqueName(), i -> i));
it stop