I'm trying to mock one of my classes in the following manner.
class A {
....
...
public Fruits getFruitsByID(String fruitId)
//get fruit type from DB
}
Now class B tries to access this method in class A in the following manner
class B{
A fruitConn;
B(A fruitConnLocal)
{
fruitConn=fruitConnLocal;
}
Response getFruits ( String fruitID) {
Fruits fruit= fruitConn.getFruitsByID(fruitID);
..../// send response with fruits.
}
Here's how I try to mock it using Mockito.
classBTest {
public void testGetFruits(){
A fruitConn= mock(fruitConn.class);
Fruit fruit= mock(Fruit.class);
B testB= new B(fruitConn);
when(fruitConn.getFruitsByID(Matchers.anyString()).thenReturn(fruit);
// here the actual method getFruitsByID is
//called instead of the mock.. why?
AssertNotEmpty(B.getFruits("test"));
}
}
P.S. Im very new to mockito so any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire