public ReflectionProvider(T target, Context context) { try { ReflectFactory reflectFactory = context.get(ReflectFactory.class); CopyStrategyLibrary copyStrategies = context.get(CopyStrategyLibrary.class); ClassMetadata<T, ?> classMetadata = new DefaultClassMetadata<>(new SimpleUri(), (Class<T>) target.getClass(), reflectFactory, copyStrategies); for (Field field : getAllFields(target.getClass(), and(withAnnotation(Range.class), or(withType(Float.TYPE), withType(Float.class))))) { Range range = field.getAnnotation(Range.class); FieldMetadata<T, Float> fieldMetadata = (FieldMetadata<T, Float>) classMetadata.getField(field.getName()); Property property = new FloatProperty(target, fieldMetadata, range.min(), range.max()); properties.add(property); } } catch (NoSuchMethodException e) { logger.error("Cannot provide provide inspection for {}, does not have a default constructor", target.getClass()); } }
private void injectMockMuleContext(Object injectionTarget) throws IllegalAccessException { final Field contextField = getFields(DefaultProcessorInterceptorManager.class, withType(MuleContext.class)).iterator().next(); contextField.setAccessible(true); contextField.set(injectionTarget, mock(MuleContext.class, RETURNS_DEEP_STUBS)); }
@Override public Statement apply(Statement base, Description description) { Set<Field> fields = ReflectionUtils.getAllFields(target.getClass(), Predicates.and( withAnnotation(HiveRunnerSetup.class), withType(HiveRunnerConfig.class))); Preconditions.checkState(fields.size() <= 1, "Exact one field of type HiveRunnerConfig should to be annotated with @HiveRunnerSetup"); /* Override the config with test case config. Taking care to not replace the config instance since it has been passes around and referenced by some of the other test rules. */ if (!fields.isEmpty()) { config.override(ReflectionUtils .getFieldValue(target, fields.iterator().next().getName(), HiveRunnerConfig.class)); } return base; } };
@Override public Statement apply(Statement base, Description description) { Set<Field> fields = ReflectionUtils.getAllFields(target.getClass(), Predicates.and( withAnnotation(HiveRunnerSetup.class), withType(HiveRunnerConfig.class))); Preconditions.checkState(fields.size() <= 1, "Exact one field of type HiveRunnerConfig should to be annotated with @HiveRunnerSetup"); /* Override the config with test case config. Taking care to not replace the config instance since it has been passes around and referenced by some of the other test rules. */ if (!fields.isEmpty()) { config.override(ReflectionUtils .getFieldValue(target, fields.iterator().next().getName(), HiveRunnerConfig.class)); } return base; } };
@Override public Object process(Object object) { for (Field field : getAllFields(object.getClass(), withAnnotation(Inject.class), withType(Registry.class))) { try { field.setAccessible(true); field.set(object, new DefaultRegistry(context)); } catch (Exception e) { throw new RuntimeException(format("Could not inject dependency on field %s of type %s", field.getName(), object.getClass().getName()), e); } } for (Method method : getAllMethods(object.getClass(), withAnnotation(Inject.class), withParameters(Registry.class))) { try { method.invoke(object, new DefaultRegistry(context)); } catch (Exception e) { throw new RuntimeException(format("Could not inject dependency on method %s of type %s", method.getName(), object.getClass().getName()), e); } } return object; } }
private void injectMockMuleContext(Object injectionTarget) throws IllegalAccessException { final Field contextField = getFields(DefaultProcessorInterceptorManager.class, withType(MuleContext.class)).iterator().next(); contextField.setAccessible(true); contextField.set(injectionTarget, mock(MuleContext.class, RETURNS_DEEP_STUBS)); }