Testing a persistence adapter with integration tests
For a similar reason, it makes sense to cover persistence adapters with integration tests instead of unit tests since we not only want to verify the logic within the adapter but also the mapping into the database.
We want to test the persistence adapter we built in Chapter 7, Implementing a Persistence Adapter. The adapter has two methods, one to load an Account entity from the database and another to save new account activities to the database:
With @DataJpaTest, we tell Spring to instantiate the network of objects that are needed for database access, including our Spring Data repositories that connect to the database. We use the @Import annotation to import some additional configurations to make sure that certain objects are added to that network. These objects are needed by the adapter under test to map incoming domain objects into database objects, for instance.
In the test for the loadAccount...