Skip to content

Commit 6b82c16

Browse files
committed
CountryService.getStatisticsOf(): change argument from Collection to Integer.
Addressed to #120 No functional changes.
1 parent 80509b3 commit 6b82c16

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

src/main/java/ru/mystamps/web/controller/CollectionController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public String showInfo(
8282
);
8383
model.addAttribute(
8484
"statOfCollectionByCountries",
85-
getCountriesStatistics(collection, lang)
85+
getCountriesStatistics(collection.getId(), lang)
8686
);
8787
}
8888

@@ -91,8 +91,8 @@ public String showInfo(
9191

9292
// false positive
9393
@SuppressWarnings("PMD.UnusedPrivateMethod")
94-
private Map<String, Integer> getCountriesStatistics(Collection collection, String lang) {
95-
Map<String, Integer> countriesStat = countryService.getStatisticsOf(collection, lang);
94+
private Map<String, Integer> getCountriesStatistics(Integer collectionId, String lang) {
95+
Map<String, Integer> countriesStat = countryService.getStatisticsOf(collectionId, lang);
9696

9797
// manually localize "Unknown" country's name
9898
if (countriesStat.containsKey("Unknown")) {

src/main/java/ru/mystamps/web/service/CountryService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.Map;
2121

22-
import ru.mystamps.web.entity.Collection;
2322
import ru.mystamps.web.entity.User;
2423
import ru.mystamps.web.service.dto.AddCountryDto;
2524
import ru.mystamps.web.service.dto.LinkEntityDto;
@@ -34,5 +33,5 @@ public interface CountryService {
3433
long countCountriesOf(Integer collectionId);
3534
long countByName(String name);
3635
long countByNameRu(String name);
37-
Map<String, Integer> getStatisticsOf(Collection collection, String lang);
36+
Map<String, Integer> getStatisticsOf(Integer collectionId, String lang);
3837
}

src/main/java/ru/mystamps/web/service/CountryServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import ru.mystamps.web.dao.JdbcCountryDao;
3535
import ru.mystamps.web.dao.dto.AddCountryDbDto;
36-
import ru.mystamps.web.entity.Collection;
3736
import ru.mystamps.web.entity.User;
3837
import ru.mystamps.web.service.dto.AddCountryDto;
3938
import ru.mystamps.web.service.dto.LinkEntityDto;
@@ -123,11 +122,10 @@ public long countByNameRu(String name) {
123122

124123
@Override
125124
@Transactional(readOnly = true)
126-
public Map<String, Integer> getStatisticsOf(Collection collection, String lang) {
127-
Validate.isTrue(collection != null, "Collection must be non null");
128-
Validate.isTrue(collection.getId() != null, "Collection id must be non null");
125+
public Map<String, Integer> getStatisticsOf(Integer collectionId, String lang) {
126+
Validate.isTrue(collectionId != null, "Collection id must be non null");
129127

130-
return countryDao.getStatisticsOf(collection.getId(), lang);
128+
return countryDao.getStatisticsOf(collectionId, lang);
131129
}
132130

133131
}

src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import spock.lang.Unroll
2222

2323
import ru.mystamps.web.dao.JdbcCountryDao
2424
import ru.mystamps.web.dao.dto.AddCountryDbDto
25-
import ru.mystamps.web.entity.Collection
2625
import ru.mystamps.web.entity.User
2726
import ru.mystamps.web.model.AddCountryForm
2827
import ru.mystamps.web.service.dto.LinkEntityDto
@@ -361,19 +360,9 @@ class CountryServiceImplTest extends Specification {
361360
// Tests for getStatisticsOf()
362361
//
363362

364-
def "getStatisticsOf() should throw exception when collection is null"() {
365-
when:
366-
service.getStatisticsOf(null, 'whatever')
367-
then:
368-
thrown IllegalArgumentException
369-
}
370-
371363
def "getStatisticsOf() should throw exception when collection id is null"() {
372-
given:
373-
Collection collection = Mock()
374-
collection.getId() >> null
375364
when:
376-
service.getStatisticsOf(collection, 'whatever')
365+
service.getStatisticsOf(null, 'whatever')
377366
then:
378367
thrown IllegalArgumentException
379368
}
@@ -383,11 +372,8 @@ class CountryServiceImplTest extends Specification {
383372
Integer expectedCollectionId = 17
384373
and:
385374
String expectedLang = 'expected'
386-
and:
387-
Collection expectedCollection = Mock()
388-
expectedCollection.getId() >> expectedCollectionId
389375
when:
390-
service.getStatisticsOf(expectedCollection, expectedLang)
376+
service.getStatisticsOf(expectedCollectionId, expectedLang)
391377
then:
392378
1 * countryDao.getStatisticsOf(
393379
{ Integer collectionId ->

0 commit comments

Comments
 (0)