Testing class
public class CollectionImplementationUnitTest {
CollectionImplementation colImp;
public void setup() throws Exception {
...
colImp = Mockito.spy(new CollectionImplementation());
...
}
private String mockHistoryFromStrgyTable() {
String value1 = "myValue";
return value1;
}
@Test
public void testgetinfo (){
...
Mockito.when(
colImp.historyFromStrgyTable(
Mockito.anyString(),Mockito.anyString(),Mockito.anyString()
)
)
.thenReturn(mockHistoryFromStrgyTable());
CollectionsAccount Info = colImp.accountInfo(
"string1","string2","string3", new IdentityAcc(), TableLst
);
}
}
Class under the test
public class CollectionImplementation {
...
@Override
public CollectionsAccount accountInfo(("string1","string2","string3", new IdentityAcc(), TableLst)) {
DetailsHelper helper = new (db2, "string",getmethod());
return helper.accountInfo("string1","string2", new IdentityAcc(), TableLst);
}
public String historyFromStrgyTable(){
}
}
DetailsHelper
public class DetailsHelper{
public CollectionsAccount accountInfo((String string1,String string2,String string3, new IdentityAcc(), TableLst)){
...
String paymentdetails = historyFromStrgyTable();
}
public String historyFromStrgyTable(){
}
}
When I try to make fun of the data for the HistoryFromStrgyTable () method, it actually accesses HistoryFromStrgyTable () instead of getting from mockHistoryFromStrgyTable ().
My test cases do not work on this line
Mockito.when(col_Imp.HistoryFromStrgyTable(Mockito.anyString(),
Mockito.anyString(),Mockito.anyString())).thenReturn( mockHistoryFromStrgyTable());
Can anyone help me with this. I donβt understand what happened. I also changed the mockHistoryFromStrgyTable () method from private to public, since mockito cannot mock private methods.