Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlambo3/chainofresponsability---emailscheck
Java implementation showcasing the Chain of Responsibility pattern. The main branch contains the base development, while the chain-of-responsibility and chain-of-responsibility-2 branches apply the pattern. Includes JUnit 5 tests for validating email routing logic.
https://github.com/vlambo3/chainofresponsability---emailscheck
chainofresponsibility chainofresponsibility-pattern java junit-test junit5 test testing
Last synced: about 1 month ago
JSON representation
Java implementation showcasing the Chain of Responsibility pattern. The main branch contains the base development, while the chain-of-responsibility and chain-of-responsibility-2 branches apply the pattern. Includes JUnit 5 tests for validating email routing logic.
- Host: GitHub
- URL: https://github.com/vlambo3/chainofresponsability---emailscheck
- Owner: vlambo3
- Created: 2024-07-17T15:04:26.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-17T20:19:18.000Z (6 months ago)
- Last Synced: 2024-07-18T20:57:55.922Z (6 months ago)
- Topics: chainofresponsibility, chainofresponsibility-pattern, java, junit-test, junit5, test, testing
- Language: Java
- Homepage: https://github.com/vlambo3/ChainOfResponsability---EmailsCheck
- Size: 76.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chain of Responsibility Pattern Example
## Overview
This repository contains an example of how to apply the Chain of Responsibility pattern in Java. The `main` branch contains the development without applying the pattern, while the `chain-of-responsibility` branch contains the same development with the pattern applied.
## Branches
- **`main`**: Development without the Chain of Responsibility pattern.
- **`chain-of-responsibility`**: Development applying the Chain of Responsibility pattern.## Scenario
At the company called Colmena, there are three departments: Management, Sales, and Technical. When they receive an email (in their colmena.com domain), they want it to be controlled according to the company's AI rules and sent to the appropriate department.
We will simulate this control with the following assumptions:
### Email Routing Rules
| Subject | Destination Email | Department |
|------------|-----------------------------|--------------|
| Management | [email protected] | Management |
| Sales | [email protected] | Sales |
| Technical | [email protected] | Technical |
| Any other | Any other | Marked as SPAM |The program will display where the email is received in each case. The email belongs to a class called `Email`, which has three string attributes: origin, destination, and subject.
## Implementation
A class named `EmailCheck` is created to build a chain of responsibilities. This class checks each element (part of the chain). If the email is for Management, it informs accordingly. If not, it continues to the next check, which tests if it is for Technical, and so on until it determines the appropriate department or marks the email as spam.
### Tests
JUnit 5 tests are used to ensure the quality of the `setEmail()` method in the `CheckEmail` class. These tests validate that emails are correctly routed to the appropriate departments or marked as spam when necessary.
## How to Run
1. **Clone the repository**:
```sh
git clone https://github.com/vlambo3/ChainOfResponsability---EmailsCheck
```2. **Checkout the desired branch**:
- For development without the pattern:
```sh
git checkout main
```
- For development with the Chain of Responsibility pattern:
```sh
git checkout chain-of-responsibility
```3. **Build and run the project**:
- Ensure you have Java and Maven installed.
- Navigate to the project directory and execute:
```sh
mvn clean install
mvn exec:java -Dexec.mainClass="com.colmena.Main"
```4. **Run tests**:
```sh
mvn test
```## Conclusion
This example demonstrates the application of the Chain of Responsibility pattern in a real-world scenario. The use of JUnit 5 tests ensures that the email processing logic is robust and reliable. By comparing the two branches, developers can understand the benefits and implementation details of the Chain of Responsibility pattern.
## Contact
If you have any questions or need assistance with the project, feel free to contact me:
- **LinkedIn:** [Vanina Godoy](https://www.linkedin.com/in/vanina-a-godoy/?locale=en_US)