mockit.internal.expectations.injection.InjectionPoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for automated developer testing.
It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external
APIs; JUnit (4 & 5) and TestNG test runners are supported.
It also contains an advanced code coverage tool.
/*
* Copyright (c) 2006 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.expectations.injection;
import java.lang.annotation.*;
import java.lang.reflect.*;
import javax.annotation.*;
import javax.ejb.*;
import javax.inject.*;
import javax.persistence.*;
import javax.servlet.*;
import static mockit.internal.util.ClassLoad.*;
import static mockit.internal.util.MethodReflection.*;
import static mockit.internal.util.ParameterReflection.*;
import static mockit.internal.util.Utilities.*;
final class InjectionPoint
{
enum KindOfInjectionPoint { NotAnnotated, Required, Optional, WithValue }
@Nullable static final Class extends Annotation> INJECT_CLASS;
@Nullable private static final Class extends Annotation> EJB_CLASS;
@Nullable static final Class extends Annotation> PERSISTENCE_UNIT_CLASS;
@Nullable static final Class> SERVLET_CLASS;
@Nullable static final Class> CONVERSATION_CLASS;
static
{
INJECT_CLASS = searchTypeInClasspath("javax.inject.Inject");
EJB_CLASS = searchTypeInClasspath("javax.ejb.EJB");
PERSISTENCE_UNIT_CLASS = searchTypeInClasspath("javax.persistence.PersistenceUnit");
SERVLET_CLASS = searchTypeInClasspath("javax.servlet.Servlet");
CONVERSATION_CLASS = searchTypeInClasspath("javax.enterprise.context.Conversation");
}
static boolean isServlet(@Nonnull Class> aClass)
{
return SERVLET_CLASS != null && Servlet.class.isAssignableFrom(aClass);
}
private InjectionPoint() {}
@Nonnull
static Object wrapInProviderIfNeeded(@Nonnull Type type, @Nonnull final Object value)
{
if (
INJECT_CLASS != null && type instanceof ParameterizedType && !(value instanceof Provider) &&
((ParameterizedType) type).getRawType() == Provider.class
) {
return new Provider
© 2015 - 2024 Weber Informatics LLC | Privacy Policy