本文整理匯總了Java中org.needle4j.injection.InjectionTargetInformation類的典型用法代碼示例。如果您正苦於以下問題:Java InjectionTargetInformation類的具體用法?Java InjectionTargetInformation怎麽用?Java InjectionTargetInformation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InjectionTargetInformation類屬於org.needle4j.injection包,在下文中一共展示了InjectionTargetInformation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createArguments
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
private Object[] createArguments(final Class<?>[] parameterTypes,
final InjectionTargetInformationFactory injectionTargetInformationFactory) {
final Object[] arguments = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
final InjectionTargetInformation injectionTargetInformation = injectionTargetInformationFactory.create(
parameterTypes[i], i);
final Entry<Object, Object> injection = inject(injectionTargetInformation);
if (injection != null) {
arguments[i] = injection.getValue();
}
}
return arguments;
}
示例2: initFields
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
private void initFields(final Object instance) {
final List<Field> fields = ReflectionUtil.getAllFieldsWithSupportedAnnotation(instance.getClass(),
isSupportedAnnotationPredicate);
for (final Field field : fields) {
final InjectionTargetInformation injectionTargetInformation = new InjectionTargetInformation(
field.getType(), field);
final Entry<Object, Object> injection = inject(injectionTargetInformation);
if (injection != null) {
try {
ReflectionUtil.setField(field, instance, injection.getValue());
} catch (final Exception e) {
LOG.error(e.getMessage(), e);
}
}
}
}
示例3: inject
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
private Entry<Object, Object> inject(final InjectionTargetInformation injectionTargetInformation) {
for (final Collection<InjectionProvider<?>> collection : configuration.getInjectionProvider()) {
final Entry<Object, Object> injection = configuration.handleInjectionProvider(collection,
injectionTargetInformation);
if (injection != null) {
final Object injectionKey = injection.getKey();
// check if mock object already created
final Object injectionValue = context.getInjectedObject(injectionKey) == null ? injection.getValue()
: context.getInjectedObject(injectionKey);
context.addInjectedObject(injectionKey, injectionValue);
return new MapEntry<Object, Object>(injectionKey, injectionValue);
}
}
return null;
}
示例4: initMethodInjection
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
private void initMethodInjection(final Object instance) {
final List<Method> methods = ReflectionUtil.getMethods(instance.getClass());
for (final Method method : methods) {
// if the method is not annotated with at least one supported
// annotation, skip it!
if (!isSupportedAnnotationPredicate.applyAny(method.getDeclaredAnnotations())) {
continue;
}
final Class<?>[] parameterTypes = method.getParameterTypes();
final InjectionTargetInformationFactory injectionTargetInformationFactory = new InjectionTargetInformationFactory() {
@Override
public InjectionTargetInformation create(final Class<?> parameterType, final int parameterIndex) {
return new InjectionTargetInformation(parameterType, method,
method.getGenericParameterTypes()[parameterIndex],
method.getParameterAnnotations()[parameterIndex]);
}
};
final Object[] arguments = createArguments(parameterTypes, injectionTargetInformationFactory);
try {
ReflectionUtil.invokeMethod(method, instance, arguments);
} catch (final Exception e) {
LOG.warn("could not invoke method", e);
}
}
}
示例5: getInstanceByConstructorInjection
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
protected Object getInstanceByConstructorInjection(final Class<?> implementation)
throws ObjectUnderTestInstantiationException {
final Constructor<?>[] constructors = implementation.getConstructors();
for (final Constructor<?> constructor : constructors) {
// has the constructor at least one supported injection annotation?
if (!isSupportedAnnotationPredicate.applyAny(constructor.getAnnotations())) {
continue;
}
final Class<?>[] parameterTypes = constructor.getParameterTypes();
final InjectionTargetInformationFactory injectionTargetInformationFactory = new InjectionTargetInformationFactory() {
@Override
public InjectionTargetInformation create(final Class<?> parameterType, final int parameterIndex) {
return new InjectionTargetInformation(parameterType, constructor,
constructor.getGenericParameterTypes()[parameterIndex],
constructor.getParameterAnnotations()[parameterIndex]);
}
};
final Object[] arguments = createArguments(parameterTypes, injectionTargetInformationFactory);
try {
return constructor.newInstance(arguments);
} catch (final Exception e) {
throw new ObjectUnderTestInstantiationException(e);
}
}
return null;
}
示例6: EntityManagerProvider
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
public EntityManagerProvider(final DatabaseTestcase databaseTestcase) {
super();
this.databaseTestcase = databaseTestcase;
verifyer = new InjectionVerifier() {
@Override
public boolean verify(final InjectionTargetInformation information) {
if (information.getType() == EntityManager.class) {
return true;
}
return false;
}
};
}
示例7: EntityManagerFactoryProvider
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
EntityManagerFactoryProvider(final DatabaseTestcase databaseTestcase) {
super();
this.databaseTestcase = databaseTestcase;
verifier = new InjectionVerifier() {
@Override
public boolean verify(final InjectionTargetInformation information) {
if (information.getType() == EntityManagerFactory.class) {
return true;
}
return false;
}
};
}
示例8: testVerify
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Test
public void testVerify() throws Exception {
InjectionTargetInformation injectionTargetInformation = new InjectionTargetInformation(TransactionHelper.class,
ReflectionUtil.getField(this.getClass(), "helper"));
assertTrue(provider.verify(injectionTargetInformation));
assertNotNull(provider.getInjectedObject(TransactionHelper.class));
}
示例9: verify
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public boolean verify(InjectionTargetInformation injectionTargetInformation) {
final Class<?> type = injectionTargetInformation.getType();
return type.isAssignableFrom(mockProvider.getClass());
}
示例10: getKey
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public Object getKey(InjectionTargetInformation injectionTargetInformation) {
return MockProvider.class;
}
示例11: getKey
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public Object getKey(final InjectionTargetInformation injectionTargetInformation) {
return injectionProviderDelegate.getKey(injectionTargetInformation);
}
示例12: verify
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public boolean verify(final InjectionTargetInformation injectionTargetInformation) {
return injectionProviderDelegate.verify(injectionTargetInformation);
}
示例13: verify
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public boolean verify(InjectionTargetInformation information) {
return information.getType() == EntityTransaction.class ? true : false;
}
示例14: getKey
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public Object getKey(InjectionTargetInformation information) {
return EntityTransaction.class;
}
示例15: verify
import org.needle4j.injection.InjectionTargetInformation; //導入依賴的package包/類
@Override
public boolean verify(InjectionTargetInformation information) {
return information.getType() == TransactionHelper.class ? true : false;
}