I have a factory method that creates objects that will be used in unit tests. All these objects are made from one base class:
public static <T extends BaseEntity> T modMake(Class<T> clazz)
{
try {
return clazz.newInstance();
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
}
}
Now I want to override the getter method from this base class, but only for tests. I usually do this with an anonymous class, for example ( Nodeis one of the subtypes BaseEntity):
public static Node nodMake()
{
return new Node() {
@Override
public long ixGet() { return 1; }
};
}
Can I do this in a function with an argument Classtoo?
source
share