Your cast is failing because you're casting an ArgumentCaptor<stuff>
to a List<stuff>
.
If you are already calling MockitoAnnotations.initMocks(this)
, you can just declare a field as a @Captor
, which is the easiest way to reduce the repetition:
public class YourTest {
@Mock SomeClass someMock;
@Captor ArgumentCaptor<List<EditJobSettingsSet>> argument;
@Before public void initializeMocks() {
// This gets called automatically if you @RunWith(MockitoJUnitRunner.class).
MockitoAnnotations.initMocks(this);
}
@Test public void yourTest() {
// [insert setup here]
verify(mEditJobListener).settingsAdded(argument.capture());
// [insert assertions here]
}
}
Otherwise, you're going to have to cast something approximating this (which I will test when I can):
// Might not work without the cast to (ArgumentCaptor) and some @SuppressWarnings.
ArgumentCaptor<List<EditJobSettingsSet>> argument =
(ArgumentCaptor<List<EditJobSettingsSet>>)
((ArgumentCaptor) ArgumentCaptor.forClass(List.class));