Skip to content

Commit 74c9101

Browse files
committed
Spring Boot tests
1 parent a899df5 commit 74c9101

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

springboot-examples/springboot-restapi-testing-all-layers/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<groupId>org.springframework.boot</groupId>
5252
<artifactId>spring-boot-starter-test</artifactId>
5353
</dependency>
54+
5455
<dependency>
5556
<groupId>org.hsqldb</groupId>
5657
<artifactId>hsqldb</artifactId>

springboot-examples/springboot-restapi-testing-all-layers/src/main/java/com/hellokoding/springboot/restful/product/ProductRespository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
import org.springframework.data.jpa.repository.JpaRepository;
44

5+
import java.util.Optional;
6+
57
public interface ProductRespository extends JpaRepository<Product, Long> {
8+
Optional<Product> findByName(String name);
69
}

springboot-examples/springboot-restapi-testing-all-layers/src/test/java/com/hellokoding/springboot/restful/product/ProductRepositoryTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public void setUp(){
3434
testEntityManager.persist(product);
3535
}
3636

37+
@Test
38+
public void whenFindByName_thenReturnProduct() {
39+
// when
40+
Product product = productRespository.findByName("P1").get();
41+
42+
// then
43+
assertThat(product.getDescription()).isEqualTo("P1 desc");
44+
}
45+
3746
@Test
3847
public void whenFindAll_thenReturnProductList() {
3948
// when

0 commit comments

Comments
 (0)