private static void addClassInfo(FieldInfo mi, ClassInfo ci) {
expect(mi.getClassInfo()).andReturn(ci).anyTimes();
}
public static ClassInfo cls(String name, InfoObject... members) {
ClassInfo ci = createMock(ClassInfo.class);
expect(ci.getName()).andReturn(name).anyTimes();
ArrayList<MethodInfo> methods = new ArrayList<MethodInfo>();
ArrayList<FieldInfo> instanceFields = new ArrayList<FieldInfo>();
ArrayList<FieldInfo> staticFields = new ArrayList<FieldInfo>();
for (InfoObject member : members) {
if(member instanceof MethodInfo){
addClassInfo((MethodInfo) member, ci);
replay(member);
methods.add((MethodInfo) member);
}
else {
FieldInfo f = (FieldInfo) member;
addClassInfo(f, ci);
replay(f);
if(Modifier.isStatic(f.getModifiers()))
staticFields.add(f);
else
instanceFields.add(f);
}
}
expect(ci.getDeclaredMethodInfos()).andReturn(methods.toArray(new MethodInfo[0])).anyTimes();
expect(ci.getDeclaredInstanceFields()).andReturn(instanceFields.toArray(new FieldInfo[0])).anyTimes();
expect(ci.getDeclaredStaticFields()).andReturn(staticFields.toArray(new FieldInfo[0])).anyTimes();
replay(ci);
return ci;
}