forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractStorageTest.java
More file actions
157 lines (131 loc) · 5.03 KB
/
AbstractStorageTest.java
File metadata and controls
157 lines (131 loc) · 5.03 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.urise.webapp.storage;
import com.urise.webapp.exception.ExistStorageException;
import com.urise.webapp.exception.NotExistStorageException;
import com.urise.webapp.model.*;
import org.junit.Before;
import org.junit.Test;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
public abstract class AbstractStorageTest {
private static final String UUID_1 = "UUID_1";
private static final String UUID_2 = "UUID_2";
private static final String UUID_3 = "UUID_3";
private static final String UUID_4 = "UUID_4";
private static final Resume R_1 = new Resume(UUID_1, "FullName_1");
private static final Resume R_2 = new Resume(UUID_2, "FullName_2");
private static final Resume R_3 = new Resume(UUID_3, "FullName_3");
private static final Resume R_4 = new Resume(UUID_4, "FullName_4");
static {
<<<<<<< HEAD
ResumeDataTest.fillResumeSections(R_1,3,3,3,3);
ResumeDataTest.fillResumeSections(R_2,4,4,4,4);
ResumeDataTest.fillResumeSections(R_3,5,5,5,5);
ResumeDataTest.fillResumeSections(R_4,6,6,6,6);
=======
List<Organization> organizationList = new ArrayList<>();
organizationList.add(new Organization("JOB_1", "http://job_1.org",
LocalDate.of(2001, 01, 30),
LocalDate.of(2002, 01, 30),
"Title1",
"description1"));
organizationList.add(new Organization("JOB_2", "http://job_2.org",
LocalDate.of(2001, 01, 30),
LocalDate.of(2002, 01, 30),
"Title2",
"description2"));
R_1.addSection(SectionType.PERSONAL, new TextSection("This is describing string of myown!"));
R_1.addSection(SectionType.OBJECTIVE, new TextSection("This is describing string of willing position!"));
List<String> qualifications = new ArrayList<>();
qualifications.add("This is string №" + 0 + " describing qualifications!");
R_1.addSection(SectionType.QUALIFICATIONS, new ListSection(qualifications));
List<String> achivements = new ArrayList<>();
achivements.add("This is string №" + 0 + " describing achievements!");
R_1.addSection(SectionType.ACHIEVEMENT, new ListSection(achivements));
R_1.addSection(SectionType.EXPIRIENCE, new OrganizationSection(organizationList));
List<Organization> educationList = new ArrayList<>();
educationList.add(new Organization("VUZ_1", "http://vuz_1.org",
LocalDate.of(2001, 01, 30),
LocalDate.of(2002, 01, 30),
"Title1",
"description1"));
educationList.add(new Organization("VUZ_2", "http://vuz_2.org",
LocalDate.of(2001, 01, 30),
LocalDate.of(2002, 01, 30),
"Title2",
"description2"));
R_1.addSection(SectionType.EDUCATION, new OrganizationSection(educationList));
>>>>>>> lesson 8.
}
protected Storage storage;
protected AbstractStorageTest(Storage storage) {
this.storage = storage;
}
@Before
public void setUp() {
storage.clear();
storage.save(R_1);
storage.save(R_2);
storage.save(R_3);
}
@Test
public void clear() {
storage.clear();
assertEquals(0, storage.size());
}
@Test(expected = ExistStorageException.class)
public void saveExist() {
storage.save(R_3);
}
@Test
public void saveNotExist() {
int sizeBefore = storage.size();
storage.save(R_4);
assertEquals(sizeBefore + 1, storage.size());
assertEquals(R_4, storage.get(UUID_4));
}
@Test
public void getExist() {
assertEquals(R_1, storage.get(UUID_1));
assertEquals(R_2, storage.get(UUID_2));
assertEquals(R_3, storage.get(UUID_3));
}
@Test(expected = NotExistStorageException.class)
public void getNotExist() {
storage.get("notExistableUUID");
}
@Test(expected = NotExistStorageException.class)
public void deleteExist() {
int sizeBefore = storage.size();
storage.delete(UUID_1);
assertEquals(sizeBefore - 1, storage.size());
storage.get(UUID_1);
}
@Test(expected = NotExistStorageException.class)
public void deleteNotExist() {
storage.delete("notExistableUUID");
}
@Test
public void getAllSorted() {
assertEquals(Arrays.asList(R_1, R_2, R_3), storage.getAllSorted());
}
@Test
public void size() {
assertEquals(3, storage.size());
}
@Test
public void updateExist() {
Resume rBefore = storage.get(UUID_1);
Resume rAfter = new Resume(UUID_1, "FullName_1");
storage.update(rAfter);
assertNotSame(storage.get(UUID_1), rBefore);
}
@Test(expected = NotExistStorageException.class)
public void updateNotExist() {
Resume rAfter = new Resume("test");
storage.update(rAfter);
}
}