Skip to content

Commit ea75433

Browse files
Merge branch 'main' of github.com:helpdeveloper/java-modular-architecture into main
2 parents 03eadc0 + 755cf12 commit ea75433

File tree

7 files changed

+106
-20
lines changed

7 files changed

+106
-20
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
![Issues](https://img.shields.io/github/issues/helpdeveloper/java-modular-architecture.svg)
2+
![Forks](https://img.shields.io/github/forks/helpdeveloper/java-modular-architecture.svg)
3+
![Stars](https://img.shields.io/github/stars/helpdeveloper/java-modular-architecturei.svg)
4+
![Release Version](https://img.shields.io/github/release/helpdeveloper/java-modular-architecture.svg)
15
# Arquitetura modular
2-
### Projeto em desenvolvimento...
6+
### Projeto em desenvolvimento
37

48
<p align="center">
59
<img src="./images/arch.png" height="350">
@@ -26,21 +30,21 @@ Todo acesso a dados seja banco e/ou api's expostos pelas interfaces do Use Case
2630
Facilidade na execução dos testes com uma melhor granularidade.
2731

2832
### Unitários
29-
- JUnit5
30-
- Mockito
31-
- AssertJ
32-
- Mutação
33-
- Cobertura de código (linha e condições)
33+
- [JUnit5](https://junit.org/junit5/)
34+
- [Mockito](https://site.mockito.org)
35+
- [AssertJ](https://assertj.github.io/doc/)
36+
- [Mutação](https://pitest.org)
37+
- [Cobertura de código (linha e condições)](https://www.eclemma.org/jacoco/)
3438

3539
### Aceitação (acceptance-test)
3640
Teste do ponto de vista de quem irá consumir, sempre buscando o mais perto de produção.
3741

3842
#### O que tem:
39-
- Docker
40-
- TestContainers
41-
- RestAssured
42-
- WireMock
43-
- Flyway
43+
- [Docker](https://www.docker.com)
44+
- [TestContainers](https://www.testcontainers.org)
45+
- [RestAssured](https://rest-assured.io)
46+
- [WireMock](http://wiremock.org)
47+
- [Flyway](https://flywaydb.org)
4448

4549
#### O que não tem:
4650
- Framework (Spring ou quarkus)

acceptance-test/src/test/java/br/com/helpdev/atdd/ApplicationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void whenGetWithInvalidIdThenReturnError() {
5555
.then()
5656
.statusCode(404)
5757
.body("message",
58-
equalTo("Mensagem com o id: 123123 não foi encontrada, confira se o identificador está correto e tente novamente."));
58+
equalTo("Message with Id 123123 not found"));
5959
}
6060

6161
@Test

core/use-case/src/main/java/br/com/helpdev/usecase/FindRequestNotification.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public class FindRequestNotification {
2323

2424
public Message find(final MessageId id) throws NotificationException {
2525
return repository.find(id).orElseThrow(() ->
26-
new MessageNotFoundException(
27-
"Mensagem com o id: " + id + " não foi encontrada, confira se o identificador está correto e tente novamente.")
26+
new MessageNotFoundException("Message with Id " + id + " not found")
2827
);
2928
}
3029

core/use-case/src/main/java/br/com/helpdev/usecase/PushRequestNotification.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ public class PushRequestNotification {
2424

2525
public Message push(final Message message) throws NotificationException {
2626
return repository.create(message.toBuilder()
27-
.chats(List.of(Chat.builder()
28-
.date(ZonedDateTime.now())
29-
.status(Status.WAITING)
30-
.build())).build());
27+
.chats(getSingleListWithCurrentTimesAndWaitingStatus())
28+
.build());
29+
}
30+
31+
private List<Chat> getSingleListWithCurrentTimesAndWaitingStatus() {
32+
return List.of(Chat.builder()
33+
.date(ZonedDateTime.now())
34+
.status(Status.WAITING)
35+
.build());
3136
}
3237

3338
}

core/use-case/src/test/java/br/com/helpdev/usecase/DeleteRequestNotificationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void shouldThrowsMessageNotFoundExceptionWhenNotFoundId() {
4848
assertThatThrownBy(() -> deleteRequestNotification.delete(messageId))
4949
.hasMessage("Message id: " + messageId.value() + " dont exists");
5050

51-
5251
verify(repository, times(1))
5352
.exists(messageId);
5453
}

core/use-case/src/test/java/br/com/helpdev/usecase/FindRequestNotificationTest.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package br.com.helpdev.usecase;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5+
import static org.mockito.Mockito.mock;
6+
import static org.mockito.Mockito.times;
7+
import static org.mockito.Mockito.verify;
8+
import static org.mockito.Mockito.when;
9+
10+
import br.com.helpdev.domain.Message;
11+
import br.com.helpdev.domain.vo.MessageId;
312
import br.com.helpdev.usecase.port.MessageRepository;
13+
import java.util.Optional;
14+
import org.junit.jupiter.api.Test;
415
import org.junit.jupiter.api.extension.ExtendWith;
516
import org.mockito.InjectMocks;
617
import org.mockito.Mock;
@@ -13,5 +24,33 @@ class FindRequestNotificationTest {
1324
private MessageRepository repository;
1425

1526
@InjectMocks
16-
private FindRequestNotification deleteRequestNotification;
27+
private FindRequestNotification findRequestNotification;
28+
29+
@Test
30+
void shouldBeFindMessageWhenMessageIdExists() {
31+
final var messageId = MessageId.from(12L);
32+
final var message = mock(Message.class);
33+
34+
when(repository.find(messageId)).thenReturn(Optional.of(message));
35+
36+
final var response = findRequestNotification.find(messageId);
37+
38+
verify(repository, times(1))
39+
.find(messageId);
40+
assertThat(response)
41+
.isEqualTo(message);
42+
}
43+
44+
@Test
45+
void shouldThrowsMessageNotFoundExceptionWhenNotFoundId() {
46+
final var messageId = MessageId.from(12L);
47+
48+
when(repository.find(messageId)).thenReturn(Optional.empty());
49+
50+
assertThatThrownBy(() -> findRequestNotification.find(messageId))
51+
.hasMessage("Message with Id " + messageId.value() + " not found");
52+
53+
verify(repository, times(1))
54+
.find(messageId);
55+
}
1756
}

core/use-case/src/test/java/br/com/helpdev/usecase/PushRequestNotificationTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package br.com.helpdev.usecase;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.when;
6+
7+
import br.com.helpdev.domain.Message;
8+
import br.com.helpdev.domain.Recipient;
9+
import br.com.helpdev.domain.Status;
10+
import br.com.helpdev.domain.vo.MessageBody;
11+
import br.com.helpdev.domain.vo.MessageId;
12+
import br.com.helpdev.domain.vo.Phone;
313
import br.com.helpdev.usecase.port.MessageRepository;
14+
import org.junit.jupiter.api.Test;
415
import org.junit.jupiter.api.extension.ExtendWith;
516
import org.mockito.InjectMocks;
617
import org.mockito.Mock;
@@ -14,4 +25,33 @@ class PushRequestNotificationTest {
1425

1526
@InjectMocks
1627
private PushRequestNotification deleteRequestNotification;
28+
29+
@Test
30+
void shouldBeCreateMessageWithSuccess() {
31+
final var message = fakeBuilder().build();
32+
final var requiredResponse = mock(Message.class);
33+
34+
when(repository.create(message))
35+
.then(invocationOnMock -> {
36+
Message messageInCreate = invocationOnMock.getArgument(0);
37+
assertThat(messageInCreate.getChats())
38+
.isNotNull()
39+
.allMatch(x -> x.getStatus().equals(Status.WAITING))
40+
.hasSize(1);
41+
return requiredResponse;
42+
});
43+
44+
final var response = deleteRequestNotification.push(message);
45+
46+
assertThat(response)
47+
.isEqualTo(requiredResponse);
48+
}
49+
50+
private Message.MessageBuilder fakeBuilder() {
51+
return Message.builder().body(MessageBody.from("empty"))
52+
.recipient(Recipient.builder()
53+
.phone(Phone.newNumber("123123"))
54+
.build())
55+
.id(MessageId.from(1L));
56+
}
1757
}

0 commit comments

Comments
 (0)