Skip to content

Commit 845c73f

Browse files
committed
Extracted method: CountryServiceTest.getCountry() -> TestObjects.createCountry()
No functional changes.
1 parent e22acd3 commit 845c73f

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

src/test/java/ru/mystamps/web/service/CountryServiceTest.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package ru.mystamps.web.service;
1919

20-
import java.util.Date;
2120
import java.util.ArrayList;
2221
import java.util.List;
2322

@@ -48,9 +47,6 @@
4847
@RunWith(MockitoJUnitRunner.class)
4948
public class CountryServiceTest {
5049

51-
private static final Integer TEST_COUNTRY_ID = 1;
52-
private static final String TEST_COUNTRY_NAME = "Somewhere";
53-
5450
@Mock
5551
private CountryDao countryDao;
5652

@@ -94,7 +90,7 @@ public void addShouldThrowExceptionWhenUserIsNull() {
9490

9591
@Test
9692
public void addShouldCallDao() {
97-
Country expected = getCountry();
93+
Country expected = TestObjects.createCountry();
9894
when(countryDao.save(any(Country.class))).thenReturn(expected);
9995

10096
Country actual = service.add(form, user);
@@ -164,11 +160,11 @@ public void addShouldAssignUpdatedByToUser() {
164160
public void findAllShouldCallDao() {
165161
List<Country> expectedCountries = new ArrayList<Country>();
166162

167-
Country country1 = getCountry();
163+
Country country1 = TestObjects.createCountry();
168164
country1.setName("First Country");
169165
expectedCountries.add(country1);
170166

171-
Country country2 = getCountry();
167+
Country country2 = TestObjects.createCountry();
172168
country2.setName("Second Country");
173169
expectedCountries.add(country2);
174170

@@ -190,7 +186,7 @@ public void findByNameShouldThrowExceptionWhenNameIsNull() {
190186

191187
@Test
192188
public void findByNameShouldCallDao() {
193-
Country expectedCountry = getCountry();
189+
Country expectedCountry = TestObjects.createCountry();
194190
when(countryDao.findByName(anyString())).thenReturn(expectedCountry);
195191

196192
Country country = service.findByName("Any name here");
@@ -205,14 +201,4 @@ public void findByNameShouldPassCountryNameToDao() {
205201
verify(countryDao).findByName(eq("Canada"));
206202
}
207203

208-
static Country getCountry() {
209-
Country country = new Country();
210-
country.setId(TEST_COUNTRY_ID);
211-
country.setName(TEST_COUNTRY_NAME);
212-
Date now = new Date();
213-
country.getMetaInfo().setCreatedAt(now);
214-
country.getMetaInfo().setUpdatedAt(now);
215-
return country;
216-
}
217-
218204
}

src/test/java/ru/mystamps/web/service/SeriesServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void addShouldPassEntityToSeriesDao() {
132132

133133
@Test
134134
public void addShouldLoadAndPassCountryToSeriesDaoIfCountryPresent() {
135-
Country expectedCountry = CountryServiceTest.getCountry();
135+
Country expectedCountry = TestObjects.createCountry();
136136

137137
form.setCountry(expectedCountry);
138138

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2009-2013 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.service;
19+
20+
import java.util.Date;
21+
22+
import ru.mystamps.web.entity.Country;
23+
24+
final class TestObjects {
25+
26+
private static final Integer TEST_COUNTRY_ID = 1;
27+
private static final String TEST_COUNTRY_NAME = "Somewhere";
28+
29+
private TestObjects() {
30+
}
31+
32+
public static Country createCountry() {
33+
Country country = new Country();
34+
country.setId(TEST_COUNTRY_ID);
35+
country.setName(TEST_COUNTRY_NAME);
36+
Date now = new Date();
37+
country.getMetaInfo().setCreatedAt(now);
38+
country.getMetaInfo().setUpdatedAt(now);
39+
return country;
40+
}
41+
42+
}

0 commit comments

Comments
 (0)