Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install mock by TypeLiteral and Qualifiers #29779

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.annotation.Annotation;

import javax.enterprise.inject.spi.CDI;
import javax.enterprise.util.TypeLiteral;

import org.junit.jupiter.api.TestInstance;

Expand Down Expand Up @@ -56,4 +57,16 @@ public static <T> void installMockForType(T mock, Class<? super T> instance, Ann
}
MockSupport.installMock(CDI.current().select(instance, qualifiers).get(), mock);
}

/**
* Installs a mock for a CDI normal scoped bean by typeLiteral and qualifiers
*
* @param mock The mock object
* @param typeLiteral TypeLiteral representing the required type
* @param qualifiers The CDI qualifiers of the bean to mock
* @param <T> The bean type
*/
public static <T> void installMockForType(T mock, TypeLiteral<? super T> typeLiteral, Annotation... qualifiers) {
MockSupport.installMock(CDI.current().select(typeLiteral, qualifiers).get(), mock);
}
}