A Java application that manages train routes, merging, and station management. The system can create trains, manage their routes, and handle train merging at designated stations.
- 🚂 Train creation and route management
- 🛤️ Dynamic route loading from CSV files
- 🔄 Train merging at designated stations
- 🚉 Station distance and path calculations
- ⚡ Command-based architecture
- 🧪 Comprehensive test coverage
- Java 11
- Gradle
- JUnit 5
- Mockito
src/
├── main/
│ ├── java/com/geektrust/backend/
│ │ ├── commands/ # Command pattern implementations
│ │ ├── entities/ # Domain models
│ │ ├── repositories/ # Data access layer
│ │ ├── services/ # Business logic
│ │ └── exceptions/ # Custom exceptions
│ └── resources/
│ └── *.csv # Route configuration files
└── test/
└── java/com/geektrust/backend/
├── commands/ # Command tests
├── entities/ # Entity tests
├── services/ # Service layer tests
└── resources/ # Test data files
- JDK 11 or higher
- Gradle 7.x or higher
# Clone the repository
git clone <repository-url>
cd anantsaini-india-ME_GEEKTRUST_BACKEND
# Build the project
./gradlew build
# Run tests
./gradlew test# Run with input file
java -jar build/libs/geektrust.jar <path-to-input-file>The application accepts a text file with train configurations. Each line should contain:
TRAIN_NAME ENGINE STATION1 STATION2 ... STATIONN
Example:
TRAIN_A ENGINE NDL NDL GHY NJP NGP
TRAIN_B ENGINE NJP GHY AGA BPL PTA
The application will output train arrivals and departures in the format:
ARRIVAL TRAIN_NAME ENGINE STATION1 STATION2 ... STATIONN
DEPARTURE TRAIN_NAME ENGINE1 ENGINE2 STATION1 STATION2 ... STATIONN
-
Commands
LoadRouteCommand: Loads route data from CSV filesCreateTrainCommand: Creates new train instancesRunTrainTillMergingStationCommand: Handles train movementMergeTrainCommand: Manages train merging operations
-
Services
TrainService: Core business logic for train operationsRouteService: Route management and calculations
-
Repositories
- Implements CRUD operations for entities
- Uses in-memory storage with
ICrudRepositoryinterface
-
Entities
Train: Represents a train with its unitsRoute: Defines a train route with stationsStation: Represents a station with distance infoBogie&Engine: Train unit types
The project includes comprehensive unit tests for all components:
# Run all tests
./gradlew test
# Run specific test class
./gradlew test --tests "com.geektrust.backend.commands.CreateTrainCommandTest"
# Generate test coverage report
./gradlew jacocoTestReportTest reports can be found at build/reports/tests/test/index.html.
- Command Pattern: For executing different train operations
- Repository Pattern: For data access abstraction
- Dependency Injection: For loose coupling between components
- Builder Pattern: For constructing complex objects
The application includes custom exceptions:
NoEngineFoundExceptionRouteNotFoundExceptionNoMergingOrDivergingStationFoundOnRouteException
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for GeekTrust Backend Challenge