I have to create a lot of objects in my test class, and I can't seem to find a way to do it. So far it would have to be done as so
but I would rather have the switch in a method with parameters, so I can do
and just use create(String name) for each object.
Any hints in the right direction?
Code:
Object a;
private void creatorA()
{
switch (generator.nextInt(2) )
{
case 0: a = new TypeA();
break;
case 1: a = new TypeB();
break;
case 2: a = new TypeC();
break;
}
}
Object b;
private void creatorB()
{
switch (generator.nextInt(2) )
{
case 0: b = new TypeA();
break;
case 1: b = new TypeB();
break;
case 2: b = new TypeC();
break;
}
}
but I would rather have the switch in a method with parameters, so I can do
Code:
private void create(String name)
{
switch (generator.nextInt(2) )
{
case 0: Object name = new TypeA();
break;
case 1: Object name = new TypeB();
break;
case 2: Object name = new TypeC();
break;
}
}
and just use create(String name) for each object.
Any hints in the right direction?