Skip to content

Commit bc8ac7a

Browse files
committed
chore: aggiunti integration test per esercizio 2
1 parent 6e789fb commit bc8ac7a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.doubleloop.driverexplicit;
2+
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
7+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
8+
import org.testcontainers.containers.MongoDBContainer;
9+
import org.testcontainers.junit.jupiter.Container;
10+
import org.testcontainers.junit.jupiter.Testcontainers;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
@DataMongoTest
15+
@Testcontainers
16+
class UserRepositoryTest {
17+
18+
@Container
19+
@ServiceConnection
20+
private static MongoDBContainer container = new MongoDBContainer("mongo:latest");
21+
22+
@Autowired
23+
private UserRepository userRepository;
24+
25+
@BeforeEach
26+
void setUp() {
27+
userRepository.deleteAll();
28+
}
29+
30+
@Test
31+
void findByEmailMatch() {
32+
userRepository.save(new User("[email protected]", "test"));
33+
userRepository.save(new User("[email protected]", "test"));
34+
35+
final var result = userRepository.findByEmail("[email protected]");
36+
37+
assertThat(result.isPresent()).isTrue();
38+
assertThat(result.get().getEmail()).isEqualTo("[email protected]");
39+
}
40+
41+
@Test
42+
void findByEmailNotMatch() {
43+
userRepository.save(new User("[email protected]", "test"));
44+
45+
final var result = userRepository.findByEmail("[email protected]");
46+
47+
assertThat(result.isEmpty()).isTrue();
48+
}
49+
}

0 commit comments

Comments
 (0)