Skip to content

Commit 93f8074

Browse files
committed
added missing test classes
1 parent 5ecb279 commit 93f8074

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.reflectoring.testing.persistence;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
7+
import org.springframework.test.context.TestPropertySource;
8+
import org.springframework.test.context.junit.jupiter.SpringExtension;
9+
10+
@ExtendWith(SpringExtension.class)
11+
@DataJpaTest
12+
@TestPropertySource(properties = {
13+
"spring.jpa.hibernate.ddl-auto=validate",
14+
"spring.liquibase.enabled=false",
15+
"spring.flyway.enabled=true"
16+
})
17+
class FlywayTest {
18+
19+
@Test
20+
void databaseHasBeenInitialized() {
21+
22+
}
23+
24+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.reflectoring.testing.persistence;
2+
3+
import javax.persistence.EntityManager;
4+
import javax.sql.DataSource;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.extension.ExtendWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
10+
import org.springframework.jdbc.core.JdbcTemplate;
11+
import org.springframework.test.context.TestPropertySource;
12+
import org.springframework.test.context.junit.jupiter.SpringExtension;
13+
import static org.assertj.core.api.Assertions.*;
14+
15+
@ExtendWith(SpringExtension.class)
16+
@DataJpaTest
17+
@TestPropertySource(properties = {
18+
"spring.jpa.hibernate.ddl-auto=create-drop",
19+
"spring.flyway.enabled=false"
20+
})
21+
class HibernateTest {
22+
23+
@Autowired
24+
private UserRepository userRepository;
25+
26+
@Autowired
27+
private DataSource dataSource;
28+
29+
@Autowired
30+
private JdbcTemplate jdbcTemplate;
31+
32+
@Autowired
33+
private EntityManager entityManager;
34+
35+
@Test
36+
void injectedComponentsAreNotNull() {
37+
assertThat(dataSource).isNotNull();
38+
assertThat(jdbcTemplate).isNotNull();
39+
assertThat(entityManager).isNotNull();
40+
assertThat(userRepository).isNotNull();
41+
}
42+
43+
@Test
44+
void stateIsNotShared1() {
45+
assertThat(userRepository.findByName("user2")).isNull();
46+
userRepository.save(new UserEntity("user1", "mail1"));
47+
}
48+
49+
@Test
50+
void stateIsNotShared2() {
51+
assertThat(userRepository.findByName("user1")).isNull();
52+
userRepository.save(new UserEntity("user2", "mail2"));
53+
}
54+
55+
@Test
56+
void whenSaved_thenFindsByName() {
57+
userRepository.save(new UserEntity(
58+
"Zaphod Beeblebrox",
59+
60+
assertThat(userRepository.findByName("Zaphod Beeblebrox")).isNotNull();
61+
}
62+
63+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.reflectoring.testing.persistence;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
6+
import org.springframework.test.context.TestPropertySource;
7+
import org.springframework.test.context.junit.jupiter.SpringExtension;
8+
9+
@ExtendWith(SpringExtension.class)
10+
@DataJpaTest
11+
@TestPropertySource(properties = {
12+
"spring.jpa.hibernate.ddl-auto=validate",
13+
"spring.liquibase.enabled=true",
14+
"spring.flyway.enabled=false"
15+
})
16+
class LiquibaseTest {
17+
18+
@Test
19+
void databaseHasBeenInitialized() {
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)