Skip to content

Commit c330118

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

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public String showInfo(
7070
model.addAttribute("seriesOfCollection", seriesOfCollection);
7171

7272
if (seriesOfCollection.iterator().hasNext()) {
73-
model.addAttribute("categoryCounter", categoryService.countCategoriesOf(collection));
73+
// CheckStyle: ignore LineLength for next 1 line
74+
model.addAttribute("categoryCounter", categoryService.countCategoriesOf(collection.getId()));
7475
model.addAttribute("countryCounter", countryService.countCountriesOf(collection));
7576
model.addAttribute("seriesCounter", seriesService.countSeriesOf(collectionId));
7677
model.addAttribute("stampsCounter", seriesService.countStampsOf(collectionId));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface CategoryService {
3131
Iterable<SelectEntityDto> findAllAsSelectEntities(String lang);
3232
Iterable<LinkEntityDto> findAllAsLinkEntities(String lang);
3333
long countAll();
34-
long countCategoriesOf(Collection collection);
34+
long countCategoriesOf(Integer collectionId);
3535
long countByName(String name);
3636
long countByNameRu(String name);
3737
Map<String, Integer> getStatisticsOf(Collection collection, String lang);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ public long countAll() {
100100

101101
@Override
102102
@Transactional(readOnly = true)
103-
public long countCategoriesOf(Collection collection) {
104-
Validate.isTrue(collection != null, "Collection must be non null");
105-
Validate.isTrue(collection.getId() != null, "Collection id must be non null");
103+
public long countCategoriesOf(Integer collectionId) {
104+
Validate.isTrue(collectionId != null, "Collection id must be non null");
106105

107-
return categoryDao.countCategoriesOfCollection(collection.getId());
106+
return categoryDao.countCategoriesOfCollection(collectionId);
108107
}
109108

110109
@Override

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,31 +278,18 @@ class CategoryServiceImplTest extends Specification {
278278
// Tests for countCategoriesOf()
279279
//
280280

281-
def "countCategoriesOf() should throw exception when collection is null"() {
282-
when:
283-
service.countCategoriesOf(null)
284-
then:
285-
thrown IllegalArgumentException
286-
}
287-
288281
def "countCategoriesOf() should throw exception when collection id is null"() {
289-
given:
290-
Collection collection = Mock()
291-
collection.getId() >> null
292282
when:
293-
service.countCategoriesOf(collection)
283+
service.countCategoriesOf(null)
294284
then:
295285
thrown IllegalArgumentException
296286
}
297287

298288
def "countCategoriesOf() should pass arguments to dao"() {
299289
given:
300290
Integer expectedCollectionId = 10
301-
and:
302-
Collection expectedCollection = Mock()
303-
expectedCollection.getId() >> expectedCollectionId
304291
when:
305-
service.countCategoriesOf(expectedCollection)
292+
service.countCategoriesOf(expectedCollectionId)
306293
then:
307294
1 * categoryDao.countCategoriesOfCollection({ Integer collectionId ->
308295
assert expectedCollectionId == collectionId

0 commit comments

Comments
 (0)