/** * Select a field from given class's declared field as a test target. * * @throws RejectedChoice If class has no fields to choose from. */ protected Field targetFieldFrom(Class<?> clazz, FieldGetMethod howToGet) throws RejectedChoice { Field[] fields = null; switch (howToGet) { case GET_DECLARED_FIELD: case GET_DECLARED_FIELDS: fields = ReflectiveInterceptor.jlClassGetDeclaredFields(clazz); break; case GET_FIELD: case GET_FIELDS: fields = ReflectiveInterceptor.jlClassGetFields(clazz); break; } // To be deterministic we must sort these in a predictable fashion! Arrays.sort(fields, new ToStringComparator()); Field f = choice(fields); toStringValue.append(f.getName()); try { switch (howToGet) { case GET_DECLARED_FIELDS: case GET_FIELDS: return f; case GET_DECLARED_FIELD: return ReflectiveInterceptor.jlClassGetDeclaredField(clazz, f.getName()); case GET_FIELD: return ReflectiveInterceptor.jlClassGetField(clazz, f.getName()); } } catch (Exception e) { throw new Error(e); } return f; }