Class under test:
class FruitQuality {
void testQuality() {
getfruits();
//some code
}
List<Fruits> getfruits() {
return orange;
}
}
Below is the test code. I mocked the class class under test and overridden a return value for the method getfruits. But when I run the mock, I don't get the expected mocked return value. Easymock can substitute return values for methods of class under test, if those are explicitly mocked. How can I get the mocked return value when I mock the real object method.
@Test
public void test() {
Fruits fruit= new Fruits();
fruit.setFruit("orange");
List<Fruits> fruitsList = new ArrayList<Fruits>();
fruitsList.add(fruit);
Fruits mock = Mockito.mock(FruitQuality.class)
classUnderTest = new FruitQuality();
when(mock.getfruits()).thenReturn(fruitsList);
result= classUnderTest.getfruits();
assertEquals(result, fruitsList);
}