-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathContactServiceTest.java
55 lines (44 loc) · 1.96 KB
/
ContactServiceTest.java
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
package com.pik.contact.service.integration;
import com.pik.contact.Application;
import com.pik.contact.domain.Contact;
import com.pik.contact.service.ContactService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@DirtiesContext
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class ContactServiceTest {
@Autowired
private ContactService contactService;
@Before
public void tearDown() {
contactService.deleteAllContacts();
}
@Test
public void saves_new_contact() {
//given
Contact contact = new Contact("John", "Doe", "Developer", "jdoe@company.com", "123 456 7890", "jdoe90");
//when
Contact savedContact = contactService.saveContact(contact);
//then
assertThat(contactService.load(savedContact.getId())).isEqualTo(contact);
}
@Test
public void finds_contacts_by_name() {
Contact contact1 = contactService.saveContact(new Contact("John", "Doe", "Developer", "jdoe@company.com", "123 456 7890", "jdoe90"));
Contact contact2 = contactService.saveContact(new Contact("Johnny", "Smith", "Developer", "smith@company.com", "123 456 7890", "smith90"));
Contact contact3 = contactService.saveContact(new Contact("Bob", "Smith", "Developer", "bob@company.com", "123 456 7890", "bobbb90"));
List<Contact> contacts = contactService.searchContacts("John");
assertThat(contacts).containsOnly(contact1, contact2);
}
}