https://github.com/testsmith-io/java-coffee-machine-unit-testing
☕ Coffee Machine Simulator - Java Coffee Machine Unit Testing
https://github.com/testsmith-io/java-coffee-machine-unit-testing
jacoco java testing unit
Last synced: 3 days ago
JSON representation
☕ Coffee Machine Simulator - Java Coffee Machine Unit Testing
- Host: GitHub
- URL: https://github.com/testsmith-io/java-coffee-machine-unit-testing
- Owner: testsmith-io
- Created: 2025-02-20T18:59:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-13T11:40:07.000Z (about 1 year ago)
- Last Synced: 2026-03-12T03:56:04.298Z (4 months ago)
- Topics: jacoco, java, testing, unit
- Language: Java
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ☕ Coffee Machine Simulator - Java Coffee Machine Unit Testing
A **Java-based coffee machine simulation**, designed with **Object-Oriented Programming (OOP)** principles, **custom exceptions**, and **100% unit test coverage** using **JUnit & JaCoCo** (Java Code Coverage). This project includes a **CI/CD pipeline with GitHub Actions** to ensure high code quality.
## 🚀 Features
✅ Supports multiple **coffee types**: `Espresso`, `Latte`, `Cappuccino`, etc.
✅ **Encapsulation & Abstraction** for reservoirs (**water, beans, milk**)
✅ **Custom exceptions** for resource shortages
✅ **100% unit test coverage** with **JaCoCo**
✅ **Mockito-powered tests** for mocking dependencies
✅ **Automated testing & coverage reporting** via **GitHub Actions**
## 📁 Project Structure
```
io.testsmith.coffeemachine
│── enums
│ ├── CoffeeType.java # Menu of coffee types
│── exceptions
│ ├── InsufficientBeansException.java
│ ├── InsufficientWaterException.java
│ ├── InsufficientMilkException.java
│── models
│ ├── AbstractReservoir.java # Base class for reservoirs
│ ├── WaterTank.java # Water container
│ ├── BeanReservoir.java # Bean container
│ ├── MilkReservoir.java # Milk container
├── CoffeeMachine.java # Main coffee machine logic
│── tests
│ ├── CoffeeMachineTest.java # Unit tests with Mockito
```
---
## ⚙️ Installation & Setup
### 1️⃣ Clone the Repository
```sh
git clone https://github.com/testsmith-io/java-coffee-machine-unit-testing.git
cd java-coffee-machine-unit-testing
```
### 2️⃣ Run Tests
```sh
mvn clean test
```
### 3️⃣ Generate Code Coverage Report
```sh
mvn jacoco:report
```
- **View Report:** Open `target/site/jacoco/index.html` in a browser.
### 4️⃣ Generate Code Coverage Report
```sh
mvn test-compile org.pitest:pitest-maven:mutationCoverage
```
- **View Report:** Open `target/pit-reports/index.html` in a browser.
## ☕ Coffee Menu
The machine can brew the following **coffee types**, with predefined **water, bean, and milk requirements**:
| Coffee Type | Water (ml) | Beans (g) | Milk (ml) |
|------------------|------------|----------|-----------|
| **Espresso** | 100 | 30 | 0 |
| **Double Espresso** | 150 | 40 | 0 |
| **Coffee** | 200 | 20 | 0 |
| **Latte** | 150 | 20 | 100 |
| **Cappuccino** | 100 | 25 | 150 |
| **Macchiato** | 100 | 15 | 50 |
## 🛠 CI/CD - Automated Testing
This project uses **GitHub Actions** to automate testing and coverage reporting.
Every push & pull request triggers:
- **JUnit Tests**
- **JaCoCo Code Coverage Report**
- **Test Artifacts Upload**
### 📄 GitHub Actions Workflow
[.github/workflows/ci.yml](.github/workflows/ci.yml)
### ⭐ Enjoy your coffee! 🚀