Skip to content

Commit

Permalink
Install mock by TypeLiteral and Qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
gonciarz authored and gsmet committed Jan 30, 2023
1 parent ac9e7ee commit c80a3c6
Showing 1 changed file with 13 additions and 0 deletions.
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);
}
}

0 comments on commit c80a3c6

Please sign in to comment.