Implementing the WordRepository adapter
In this section, we will use the popular database library JDBI to implement the fetchWordByNumber()
method of interface WordRepository
and make our failing integration test pass.
Hexagonal architectures were covered in Chapter 9, Hexagonal Architecture – Decoupling External Systems. An external system like a database is accessed through a port in the domain model. The code that is specific to that external system is contained in an adapter. Our failing test enables us to write the database access code to fetch a word to guess.
A little bit of database design thinking needs to be done before we begin writing code. For the task at hand, it is enough to note that we will store all available words to guess in a database table named word
. This table will have two columns. There will be a primary key named word_number
and a five-letter word in a column named word
.
Let’s test-drive this out:
- Run the test to reveal that...