Add plain static alias of captorForClass for static imports
Author: onacitCreated May 16, 2026Updated May 16, 2026
Static imports with plain name, regardless of coding conventions, may help.
Check the following code snippet for a book's coding block whose all calls are statically imported for the brevity.
final var inOrder = inOrder(subscriber);
inOrder.verify(subscriber, times(1)).onSubscribe(notNull());
final var elementCaptor = forClass(Byte.class); // <<<<<<<<<<<<<<<<<<
inOrder.verify(subscriber, times(HelloWorld.BYTES)).onNext(elementCaptor.capture());
inOrder.verify(subscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
final var expected = hello_world_byte_array();
final var elements = elementCaptor.getAllValues();
assertEquals(expected.length, elements.size());
for (int i = 0; i < elements.size(); i++) {
assertEquals(expected[i], elements.get(i));
} // @formatter:onIt will be helpful when the ArgumentCaptor has captorForClass.
This is not a redundant signature.
Even the JUnit's Arguments class added arguments(...) method analogues to the of(...) method.
A verify thin wrapper will be ok.
public static <U, S extends U> ArgumentCaptor<U> captorForClass(Class<S> clazz) {
return forClass(clazz);
}Source: mockito/mockito