liveBook · Manning

Adapter

As explained in Unit Testing Principles, Practices, and Patterns

A design pattern that presents an application's interface over a different interface supplied by an external component or library.

An adapter places an application-facing interface over a third-party library, translating external complexity into the project’s domain language. It acts as an anti-corruption layer and limits exposure to features the application actually needs. section 9.2

Use adapters to improve maintainability and testing:

  • Mock the adapter your team owns rather than the underlying third-party type. section 9.2
  • Expose only required library behavior, reducing coupling and limiting upgrade-related ripple effects. section 9.2
  • Keep interaction verification at controller boundaries when testing unmanaged dependencies. section 9.3

Message bus wrapper

A CRM application can define its own IBus interface over a message-bus library. Tests mock IBus instead of guessing how the external interface behaves; production code remains insulated from library changes. section 9.2

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines the abstraction, rationale, and maintenance risks, but does not detail adapter implementation.
Examples
Uses an IBus message-bus wrapper and BusSpy or Moq interaction verification.
What it assumes
Assumes familiarity with interfaces, mocking, controllers, and unmanaged dependencies.
What you can do after
Apply it by defining project-owned interfaces over third-party dependencies and mocking those interfaces.
How it connects
Connects adapters with mocking, anti-corruption layers, unmanaged dependencies, controllers, and integration testing.

Also explained in

Compare how 9 books explain adapter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.