Skip to content

Commit

Permalink
Couple of nitpicks ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Herault committed Aug 17, 2012
1 parent cbf46b8 commit 1fa373f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/junit/runners/Parameterized.java
Expand Up @@ -177,7 +177,8 @@ public Object createTest() throws Exception {
List<FrameworkField> fields = getTestClass().getAnnotatedFields(Parameter.class);
if (!fields.isEmpty()) {
if (fields.size() != fParameters.length)
throw new Exception("Wrong number of parameters and @parameter fields. @parameter fields counted: "+fields.size()+", available parameters: "+fParameters.length+".");
throw new Exception("Wrong number of parameters and @parameter fields."+
" @Parameter fields counted: "+fields.size()+", available parameters: "+fParameters.length+".");
testClassInstance = getTestClass().getJavaClass().newInstance();
for (FrameworkField f : fields) {
Field field = f.getField();
Expand All @@ -186,7 +187,10 @@ public Object createTest() throws Exception {
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);
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);
}
}
} else {
Expand Down Expand Up @@ -223,17 +227,21 @@ protected void validateFields(List<Throwable> errors) {
for (FrameworkField f : annotatedFieldsByParameter) {
int index = f.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)+"."));
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("The index "+index+" is never used."));
errors.add(new Exception("@Parameter("+index+") is never used."));
} else if (numberOfUse > 1) {
errors.add(new Exception("The index "+index+" is used more than once ("+numberOfUse+")."));
errors.add(new Exception("@Parameter("+index+") is used more than once ("+numberOfUse+")."));
}
}
}
Expand Down

0 comments on commit 1fa373f

Please sign in to comment.