A RESTful API service for mathematical operations and geometry calculations developed with Spring Boot. The project is developed with SonarQube code quality analysis and JaCoCo test coverage reporting.
- Features
- Technologies
- Installation
- Usage
- API Endpoints
- Test Coverage
- SonarQube Integration
- Project Structure
- Contributing
- โ Basic Math Operations: Addition, subtraction, multiplication, division
- โ Advanced Mathematics: Power calculation, factorial computation
- โ Geometry Calculations: Circle area, rectangle area, distance between two points
- โ RESTful API: Modern REST API design
- โ Comprehensive Test Coverage: 80%+ line coverage, 70%+ branch coverage
- โ SonarQube Integration: Code quality analysis
- โ JaCoCo Reports: Detailed test coverage reports
- โ Spring Boot DevTools: Hot reload in development environment
- Java 21 - Latest LTS version
- Spring Boot 3.2.5 - Web framework
- Spring Web - RESTful web services
- Spring WebFlux - Reactive programming
- Spring Data REST - REST repository
- Maven - Dependency management
- JUnit 5 - Unit testing
- JaCoCo - Code coverage
- SonarQube - Code quality analysis
- Java 21 or higher
- Maven 3.6 or higher
- SonarQube Server (optional, for code quality analysis)
- Clone the project:
git clone https://github.com/daemonctl/sonar-java-spring.git
cd multi-module-java- Install dependencies:
mvn clean install- Run the application:
mvn spring-boot:run- Generate test coverage report:
mvn clean test jacoco:reportThe application will start running at http://localhost:8080.
You can test the API using the following endpoints in your browser or Postman:
# Addition operation
curl "http://localhost:8080/api/math/add?a=5&b=3"
# Multiplication operation
curl "http://localhost:8080/api/math/multiply?a=4&b=7"
# Circle area calculation
curl "http://localhost:8080/api/math/circle-area?radius=5"| Method | Endpoint | Parameters | Description |
|---|---|---|---|
| GET | /api/math/add |
a, b |
Adds two numbers |
| GET | /api/math/subtract |
a, b |
Subtracts two numbers |
| GET | /api/math/multiply |
a, b |
Multiplies two numbers |
| GET | /api/math/divide |
a, b |
Divides two numbers |
| GET | /api/math/power |
base, exponent |
Power calculation |
| GET | /api/math/factorial |
n |
Factorial calculation |
| Method | Endpoint | Parameters | Description |
|---|---|---|---|
| GET | /api/math/circle-area |
radius |
Circle area calculation |
| GET | /api/math/rectangle-area |
length, width |
Rectangle area |
| GET | /api/math/distance |
x1, y1, x2, y2 |
Distance between two points |
# Addition
GET /api/math/add?a=10&b=5
Response: 15.0
# Factorial
GET /api/math/factorial?n=5
Response: 120
# Circle area
GET /api/math/circle-area?radius=3
Response: 28.274333882308138
# Distance calculation
GET /api/math/distance?x1=0&y1=0&x2=3&y2=4
Response: 5.0The project is developed with high test coverage targets:
- Line Coverage: Minimum 80%
- Branch Coverage: Minimum 70%
# Generate test and coverage report
mvn clean test jacoco:report
# View the report
open target/site/jacoco/index.htmlThe project is configured to perform code quality analysis with SonarQube.
- Start SonarQube server (with Docker):
docker run -d --name sonarqube -p 9000:9000 sonarqube:latest- Analyze the project:
mvn clean verify sonar:sonar- View results:
http://localhost:9000
- Project Key:
java-spring-sonar - Project Name:
java-spring-sonar - Code Coverage: JaCoCo XML reports
- Test Reports: JUnit XML reports
multi-module-java/
โโโ src/
โ โโโ main/
โ โ โโโ java/
โ โ โ โโโ com/turkcell/multimodule/
โ โ โ โโโ MultiModuleJavaApplication.java
โ โ โ โโโ controller/
โ โ โ โ โโโ MathController.java
โ โ โ โโโ service/
โ โ โ โโโ Calculator.java
โ โ โ โโโ MathGeometry.java
โ โ โโโ resources/
โ โ โโโ application.properties
โ โโโ test/
โ โโโ java/
โ โโโ com/turkcell/multimodule/
โ โโโ MultiModuleJavaApplicationTest.java
โ โโโ controller/
โ โ โโโ MathControllerTest.java
โ โโโ service/
โ โโโ CalculatorTest.java
โ โโโ MathGeometryTest.java
โโโ target/
โโโ image/
โโโ pom.xml
โโโ sonar-project.properties
โโโ README.md
- MultiModuleJavaApplication: Spring Boot main class
- MathController: Controller managing REST API endpoints
- Calculator: Basic mathematical operations service
- MathGeometry: Geometry calculations service
# Run all tests
mvn test
# Run a specific test class
mvn test -Dtest=CalculatorTest
# Run tests with coverage
mvn clean test jacoco:report- Add new method to service (
Calculator.javaorMathGeometry.java) - Add endpoint to controller (
MathController.java) - Write unit tests
- Check coverage
- Run SonarQube analysis
- Minimum Line Coverage: 80%
- Minimum Branch Coverage: 70%
- SonarQube Quality Gate: Passed
- No Code Smells: Critical/Major issues
- Fork the project
- Create feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push the branch (
git push origin feature/new-feature) - Create Pull Request
- Code coverage should not fall below 80%
- All tests must pass
- SonarQube quality gate must pass
- Code should include English comment lines
This project is licensed under the MIT License. See LICENSE file for details.
- Developer: Korhan Herguner
- Email: korhanherguner@gmail.com
- LinkedIn: Korhan Herguner
- Project URL: https://github.com/daemonctl/sonar-java-spring
โญ If you like this project, don't forget to give it a star!


