Skip to content

Commit e7397b0

Browse files
committed
CategoryService.getStatisticsOf(): change argument from Collection to Integer.
Addressed to #120 No functional changes.
1 parent c330118 commit e7397b0

File tree

4 files changed

+7
-24
lines changed

4 files changed

+7
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public String showInfo(
7878

7979
model.addAttribute(
8080
"statOfCollectionByCategories",
81-
categoryService.getStatisticsOf(collection, lang)
81+
categoryService.getStatisticsOf(collection.getId(), lang)
8282
);
8383
model.addAttribute(
8484
"statOfCollectionByCountries",

src/main/java/ru/mystamps/web/service/CategoryService.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.AddCategoryDto;
2524
import ru.mystamps.web.service.dto.LinkEntityDto;
@@ -34,5 +33,5 @@ public interface CategoryService {
3433
long countCategoriesOf(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/CategoryServiceImpl.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.JdbcCategoryDao;
3535
import ru.mystamps.web.dao.dto.AddCategoryDbDto;
36-
import ru.mystamps.web.entity.Collection;
3736
import ru.mystamps.web.entity.User;
3837
import ru.mystamps.web.service.dto.AddCategoryDto;
3938
import ru.mystamps.web.service.dto.LinkEntityDto;
@@ -122,11 +121,10 @@ public long countByNameRu(String name) {
122121

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

129-
return categoryDao.getStatisticsOf(collection.getId(), lang);
127+
return categoryDao.getStatisticsOf(collectionId, lang);
130128
}
131129

132130
}

src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.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.JdbcCategoryDao
2424
import ru.mystamps.web.dao.dto.AddCategoryDbDto
25-
import ru.mystamps.web.entity.Collection
2625
import ru.mystamps.web.entity.User
2726
import ru.mystamps.web.model.AddCategoryForm
2827
import ru.mystamps.web.service.dto.LinkEntityDto
@@ -361,19 +360,9 @@ class CategoryServiceImplTest 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 CategoryServiceImplTest extends Specification {
383372
Integer expectedCollectionId = 15
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 * categoryDao.getStatisticsOf(
393379
{ Integer collectionId ->

0 commit comments

Comments
 (0)