use of org.junit.runners.model.FrameworkField in project sling by apache.
the class PerformanceRunner method readListenersFromStaticFields.
private List<Listener> readListenersFromStaticFields() throws Exception {
List<Listener> listeners = new ArrayList<Listener>();
for (FrameworkField field : getTestClass().getAnnotatedFields(Listen.class)) {
Listener listener = (Listener) field.get(null);
if (listener == null) {
throw new IllegalArgumentException("Field " + field.getName() + " should not be null");
}
listeners.add(listener);
}
return listeners;
}
use of org.junit.runners.model.FrameworkField in project stdlib by petergeneric.
the class AutomockAnnotatedMockModule method configure.
@Override
protected void configure() {
final Errors errors = new Errors(testClass);
for (FrameworkField field : fields) {
try {
final Field f = field.getField();
final Key key = Annotations.getKey(TypeLiteral.get(f.getGenericType()), f, field.getAnnotations(), errors);
bindMock(key, f.getType(), "Automock[" + field.getName() + "] " + key);
} catch (ErrorsException e) {
// Add it to the error list and hold them all until the end
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
}
use of org.junit.runners.model.FrameworkField in project registry by hortonworks.
the class CustomParameterizedBlockJUnit4Runner method validateFields.
@Override
protected void validateFields(List<Throwable> errors) {
super.validateFields(errors);
if (getInjectionType() == InjectionType.FIELD) {
List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
int[] usedIndices = new int[annotatedFieldsByParameter.size()];
for (FrameworkField each : annotatedFieldsByParameter) {
int index = each.getField().getAnnotation(Parameter.class).value();
if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
errors.add(new Exception("Invalid @Parameter value: " + index + ". @Parameter fields counted: " + annotatedFieldsByParameter.size() + ". Please use an index between 0 and " + (annotatedFieldsByParameter.size() - 1) + "."));
} else {
usedIndices[index]++;
}
}
for (int index = 0; index < usedIndices.length; index++) {
int numberOfUse = usedIndices[index];
if (numberOfUse == 0) {
errors.add(new Exception("@Parameter(" + index + ") is never used."));
} else if (numberOfUse > 1) {
errors.add(new Exception("@Parameter(" + index + ") is used more than once (" + numberOfUse + ")."));
}
}
}
}
use of org.junit.runners.model.FrameworkField in project alchemy-test by SirWellington.
the class TestClassInjectors method inflate.
private static void inflate(FrameworkField field, Object target, Object value) throws IllegalArgumentException, IllegalAccessException {
Field javaField = field.getField();
boolean originalAccessibility = javaField.isAccessible();
try {
javaField.setAccessible(true);
javaField.set(target, value);
} finally {
javaField.setAccessible(originalAccessibility);
}
}
use of org.junit.runners.model.FrameworkField in project junit4 by junit-team.
the class AllMembersSupplier method getDataPointsFields.
protected Collection<Field> getDataPointsFields(ParameterSignature sig) {
List<FrameworkField> fields = clazz.getAnnotatedFields(DataPoints.class);
Collection<Field> validFields = new ArrayList<Field>();
for (FrameworkField frameworkField : fields) {
validFields.add(frameworkField.getField());
}
return validFields;
}
Aggregations