use of org.junit.runners.model.FrameworkField in project junit4 by junit-team.
the class AllMembersSupplier method getSingleDataPointFields.
protected Collection<Field> getSingleDataPointFields(ParameterSignature sig) {
List<FrameworkField> fields = clazz.getAnnotatedFields(DataPoint.class);
Collection<Field> validFields = new ArrayList<Field>();
for (FrameworkField frameworkField : fields) {
validFields.add(frameworkField.getField());
}
return validFields;
}
use of org.junit.runners.model.FrameworkField in project hazelcast by hazelcast.
the class AbstractParameterizedHazelcastClassRunner method createTestUsingFieldInjection.
private Object createTestUsingFieldInjection() throws Exception {
List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
if (annotatedFieldsByParameter.size() != fParameters.length) {
throw new Exception("Wrong number of parameters and @Parameter fields." + " @Parameter fields counted: " + annotatedFieldsByParameter.size() + ", available parameters: " + fParameters.length + ".");
}
Object testClassInstance = getTestClass().getJavaClass().newInstance();
for (FrameworkField each : annotatedFieldsByParameter) {
Field field = each.getField();
Parameterized.Parameter annotation = field.getAnnotation(Parameterized.Parameter.class);
int index = annotation.value();
try {
field.set(testClassInstance, fParameters[index]);
} catch (IllegalArgumentException iare) {
throw new Exception(getTestClass().getName() + ": Trying to set " + field.getName() + " with the value " + fParameters[index] + " that is not the right type (" + fParameters[index].getClass().getSimpleName() + " instead of " + field.getType().getSimpleName() + ").", iare);
}
}
return testClassInstance;
}
use of org.junit.runners.model.FrameworkField in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method getAnnotatedFieldValues.
/*
* We're using JUnit infrastructure here, but provide constant
* ordering of the result. The returned list has class...super order.
*/
private <T> List<T> getAnnotatedFieldValues(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) {
TestClass info = AccessController.doPrivileged(new PrivilegedAction<TestClass>() {
@Override
public TestClass run() {
return new TestClass(suiteClass);
}
});
List<T> results = new ArrayList<T>();
List<FrameworkField> annotatedFields = new ArrayList<FrameworkField>(info.getAnnotatedFields(annotationClass));
// Split fields by class
final HashMap<Class<?>, List<FrameworkField>> byClass = new HashMap<Class<?>, List<FrameworkField>>();
for (FrameworkField field : annotatedFields) {
Class<?> clz = field.getField().getDeclaringClass();
if (!byClass.containsKey(clz)) {
byClass.put(clz, new ArrayList<FrameworkField>());
}
byClass.get(clz).add(field);
}
// Consistent order at class level.
for (List<FrameworkField> fields : byClass.values()) {
Collections.sort(fields, new Comparator<FrameworkField>() {
@Override
public int compare(FrameworkField o1, FrameworkField o2) {
return o1.getField().getName().compareTo(o2.getField().getName());
}
});
Collections.shuffle(fields, new Random(runnerRandomness.getSeed()));
}
annotatedFields.clear();
for (Class<?> clz = suiteClass; clz != null; clz = clz.getSuperclass()) {
List<FrameworkField> clzFields = byClass.get(clz);
if (clzFields != null) {
annotatedFields.addAll(clzFields);
}
}
for (FrameworkField each : annotatedFields) {
try {
Object fieldValue = each.get(test);
if (valueClass.isInstance(fieldValue))
results.add(valueClass.cast(fieldValue));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return results;
}
use of org.junit.runners.model.FrameworkField in project alchemy-test by SirWellington.
the class TestClassInjectors method populateGeneratedFields.
static void populateGeneratedFields(TestClass testClass, Object target) throws IllegalArgumentException, IllegalAccessException {
//@GenerateString
List<FrameworkField> stringGeneratedFields = testClass.getAnnotatedFields(GenerateString.class);
for (FrameworkField field : stringGeneratedFields) {
inflateString(field, target);
}
//@GenerateBoolean
List<FrameworkField> booleanGeneratedFields = testClass.getAnnotatedFields(GenerateBoolean.class);
for (FrameworkField field : booleanGeneratedFields) {
inflateBoolean(field, target);
}
//@GenerateInteger
List<FrameworkField> integerGeneratedFields = testClass.getAnnotatedFields(GenerateInteger.class);
for (FrameworkField field : integerGeneratedFields) {
inflateInteger(field, target);
}
//@GenerateLong
List<FrameworkField> longGeneratedFields = testClass.getAnnotatedFields(GenerateLong.class);
for (FrameworkField field : longGeneratedFields) {
inflateLong(field, target);
}
//@GenerateDouble
List<FrameworkField> doubleGeneratedFields = testClass.getAnnotatedFields(GenerateDouble.class);
for (FrameworkField field : doubleGeneratedFields) {
inflateDouble(field, target);
}
//@GenerateDate
List<FrameworkField> dateGeneratedFields = testClass.getAnnotatedFields(GenerateDate.class);
for (FrameworkField field : dateGeneratedFields) {
inflateDate(field, target);
}
//@GenerateInstant
List<FrameworkField> instantGeneratedFields = testClass.getAnnotatedFields(GenerateInstant.class);
for (FrameworkField field : instantGeneratedFields) {
inflateInstant(field, target);
}
//@GenerateURL
List<FrameworkField> urlGeneratedFields = testClass.getAnnotatedFields(GenerateURL.class);
for (FrameworkField field : urlGeneratedFields) {
inflateUrl(field, target);
}
//@GeneratePojo
List<FrameworkField> pojoGeneratedFields = testClass.getAnnotatedFields(GeneratePojo.class);
for (FrameworkField field : pojoGeneratedFields) {
inflatePojo(field, target);
}
//@GenerateEnum
List<FrameworkField> enumGeneratedFields = testClass.getAnnotatedFields(GenerateEnum.class);
for (FrameworkField field : enumGeneratedFields) {
inflateEnum(field, target);
}
//@GenerateList
List<FrameworkField> listGeneratedfields = testClass.getAnnotatedFields(GenerateList.class);
for (FrameworkField field : listGeneratedfields) {
inflateList(field, target);
}
}
Aggregations