jeudi 31 janvier 2019

Mock multiple level arrays in java for unit testing

Hypothetically I have

class Box{
   Item[] items;
}

class Item{
   Toy[] toys;
}

class Toy{
   Color[] colors;
}

The method is to test if the Box has green color toy;

public bool testHasColor(Box){
   //There will be code here that
   //Streams over each type till we get to color
   // Final point is
   if(color==Color.GREEN){
    return true;
   }
}

BoxText.class

public void testBoxHasColorGreenMethod(){
    // Need mocking here
}

What the best way to mock this Box class for the test case?

Thank you

Aucun commentaire:

Enregistrer un commentaire