Search in sources :

Example 1 with FrameworkField

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;
}
Also used : ArrayList(java.util.ArrayList) FrameworkField(org.junit.runners.model.FrameworkField)

Example 2 with FrameworkField

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();
}
Also used : Errors(com.google.inject.internal.Errors) Field(java.lang.reflect.Field) FrameworkField(org.junit.runners.model.FrameworkField) ErrorsException(com.google.inject.internal.ErrorsException) FrameworkField(org.junit.runners.model.FrameworkField) Key(com.google.inject.Key)

Example 3 with FrameworkField

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 + ")."));
            }
        }
    }
}
Also used : Parameter(org.junit.runners.Parameterized.Parameter) FrameworkField(org.junit.runners.model.FrameworkField) MultipleFailureException(org.junit.runners.model.MultipleFailureException)

Example 4 with FrameworkField

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);
    }
}
Also used : Field(java.lang.reflect.Field) FrameworkField(org.junit.runners.model.FrameworkField)

Example 5 with FrameworkField

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;
}
Also used : Field(java.lang.reflect.Field) FrameworkField(org.junit.runners.model.FrameworkField) ArrayList(java.util.ArrayList) FrameworkField(org.junit.runners.model.FrameworkField)

Aggregations

FrameworkField (org.junit.runners.model.FrameworkField)12 Field (java.lang.reflect.Field)7 ArrayList (java.util.ArrayList)4 Parameter (org.junit.runners.Parameterized.Parameter)4 MultipleFailureException (org.junit.runners.model.MultipleFailureException)2 Key (com.google.inject.Key)1 Errors (com.google.inject.internal.Errors)1 ErrorsException (com.google.inject.internal.ErrorsException)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Random (java.util.Random)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 Parameterized (org.junit.runners.Parameterized)1 TestClass (org.junit.runners.model.TestClass)1