Demo: mocking the payment gateway's three outcomes
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
test OrderService for success, decline, and timeout. Prepares JNR-044-LAB1.
Draft outline details
Step by step
- Create an in-memory fake
OrderRepository. - Mock
PaymentGateway; stub an approval and assert the order isPAID. - Stub a decline and assert the order is
PAYMENT_FAILED. - Stub
thenThrow(new GatewayTimeoutException())and assert the order staysPENDING. - Planned mistake: verify five internal calls; then rename a private method and watch the test break for no good reason. Fix by asserting on results.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.