Skip to content

Commit

Permalink
#701 Duplicated PMD and Checkstyle checks for multiple string literal…
Browse files Browse the repository at this point in the history
…s fix remarks
  • Loading branch information
dskalenko committed Feb 28, 2016
1 parent 174084a commit 3d633eb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@
* @version $Id$
* @since 0.17
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public final class FourDuplicateStringLiterals {

/**
* Construcor.
*/
private FourDuplicateStringLiterals() { }

/**
* Method with four duplicate string literals.
* @return Formated string
*/
public static String methodWithFourDuplicateStringLiterals() {
return String.format("%s%s%s%s", "test", "test", "test", "test");
public String methodWithFourDuplicateStringLiterals() {
return String.format(
"%s%s%s%s%s", "test", "test", "test", "test", this.toString()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,16 @@
* @version $Id$
* @since 0.17
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public final class SuppressDuplicateStringLiterals {

/**
* Construcor.
*/
private SuppressDuplicateStringLiterals() { }

/**
* Method with two duplicate string literals.
* @return Formated string
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public static String methodWithTwoDuplicateStringLiterals() {
return String.format("%s%s", "test", "test");
}

/**
* Method with four duplicate string literals.
* @return Formated string
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public static String methodWithFourDuplicateStringLiterals() {
return String.format("%s%s%s%s", "test", "test", "test", "test");
public String methodWithFourDuplicateStringLiterals() {
return String.format(
"%s%s%s%s%s", "test", "test", "test", "test", this.toString()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@
* @version $Id$
* @since 0.17
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public final class TwoDuplicateStringLiterals {

/**
* Construcor.
*/
private TwoDuplicateStringLiterals() { }

/**
* Method with two duplicate string literals.
* @return Formated string
*/
public static String methodWithTwoDuplicateStringLiterals() {
return String.format("%s%s", "test", "test");
public String methodWithTwoDuplicateStringLiterals() {
return String.format("%s%s%s", "test", "test", this.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@
* @version $Id$
* @since 0.17
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public final class WithoutDuplicateStringLiterals {

/**
* Construcor.
*/
private WithoutDuplicateStringLiterals() { }

/**
* Method without duplicate string literals.
* @return Formated string
*/
public static String methodWithoutDuplicateStringLiterals() {
return String.format("%s", "test");
public String methodWithoutDuplicateStringLiterals() {
return String.format("%s%s", "test", this.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
*/
def log = new File(basedir, 'build.log')
assert !log.text.contains('MultipleStringLiteralsCheck')
assert !log.text.contains('SuppressDuplicateStringLiterals.java')
assert !log.text.contains('WithoutDuplicateStringLiterals.java')
assert log.text.contains('No Checkstyle violations found')
assert log.text.contains('FourDuplicateStringLiterals.java[51-51]: The String '
+ 'literal "test" appears 4 times in this file; the first occurrence is on line 51 (AvoidDuplicateLiterals)')
assert log.text.contains('TwoDuplicateStringLiterals.java[51-51]: The String '
+ 'literal "test" appears 2 times in this file; the first occurrence is on line 51 (AvoidDuplicateLiterals)')
assert log.text.contains('FourDuplicateStringLiterals.java[46-46]: The String '
+ 'literal "test" appears 4 times in this file; the first occurrence is on line 46 (AvoidDuplicateLiterals)')
assert log.text.contains('TwoDuplicateStringLiterals.java[45-45]: The String '
+ 'literal "test" appears 2 times in this file; the first occurrence is on line 45 (AvoidDuplicateLiterals)')
assert log.text.contains('Failure: 2 PMD violations')

0 comments on commit 3d633eb

Please sign in to comment.