This project involves extending an existing Java application for simulating horse races by adding robust testing and logging capabilities. The solution ensures high code quality with comprehensive test coverage and detailed logs for debugging and analysis. Also use GitHub Actions for checking the completion of the test, logging information and build process.
-
JUnit 5: Added unit and integration tests for the following classes:
- Horse:
- Constructor validation (null, blank strings, negative speed/distance).
- Methods:
getName,getSpeed,getDistance,move.
- Hippodrome:
- Constructor validation (null or empty horse list).
- Methods:
getHorses,move,getWinner.
- Main:
- Execution time test with
@Timeout(disabled by default).
- Execution time test with
- Horse:
-
Parameterized Tests: Used for scenarios requiring multiple inputs (e.g., different whitespace values in Horse constructor).
-
Mocking: Leveraged
MockedStaticfor mocking static methods such asgetRandomDouble.
-
Log4j2 with SLF4J: Implemented structured logging with YAML configuration.
- Logs written to
logs/hippodrome.logwith daily rolling and retention of up to 7 days. - Log levels:
- INFO: Main application flow (e.g., race start/end, winner).
- ERROR: Constructor validation failures.
- DEBUG: Object creation details.
- Logs written to
-
Log Structure Examples:
INFO Main: Race started with 7 participants.INFO Main: Race ended. Winner: Cherry.ERROR Hippodrome: Horses list is null.DEBUG Horse: Created Horse, name [Lobster], speed [2.8].
- RollingFile Appender:
- Log file format:
hippodrome.<date>.log. - Rotation policy: Daily.
- Retention policy: Deletes files older than 7 days.
- Example YAML snippet:
Configuration: status: all appenders: RollingFile: name: RollingFile fileName: logs/hippodrome.log filePattern: logs/hippodrome.%d{yyyy-MM-dd}.log PatternLayout: pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" Policies: TimeBasedTriggeringPolicy: interval: 1 modulate: true DefaultRolloverStrategy: Delete: basePath: logs ifLastModified: 7d ifFileName: "hippodrome-*.log"
- Example YAML snippet:
- Log file format:
- Unit Tests: All specified tests implemented and passing, ensuring validation and method functionality.
- Logging: Logs provide a clear and detailed trace of application behavior, aiding in debugging and monitoring.
- Reusable Configuration: Log4j2 YAML configuration ensures maintainability and scalability for future enhancements.
-
Clone the repository:
git clone <repository-url> cd hippodrome
-
Install dependencies and build the project:
mvn clean install
-
Run the application:
java -jar target/hippodrome.jar
-
View logs:
- Current logs:
logs/hippodrome.log - Archived logs:
logs/hippodrome.<date>.log
- Current logs:
This README outlines the added functionality, ensuring the project meets all specified requirements for testing and logging. Feel free to suggest further refinements!