Skip to content
Ameen Abozaid
Planned lessonJNR-044-L06

Demo: mocking the payment gateway's three outcomes

  • Lesson 6 of 6
  • Junior
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

  1. Create an in-memory fake OrderRepository.
  2. Mock PaymentGateway; stub an approval and assert the order is PAID.
  3. Stub a decline and assert the order is PAYMENT_FAILED.
  4. Stub thenThrow(new GatewayTimeoutException()) and assert the order stays PENDING.
  5. 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.