test: Simplified `ChatBackendControllerTest`
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / domain / ChatHomeTestBase.java
1 package de.juplo.kafka.chat.backend.domain;
2
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5 import org.junit.jupiter.api.extension.ExtendWith;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.test.context.junit.jupiter.SpringExtension;
8 import reactor.core.publisher.Mono;
9
10 import java.util.UUID;
11
12 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
13
14
15 @ExtendWith(SpringExtension.class)
16 public class ChatHomeTestBase
17 {
18   @Autowired
19   ChatHome chatHome;
20
21
22   @Test
23   @DisplayName("Assert chatroom is delivered, if it exists")
24   void testGetExistingChatroom()
25   {
26     // Given
27     UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
28
29     // When
30     Mono<ChatRoom> mono = chatHome.getChatRoom(chatRoomId);
31
32     // Then
33     assertThat(mono).emitsCount(1);
34   }
35
36   @Test
37   @DisplayName("Assert UnknownChatroomException is thrown, if chatroom does not exist")
38   void testGetNonExistentChatroom()
39   {
40     // Given
41     UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17");
42
43     // When
44     Mono<ChatRoom> mono = chatHome.getChatRoom(chatRoomId);
45
46     // Then
47     assertThat(mono).sendsError(e ->
48     {
49       assertThat(e).isInstanceOf(UnknownChatroomException.class);
50       UnknownChatroomException unknownChatroomException = (UnknownChatroomException) e;
51       assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);
52     });
53   }
54 }