Support mocking of stripe outbound RPCs for unit tests

Open
#1,453 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
api

Research direction

The current entry point is the static Customer.create(customerCreateParamsObj) call; compare it with the requested stripeFactoryObj.customerService().create(...) design and inspect how StripeMock handles outbound requests. Completion means providing a constructor- or factory-based API that can be supplied through DI and mocked or verified without StripeMock.

Written by the indexing model from the issue text.

Description

feature-request future
Is your feature request related to a problem? Please describe.

When writing unit tests, there is a need to avoid outbound RPCs to another server. Today the Stripe API uses static methods and global (or request) config parameters, but there does not seem to be a way to mock the request/verify the request without running StripeMock, which is perhaps too large for a java unit test.

Describe the solution you'd like

If there was a constructor/factory based approach to constructing the stripe api, then we would be able to mock this away in our DI layer.

Today

Customer.create(customerCreateParamsObj);

Desirable alternatives

stripeFactoryObj.customerService().create(customerCreateParamsObj);

In my code I would likely provide CustomerService via DI, and then call like such:

customerService.create(customerCreateParamsObj);

This way I would be able to provide a Mockito implementation for CustomerService and setup mocks/verifications.

Describe alternatives you've considered

My solution until this is supported will be to wrap every Stripe API in a class/method and indirectly call the stripe API.

Alternatively it seems clients could use Mockito to mock static methods, though this approach is less desirable.

Additional context

No response

Dominant language
Java
Stars
1k
Forks
406
Avg merge
2d 18h
Merged PRs (30d)
20

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stripe/stripe-java

All issues in stripe/stripe-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.