11package zin .rashidi .boot .jdbi .book ;
22
3- import org .assertj .core .api .Assertions ;
4- import org .jdbi .v3 .spring .EnableJdbiRepositories ;
3+ import org .junit .jupiter .api .DisplayName ;
54import org .junit .jupiter .api .Test ;
65import org .springframework .beans .factory .annotation .Autowired ;
7- import org .springframework .boot .autoconfigure .ImportAutoConfiguration ;
8- import org .springframework .boot .test .autoconfigure .data .jdbc .AutoConfigureDataJdbc ;
96import org .springframework .boot .test .autoconfigure .jdbc .AutoConfigureTestDatabase ;
107import org .springframework .boot .test .context .SpringBootTest ;
11- import org .springframework .context .annotation .ComponentScan ;
12- import org .springframework .context .annotation .ComponentScan .Filter ;
138import org .springframework .context .annotation .Import ;
149import org .springframework .test .context .jdbc .Sql ;
1510import org .springframework .transaction .annotation .Transactional ;
1611import zin .rashidi .boot .jdbi .TestcontainersConfiguration ;
1712
13+ import static org .assertj .core .api .Assertions .assertThat ;
1814import static org .springframework .boot .test .context .SpringBootTest .WebEnvironment .NONE ;
15+ import static org .springframework .test .context .jdbc .Sql .ExecutionPhase .BEFORE_TEST_CLASS ;
1916
2017/**
2118 * @author Rashidi Zin
2219 */
20+ @ SpringBootTest (webEnvironment = NONE )
2321@ Import (TestcontainersConfiguration .class )
2422@ AutoConfigureTestDatabase
2523@ Transactional
26- @ SpringBootTest (webEnvironment = NONE )
27- @ Sql (scripts = "classpath:schema.sql" )
24+ @ Sql (scripts = "classpath:schema.sql" , executionPhase = BEFORE_TEST_CLASS )
2825class AuthorReadOnlyRepositoryTests {
2926
3027 @ Autowired
3128 private AuthorReadOnlyRepository authors ;
3229
3330 @ Test
31+ @ DisplayName ("Given is only one author, When I search for all authors, Then I should get one author" )
3432 void findAll () {
35- Assertions .assertThat (authors .findAll ()).hasSize (1 );
36- }
37-
38- @ Test
39- void findById () {
33+ assertThat (authors .findAll ())
34+ .hasSize (1 )
35+ .extracting ("name" ).containsOnly ("Sun Tzu" );
4036 }
4137
4238 @ Test
39+ @ DisplayName ("Given there is an author named Sun Tzu, When I search by the name, Then the result should have size of one" )
4340 void findByName () {
41+ assertThat (authors .findByName ("Sun Tzu" )).hasSize (1 );
4442 }
4543
4644}
0 commit comments