I am write UT with Mockito, and I want replace my mock function(which DB select operation)
class DataBaseSelect {
List<Long> selectDataFromDB(Long key){
List<Long> result = db.select(key);
return result;
}
}
with new function (mock db select using map) I wrote in Test class;
class MapSelect {
List<Long> selectDataFromMap(Long key){
List<Long> result = map.get(key);
return result;
}
}
and I want return the right value with right key input
I try to do this using ArgumentCaptor as below, but it did not work as I want
ArgumentCaptor<Long> argumentCaptor = ArgumentCaptor.forClass(Long.class);
Mockito.when(dataBaseSelect.selectDataFromDB(argumentCaptor.capture())).thenReturn(MapSelect.selectDataFromMap(argumentCaptor.getValue()));
//some thing else here ,
I want when call dataBaseSelect.selectDataFromDB, it will be mock and then return result from MapSelect.selectDataFromMap and argument is passed from dataBaseSelect.selectDataFromDB