Skip to content

Commit aecaca2

Browse files
committed
CountryServiceImpl: use NOPLogger for unit tests to reduce output to console.
No functional changes.
1 parent 1bc7c2f commit aecaca2

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/main/config/pmd.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
<rule ref="rulesets/java/basic.xml" />
2727
<rule ref="rulesets/java/strictexception.xml" />
2828
<rule ref="rulesets/java/sunsecure.xml" />
29-
<rule ref="rulesets/java/logging-java.xml" />
29+
<rule ref="rulesets/java/logging-java.xml">
30+
<exclude name="LoggerIsNotStaticFinal" />
31+
</rule>
3032
<rule ref="rulesets/java/controversial.xml">
3133
<exclude name="AtLeastOneConstructor" />
3234
<exclude name="OnlyOneReturn" />

src/main/java/ru/mystamps/web/config/ServicesConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import java.util.Locale;
2121

22+
import org.slf4j.LoggerFactory;
23+
2224
import org.springframework.context.MessageSource;
2325
import org.springframework.context.annotation.Bean;
2426
import org.springframework.context.annotation.Configuration;
@@ -49,7 +51,10 @@ public SuspiciousActivityService getSuspiciousActivityService() {
4951

5052
@Bean
5153
public CountryService getCountryService() {
52-
return new CountryServiceImpl(daoConfig.getCountryDao());
54+
return new CountryServiceImpl(
55+
LoggerFactory.getLogger(CountryServiceImpl.class),
56+
daoConfig.getCountryDao()
57+
);
5358
}
5459

5560
@Bean

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.commons.lang3.Validate;
2626

2727
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
2928

3029
import org.springframework.transaction.annotation.Transactional;
3130

@@ -44,8 +43,8 @@
4443
@RequiredArgsConstructor
4544
@SuppressWarnings("PMD.TooManyMethods")
4645
public class CountryServiceImpl implements CountryService {
47-
private static final Logger LOG = LoggerFactory.getLogger(CountryServiceImpl.class);
4846

47+
private final Logger log;
4948
private final CountryDao countryDao;
5049

5150
@Override
@@ -76,7 +75,7 @@ public String add(AddCountryDto dto, Integer userId) {
7675

7776
Integer id = countryDao.add(country);
7877

79-
LOG.info("Country #{} has been created ({})", id, country);
78+
log.info("Country #{} has been created ({})", id, country);
8079

8180
return slug;
8281
}
@@ -177,7 +176,7 @@ public String suggestCountryForUser(Integer userId) {
177176
// if user created a series with a country, let's suggest this country to him
178177
String slug = countryDao.findCountryOfLastCreatedSeriesByUser(userId);
179178
if (slug != null) {
180-
LOG.info(
179+
log.info(
181180
"Country {} has been suggested to user #{} from a recently created series",
182181
slug,
183182
userId
@@ -189,7 +188,7 @@ public String suggestCountryForUser(Integer userId) {
189188
// belong to a specific country, let's suggest this country to him
190189
slug = countryDao.findPopularCountryInCollection(userId);
191190
if (slug != null) {
192-
LOG.info(
191+
log.info(
193192
"Country {} has been suggested to user #{} as popular in his collection",
194193
slug,
195194
userId

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ package ru.mystamps.web.service
2020
import spock.lang.Specification
2121
import spock.lang.Unroll
2222

23+
import org.slf4j.helpers.NOPLogger
24+
2325
import ru.mystamps.web.dao.CountryDao
2426
import ru.mystamps.web.dao.dto.AddCountryDbDto
2527
import ru.mystamps.web.controller.dto.AddCountryForm
@@ -33,7 +35,7 @@ class CountryServiceImplTest extends Specification {
3335
private static final Integer USER_ID = 321
3436

3537
private final CountryDao countryDao = Mock()
36-
private final CountryService service = new CountryServiceImpl(countryDao)
38+
private final CountryService service = new CountryServiceImpl(NOPLogger.NOP_LOGGER, countryDao)
3739

3840
private AddCountryForm form
3941

0 commit comments

Comments
 (0)