-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomerTest.java
More file actions
68 lines (56 loc) · 1.99 KB
/
CustomerTest.java
File metadata and controls
68 lines (56 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.onemount.demo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.jdbc.Sql;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Optional;
import com.onemount.demo.repository.CustomerRepository;
import com.onemount.demo.model.Customer;
@DataJpaTest
@Sql({"/Customer.sql"})
public class CustomerTest {
@Autowired
private CustomerRepository customerRepository;
@Test
public void getCustomerCount(){
assertThat(customerRepository.count()).isGreaterThan(10);
}
@Test
public void addCustomer() {
Customer customer = new Customer("Nguyen", "Dong", "example@gmail.com", "0988777666", "Developer");
customerRepository.save(customer);
Optional<Customer> optional = customerRepository.findByEmail("example@gmail.com");
if (optional.isPresent()) {
assertThat(optional.get()).extracting("lastName").isEqualTo("Dong");
}
}
@Test
public void getCustomerById() {
Optional<Customer> optional = customerRepository.findById(1L);
if (optional.isPresent()) {
assertThat(optional.get()).extracting("lastName").isEqualTo("Moff");
}
}
@Test
public void getCustomerByEmail() {
Optional<Customer> optional = customerRepository.findByEmail("cmoff0@java.com");
if (optional.isPresent()) {
assertThat(optional.get()).extracting("lastName").isEqualTo("Moff");
}
}
@Test
public void getCustomerByJob() {
List<Customer> list = customerRepository.findByJob("Human Resources Assistant II");
if (list.size() > 0) {
assertThat(list.get(0)).extracting("job").isEqualTo("Human Resources Assistant II");
}
}
@Test
public void delete() {
customerRepository.deleteById(2L);
Optional<Customer> optional = customerRepository.findById(2L);
assertThat(optional.isPresent()).isEqualTo(false);
}
}