11package br .com .helpdev .domain ;
22
3- import static org .junit .jupiter .api .Assertions .*;
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
5+
6+ import br .com .helpdev .domain .vo .MessageBody ;
7+ import br .com .helpdev .domain .vo .MessageId ;
8+ import br .com .helpdev .domain .vo .Phone ;
9+ import java .util .Optional ;
10+ import org .junit .jupiter .api .Test ;
411
512class MessageTest {
613
14+ @ Test
15+ void shouldThrowsInvalidRecipientExceptionWhenRecipientIsNull () {
16+ var builder = Message .builder ()
17+ .body (MessageBody .from ("body" ));
18+
19+ assertThatThrownBy (() -> builder .build ())
20+ .hasMessage ("The message needs a recipient" );
21+ }
22+
23+
24+ @ Test
25+ void shouldThrowsNullPointerWhenMessageBodyIsNull () {
26+ var builder = Message .builder ().body (null );
27+
28+ assertThatThrownBy (() -> builder .build ())
29+ .hasMessage ("Body cant be null" );
30+ }
31+
32+ @ Test
33+ void shouldReturnEmptyIdWhenMessageWasCreatedWithoutThat () {
34+ var builder = Message .builder ()
35+ .body (MessageBody .from ("body" ))
36+ .recipient (Recipient .builder ()
37+ .phone (Phone .newNumber ("1" ))
38+ .build ());
39+
40+ assertThat (builder .build ().getId ())
41+ .isEqualTo (Optional .empty ());
42+ }
43+
44+ @ Test
45+ void shouldReturnIdWhenMessageWasCreatedWith () {
46+ var builder = Message .builder ()
47+ .body (MessageBody .from ("body" ))
48+ .id (MessageId .from (123L ))
49+ .recipient (Recipient .builder ()
50+ .phone (Phone .newNumber ("1" ))
51+ .build ());
52+
53+ assertThat (builder .build ().getId ())
54+ .isEqualTo (Optional .of (MessageId .from (123L )));
55+ }
56+
757}
0 commit comments