The order service has a reservation finalization method. It must work in a simple in-memory scenario without a database or external libraries.
Context and requirements:
javac *.java && java Demo.LoyaltyGateway interface. It can complete successfully or with an error.Public contract of ReservationService.finalizeReservation:
reservationId, customerId, usePoints.reservationId is already finalized, a repeated call must return the already stored result and must not perform the external charge again.usePoints == false, the method must simply save the finalized reservation with status CONFIRMED.usePoints == true, external points charging must be called only after the finalized reservation has been saved.POINTS_FAILED, but the finalization record must still remain saved.Below is the PR change. A review is needed to find defects in the after version. The analysis must rely on the requirements above and the reproducible behavior from the code.
Java 21, standard library, no third-party dependencies. javac *.java && java Demo is sufficient. It is assumed that all files are in the same directory and packages are not used.
Use line comments to explain the problem, its impact, the fix and how to test it.