? Mono.just(existing)
: Mono.error(() -> new MessageMutationException(existing, text)))
.switchIfEmpty(
- Mono
- .fromSupplier(() ->service.persistMessage(key, LocalDateTime.now(clock), text))
- .doOnNext(m ->
+ service
+ .persistMessage(key, LocalDateTime.now(clock), text)
+ .doOnNext(m ->
+ {
+ Sinks.EmitResult result = sink.tryEmitNext(m);
+ if (result.isFailure())
{
- Sinks.EmitResult result = sink.tryEmitNext(m);
- if (result.isFailure())
- {
- log.warn("Emitting of message failed with {} for {}", result.name(), m);
- }
- }));
+ log.warn("Emitting of message failed with {} for {}", result.name(), m);
+ }
+ }));
}
.thenReturn(Mono.just(existingMessage));
// Needed for readable error-reports, in case of a bug that leads to according unwanted call
when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
- .thenReturn(mock(Message.class));
+ .thenReturn(mock(Mono.class));
// When
client
.thenReturn(Mono.empty());
// Needed for readable error-reports, in case of a bug that leads to according unwanted call
when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
- .thenReturn(mock(Message.class));
+ .thenReturn(mock(Mono.class));
// When
client
String messageText = "Bar";
Message message = new Message(key, 0l, timestamp, messageText);
when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.empty());
- when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(message);
+ when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
// When
Mono<Message> mono = chatRoom.addMessage(messageId, user, messageText);
String messageText = "Bar";
Message message = new Message(key, 0l, timestamp, messageText);
when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
- when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(message);
+ when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
// When
Mono<Message> mono = chatRoom.addMessage(messageId, user, messageText);
String mutatedText = "Boom!";
Message message = new Message(key, 0l, timestamp, messageText);
when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
- when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(message);
+ when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
// When
Mono<Message> mono = chatRoom.addMessage(messageId, user, mutatedText);