Replacing Troublesome Behavior with Stubs

Learn the implementation and use cases of stubs.

We'll cover the following

Let’s focus first on verifying how we populate an Address using the JSON response from the Http call. To do that, we’d like to change the behavior of HttpImpl’s get() method for purposes of the test so that it returns a hardcoded JSON string.

stub

An implementation that returns a hard-coded value for the purposes of testing is known as a stub.

The HttpImpl implements the functional Http interface. Let’s create a stub implementation dynamically using lambda functions:

Get hands-on with 1200+ tech skills courses.