Skip to content

Commit 0bf7bc1

Browse files
committed
Update author test
1 parent c37942e commit 0bf7bc1

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

jdbi/src/main/java/zin/rashidi/boot/jdbi/book/AuthorReadOnlyRepository.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ interface AuthorReadOnlyRepository {
1818
@SqlQuery("SELECT * FROM author")
1919
Stream<Author> findAll();
2020

21-
@SqlQuery("SELECT * FROM author WHERE id = :id")
22-
Optional<Author> findById(@Bind("id") Long id);
23-
2421
@SqlQuery("SELECT * FROM author WHERE name = :name")
2522
Stream<Author> findByName(@Bind("name") String name);
2623

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
package 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;
54
import org.junit.jupiter.api.Test;
65
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
8-
import org.springframework.boot.test.autoconfigure.data.jdbc.AutoConfigureDataJdbc;
96
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
107
import org.springframework.boot.test.context.SpringBootTest;
11-
import org.springframework.context.annotation.ComponentScan;
12-
import org.springframework.context.annotation.ComponentScan.Filter;
138
import org.springframework.context.annotation.Import;
149
import org.springframework.test.context.jdbc.Sql;
1510
import org.springframework.transaction.annotation.Transactional;
1611
import zin.rashidi.boot.jdbi.TestcontainersConfiguration;
1712

13+
import static org.assertj.core.api.Assertions.assertThat;
1814
import 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)
2825
class 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
}

jdbi/src/test/resources/schema.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ CREATE TABLE book
1212
CONSTRAINT fk_author
1313
FOREIGN KEY (author_id)
1414
REFERENCES author (id)
15-
);
15+
);
16+
17+
INSERT INTO author (name) VALUES ('Sun Tzu');

0 commit comments

Comments
 (0)