@Override protected Collection<Field> getSingleDataPointFields(ParameterSignature sig) { Collection<Field> fields = super.getSingleDataPointFields(sig); String requestedName = sig.getAnnotation(FromDataPoints.class).value(); List<Field> fieldsWithMatchingNames = new ArrayList<Field>(); for (Field field : fields) { String[] fieldNames = field.getAnnotation(DataPoint.class).value(); if (Arrays.asList(fieldNames).contains(requestedName)) { fieldsWithMatchingNames.add(field); } } return fieldsWithMatchingNames; }
@Override protected Collection<FrameworkMethod> getSingleDataPointMethods(ParameterSignature sig) { Collection<FrameworkMethod> methods = super.getSingleDataPointMethods(sig); String requestedName = sig.getAnnotation(FromDataPoints.class).value(); List<FrameworkMethod> methodsWithMatchingNames = new ArrayList<FrameworkMethod>(); for (FrameworkMethod method : methods) { String[] methodNames = method.getAnnotation(DataPoint.class).value(); if (Arrays.asList(methodNames).contains(requestedName)) { methodsWithMatchingNames.add(method); } } return methodsWithMatchingNames; }
private void addFields(ParameterSignature sig, List<PotentialAssignment> list) { for (final Field field : fClass.getJavaClass().getFields()) { if (Modifier.isStatic(field.getModifiers())) { Class<?> type = field.getType(); if (sig.canAcceptArrayType(type) && field.getAnnotation(DataPoints.class) != null) { try { addArrayValues(field.getName(), list, getStaticFieldValue(field)); } catch (Throwable e) { // ignore and move on } } else if (sig.canAcceptType(type) && field.getAnnotation(DataPoint.class) != null) { list.add(PotentialAssignment .forValue(field.getName(), getStaticFieldValue(field))); } } } }
private void addFields(final ParameterSignature sig, final List<PotentialAssignment> list) { for (final Field field : fClass.getJavaClass().getFields()) { if (Modifier.isStatic(field.getModifiers())) { Class<?> type = field.getType(); if (sig.canAcceptArrayType(type) && field.getAnnotation(DataPoints.class) != null) { try { addArrayValues(field.getName(), list, getStaticFieldValue(field)); } catch (Throwable e) { // ignore and move on } } else if (sig.canAcceptType(type) && field.getAnnotation(DataPoint.class) != null) { list.add(PotentialAssignment.forValue(field.getName(), getStaticFieldValue(field))); } } } }
@DataPoint public static APITestScenario createSimpleSource() { TestSource source = new TestSource("test", generateClassName(), Modifier.PUBLIC); source.appendFields(new RetainedTestField(String.class).createFieldSpec(), new ArgTestField(Integer.class).createFieldSpec()) .appendTransformation((b, s) -> b.superclass(MockedFragment.class)); return base -> new APITestBase(base, source); }
@DataPoint public static APITestScenario createSourceWithInnerClass() { TestSource enclosingClass = new TestSource("test", generateClassName(), Modifier.PUBLIC); TestSource source = new TestSource(null, generateClassName(), Modifier.PUBLIC); source.appendFields(new RetainedTestField(String.class).createFieldSpec(), new ArgTestField(Integer.class).createFieldSpec()) .appendTransformation((b, s) -> b.superclass(MockedFragment.class)); enclosingClass.innerClasses(true, source); return base -> new APITestBase(base, source, enclosingClass, new TestSource[] {}); }
protected Collection<Field> getSingleDataPointFields(ParameterSignature sig) { List<FrameworkField> fields = fClass.getAnnotatedFields(DataPoint.class); Collection<Field> validFields = new ArrayList<Field>(); for (FrameworkField frameworkField : fields) { validFields.add(frameworkField.getField()); } return validFields; }
private void addSinglePointMethods(ParameterSignature sig, List<PotentialAssignment> list) { for (FrameworkMethod dataPointMethod : fClass .getAnnotatedMethods(DataPoint.class)) { if (isCorrectlyTyped(sig, dataPointMethod.getType())) { list.add(new MethodParameterValue(dataPointMethod)); } } }
private List<Class> allMaterialConfigsWhichAreDataPointsInThisTest() throws Exception { Set<Field> fields = Reflections.getAllFields(getClass(), Reflections.withAnnotation(DataPoint.class)); ArrayList<Class> allDataPointMaterialConfigClasses = new ArrayList<>(); for (Field field : fields) { allDataPointMaterialConfigClasses.add(field.get(this).getClass()); } return allDataPointMaterialConfigClasses; }
private void addSinglePointMethods(final ParameterSignature sig, final List<PotentialAssignment> list) { for (FrameworkMethod dataPointMethod : fClass.getAnnotatedMethods(DataPoint.class)) { if (isCorrectlyTyped(sig, dataPointMethod.getType())) { list.add(new MethodParameterValue(dataPointMethod)); } } }
@DataPoint public static GeneratedClassWithName simpleClass() { final JavaFileObject object = CodeGenUtils .createTestClass(field(STRING_TYPE, "foo", Retained.class)); return new GeneratedClassWithName(object, TEST_CLASS); }
protected Collection<FrameworkMethod> getSingleDataPointMethods(ParameterSignature sig) { return fClass.getAnnotatedMethods(DataPoint.class); }
@DataPoint({"singlemethod", "named"}) public static String getSingleValue() { return "named single method value"; }
@DataPoint public static String getSingleOtherValue() { return "other single method value"; }
@DataPoint public static Integer object() { return 1; }
@DataPoint public static Method getType() throws SecurityException, NoSuchMethodException { return ParameterSignatureTest.class.getMethod("getType", Method.class, int.class); }
@DataPoint("named") public static String methodString() { return "expected single method string"; }
@DataPoint public static String otherSingleValueMethod() { return "other single value string"; }
@DataPoint public static int failingDataPoint() { throw new RuntimeException(); }
@DataPoint(ignoredExceptions=Throwable.class) public static int failingDataPoint() { throw new RuntimeException(); }
@DataPoint(ignoredExceptions=NullPointerException.class) public static int failingDataPoint() { throw new RuntimeException(); }
@DataPoint public int singleDataPointMethod() { return 1; }
@DataPoint static int three() { return 3; }
@DataPoint protected static int four() { return 4; }
@DataPoint private static int five() { return 5; }
@DataPoint public static int oneHundred() { return 100; }
@DataPoint public static List<Object> empty() { return new ArrayList<Object>(); }
@DataPoint public static int oneUglyHundred() { throw new RuntimeException(); }
@DataPoint public int oneHundred() { return 100; }