Hi!
I'm writing a unit test where arbitrary objects have to be created without knowing anything about the objects (with some exceptions). I use reflection to create objects and set their fields to random values etc... I'm almost there but I've come to an issue I can't find a solution to.
Say that an Object that is instansiated using reflection has a field, which is a Map<Object, Object>. I set this field to an empty map.
The object has the following method:
public SomeObject doSomething(String aString) {
SomeObject someObject = (SomeObject) map.get(aString);
if(someObject == null) throw new SomeException();
return someObject;
}
The problem is that my program want to set the map field in the Object instance to some random map. But it cant be totally random since later code depend on what is in that map. What will happen is that the value that is returned from map.get() will try to be cast to some specific type and fail, since I can't know what kind of map to create.
Is there a way to solve this? To somehow detect what the value of map.get() is going to be cast to or something?
Thanks!
/S