Skip to content

Issue 110 #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Issue 110 #175

wants to merge 3 commits into from

Conversation

MatrixFrog
Copy link

Fix for issue 110 with test case

…(and methods that return Collections), rather than just arrays.
…o a Theory (or more accurately, it won't pass objects of the wrong type that it finds in a Collection)
@dsaff
Copy link
Member

dsaff commented Mar 4, 2011

This is linked from issue 110, so closing it here.

@dsaff dsaff reopened this Jun 24, 2011
@dsaff
Copy link
Member

dsaff commented Feb 9, 2012

Linking here to issue #110

Object dataPoints= dataPointsMethod.invokeExplosively(null);
try {
addArrayValues(dataPointsMethod.getName(), list, dataPoints);
} catch (IllegalArgumentException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to do this that doesn't involve throwing an exception?

@dsaff
Copy link
Member

dsaff commented Apr 23, 2012

@MatrixFrog, do you have further time to spend on this? Thanks.

@dsaff
Copy link
Member

dsaff commented May 21, 2012

Closing for now. Feel free to re-open!

@dsaff dsaff closed this May 21, 2012
@djh82
Copy link
Contributor

djh82 commented Jun 6, 2012

Could you not doe something like this?

Modify addArrayValues to be:

private void addArrayValues(String name, List list, Object array, ParameterSignature sig) {
if (Collection.class.isAssignableFrom(array.getClass())) {
Collection<?> c = Collection.class.cast(array);
array = c.toArray((Object[]) Array.newInstance(sig.getType(), c.size()));
}
for (int i= 0; i < Array.getLength(array); i++)
list.add(PotentialAssignment.forValue(name + "[" + i + "]", Array.get(array, i)));
}

and addFields to be:

 private void addFields(ParameterSignature sig, List list) {
for (final Field field : fClass.getJavaClass().getFields()) {
if (Modifier.isStatic(field.getModifiers())) {
Class type= field.getType(); if ((sig.canAcceptArrayType(type) || Collection.class.isAssignableFrom(type) && sig.canAcceptType((Class) (((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0])))
&& field.getAnnotation(DataPoints.class) != null) {
addArrayValues(field.getName(), list, getStaticFieldValue(field), sig);
} else if (sig.canAcceptType(type)
&& field.getAnnotation(DataPoint.class) != null) {
list.add(PotentialAssignment
.forValue(field.getName(), getStaticFieldValue(field)));
}
}
}
}

@Stephan202
Copy link
Contributor

Just for reference: this pull request has been superseded by #658.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants