I am writing UT with Mockito and I want to replace my mock function (what DB select operation)
class DataBaseSelect {
List<Long> selectDataFromDB(Long key){
List<Long> result = db.select(key);
return result;
}
}
with a new function (mock db select using map) I wrote in the Test class;
class MapSelect {
List<Long> selectDataFromMap(Long key){
List<Long> result = map.get(key);
return result;
}
}
and I want to return the correct value with the correct key entry
I am trying to do this with an ArgumentCaptor as shown below, but this 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 dataBaseSelect.selectDataFromDB is called, it will be the layout, and then it returns the result from MapSelect.selectDataFromMap and the argument is passed from dataBaseSelect.selectDataFromDB
source
share