File tree Expand file tree Collapse file tree 4 files changed +51
-4
lines changed
main/java/br/com/helpdev/domain/vo
test/java/br/com/helpdev/domain/vo Expand file tree Collapse file tree 4 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public static MessageBody from(final String body) {
1212 private final String body ;
1313
1414 MessageBody (final String body ) {
15- Objects .requireNonNull (body );
15+ Objects .requireNonNull (body , "Body cant be null" );
1616 if (body .isEmpty ()) {
1717 throw new InvalidMessageException ("Body cant be empty" );
1818 }
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public static MessageId from(final Long id) {
1414 private final Long id ;
1515
1616 MessageId (final Long id ) {
17- Objects .requireNonNull (id );
17+ Objects .requireNonNull (id , "Id cant be null" );
1818 if (id <= 0 ) {
1919 throw new IllegalArgumentException ("Id should be greater than 0" );
2020 }
Original file line number Diff line number Diff line change 11package br .com .helpdev .domain .vo ;
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 org .junit .jupiter .api .Test ;
47
58class MessageBodyTest {
69
10+ @ Test
11+ void shouldThrowsNullPointerWhenBodyIsNull () {
12+ assertThatThrownBy (() -> MessageBody .from (null ))
13+ .hasMessage ("Body cant be null" );
14+ }
15+
16+ @ Test
17+ void shouldThrowsInvalidMessageExceptionWhenBodyIsEmpty () {
18+ assertThatThrownBy (() -> MessageBody .from ("" ))
19+ .hasMessage ("Body cant be empty" );
20+ }
21+
22+ @ Test
23+ void shouldBeCreatedWithSuccess () {
24+ final var messageBody = MessageBody .from ("test" );
25+ assertThat (messageBody .value ())
26+ .isNotNull ()
27+ .isEqualTo ("test" );
28+ }
29+
730}
Original file line number Diff line number Diff line change 11package br .com .helpdev .domain .vo ;
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 org .junit .jupiter .api .Test ;
47
58class MessageIdTest {
69
10+ @ Test
11+ void shouldThrowsNullPointerWhenMessageIdIsNull () {
12+ assertThatThrownBy (() -> MessageId .from (null ))
13+ .hasMessage ("Id cant be null" );
14+ }
15+
16+ @ Test
17+ void shouldThrowsInvalidMessageExceptionWhenBodyIsntGreaterThan0 () {
18+ assertThatThrownBy (() -> MessageId .from (0L ))
19+ .hasMessage ("Id should be greater than 0" );
20+ assertThatThrownBy (() -> MessageId .from (-1L ))
21+ .hasMessage ("Id should be greater than 0" );
22+ }
23+
24+ @ Test
25+ void shouldBeCreatedWithSuccess () {
26+ final var messageBody = MessageId .from (1L );
27+ assertThat (messageBody .value ())
28+ .isNotNull ()
29+ .isEqualTo (1L );
30+ }
731}
You can’t perform that action at this time.
0 commit comments