Мой код выглядит примерно так:
Код: Выделить всё
return client.sql(sqlToSearch)
.bind("alternateCodeType", alternateCodeType)
.bind("alternateCode", alternateCode)
.map(locationR2DBCMapper::apply).one();
Код класса сопоставителя выглядит следующим образом:
Код: Выделить всё
public class LocationR2DBCMapper implements BiFunction {
@Override
public Location apply(Row row, Object o) {
if(row.get(0)!=null)
{
Location location = new Location();
location.setId(row.get("location_id", Long.class));
location.setLocationName(row.get("location_name", String.class));
location.setLocationType(row.get("location_type", String.class));
location.setProjectionMsg(row.get("projection_msg", String.class));
location.setIsFacility(row.get("is_facility",Boolean.class));
return location;
}
else {
return new Location();
}
}
}
Код: Выделить всё
client.sql(sqlToSearch)
.bind("alternateCodeType", alternateCodeType)
.bind("alternateCode", alternateCode)
.map(locationR2DBCMapper::apply).one();
Я попробовал этот подход:
Код: Выделить всё
@BeforeEach
void setUp() {
databaseClientMock = Mockito.mock(DatabaseClient.class);
locationR2DBCMapperMock = Mockito.mock(LocationR2DBCMapper.class);
DatabaseClient databaseClientMock = mock(DatabaseClient.class);
DatabaseClient.GenericExecuteSpec executeSpecMock = mock(DatabaseClient.GenericExecuteSpec.class);
Mono monoResultMock = mock(Mono.class);
locationCustomRepositoryImplMock = new LocationCustomRepositoryImpl(databaseClientMock,locationR2DBCMapperMock);
}
@Test
public void getLocationByLocationTypeTest()
{
RowsFetchSpec rowsFetchSpecMock = mock(RowsFetchSpec.class);
when(databaseClientMock.sql(anyString())).thenReturn(executeSpecMock);
when(executeSpecMock.map(Mockito.any(BiFunction.class))).thenReturn(rowsFetchSpecMock);
Flux resultFluxMock = Flux.empty(); // Replace this with your own Flux instance
when(rowsFetchSpecMock.all()).thenReturn(resultFluxMock);
//Mockito.when(databaseClientMock.sql(anyString())).thenReturn(Flux.just(Location.builder().locationName("someName").id(Long.valueOf(123)).build()));
}
Код: Выделить всё
when(rowsFetchSpecMock.all()).thenReturn(resultFluxMock);
Подробнее здесь: https://stackoverflow.com/questions/769 ... baseclient