I have a class called Garden which contains an arraylist of flowers. I have a method which returns an instance of the class in the class and a method to add flowers to the class. How can I add flowers to the instance of the class in my test harness. My code:
public class Garden {
ArrayList<Flower> flowerbed = new ArrayList<Flower>();
Hive hive = null;
private static Garden instance;
public static Garden getInstance(){
if(instance == null){
instance = new Garden();
}
return instance;
}
public void addFlower(Flower flower){
flowerbed.add(flower);
}//some methods omitted
}
If I do:
Flower f;
Garden g = new Garden();
g.addFlower(f);
a new flower is added to the garden but not to the instance of the garden and because the getInstance method is static it is confusing me on how to use it in my testharness.