Код: Выделить всё
@Test
void test() {
Optional someParam = Optional.empty();
String TOPIC = "topic";
Token token = getToken();
Stream tokenStream = Stream.of(token);
TokenDto tokenDto = getDto();
when(specificDataMapper.fromToken(token)).thenReturn(tokenDto);
doAnswer(invocation -> {
TransactionCallbackWithoutResult callback = new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
Stream stream = tokenRepository.streamAll();
stream.forEach(t -> {
TokenDto payload = specificDataMapper.fromToken(t);
pubSubTemplate.publish(TOPIC, payload);
});
}
};
callback.doInTransaction(null);
return null;
}).when(transactionTemplate).executeWithoutResult(any());
doReturn(tokenStream).when(tokenRepository).streamAll();
publisherService.publishservice(someParam);
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... n-template