I'm trying to replace cdi-unit by cdi-test. I already managed to make it work for several cases, however I hit in a situation where I need several mocks of the same type on the same test.
Due to a validation in cdi-test we can't inject mocks with the same type.
I would like that we use another attribute as a discriminator, allowing several mocks of the same type to be injected. Maybe mocks with a given name, could be injected with @Named or a qualifier with the same name as the mock.
No workaround came to my mind.
The code where it is blocking the injection:
@Override
public synchronized void onMockCreated(Object mock, MockCreationSettings settings) {
final Class<?> typeToMock = settings.getTypeToMock();
final Map<Class<?>, Object> mocks = currentMockSet();
if (mocks.containsKey(typeToMock)) {
throw new CdiTestException("mock " + typeToMock + " already in set");
}
try {
mocks.put(typeToMock, mock);
} catch (UnsupportedOperationException uoe) {
// IGNORE
}
}
Hello.
I'm trying to replace cdi-unit by cdi-test. I already managed to make it work for several cases, however I hit in a situation where I need several mocks of the same type on the same test. Due to a validation in cdi-test we can't inject mocks with the same type.
I would like that we use another attribute as a discriminator, allowing several mocks of the same type to be injected. Maybe mocks with a given name, could be injected with
@Named
or a qualifier with the same name as the mock.No workaround came to my mind.
The code where it is blocking the injection: