Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 19, 2016
2 parents 64f0e7a + 782c74b commit b88119d
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
4 changes: 2 additions & 2 deletions qulice-pmd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<packaging>jar</packaging>
<name>qulice-pmd</name>
<properties>
<pmd.version>5.3.4</pmd.version>
<pmd.version>5.4.1</pmd.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -95,7 +95,7 @@
<configuration>
<parallel>classes</parallel>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
65 changes: 65 additions & 0 deletions qulice-pmd/src/test/java/com/qulice/pmd/PMDValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public final class PMDValidatorTest {
*/
private static final String MULT_CON_INIT = "%s\\[\\d+-\\d+\\]: Avoid field initialization in several constructors.";

/**
* Template for string inside brackets.
*/
private static final String BRACKETS = "(%s)";

/**
* PMDValidator can find violations in Java file(s).
* @throws Exception If something wrong happens inside.
Expand Down Expand Up @@ -358,4 +363,64 @@ public void forbidsCallToStaticFieldsInNonStaticWay()
)
).validate();
}

/**
* PMDValidator forbids non public clone methods (PMD rule
* rulesets/java/clone.xml/CloneMethodMustBePublic).
* @throws Exception If something wrong happens inside.
*/
@Test
public void forbidsNonPublicCloneMethod() throws Exception {
new PMDAssert(
"CloneMethodMustBePublic.java",
Matchers.is(false),
Matchers.containsString(
String.format(
PMDValidatorTest.BRACKETS,
"CloneMethodMustBePublic"
)
)
).validate();
}

/**
* PMDValidator forbids clone methods with return type not matching class
* name (PMD rule
* rulesets/java/clone.xml/CloneMethodReturnTypeMustMatchClassName).
* @throws Exception If something wrong happens inside.
*/
@Test
public void forbidsCloneMethodReturnTypeNotMatchingClassName()
throws Exception {
new PMDAssert(
"CloneMethodReturnTypeMustMatchClassName.java",
Matchers.is(false),
Matchers.containsString(
String.format(
PMDValidatorTest.BRACKETS,
"CloneMethodReturnTypeMustMatchClassName"
)
)
).validate();
}

/**
* PMDValidator forbids ternary operators that can be simplified (PMD rule
* rulesets/java/basic.xml/SimplifiedTernary).
* @throws Exception If something wrong happens inside.
*/
@Test
public void forbidsNonSimplifiedTernaryOperators()
throws Exception {
new PMDAssert(
"SimplifiedTernary.java",
Matchers.is(false),
Matchers.containsString(
String.format(
PMDValidatorTest.BRACKETS,
"SimplifiedTernary"
)
)
).validate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package foo;

public class CloneMethodMustBePublic implements Cloneable {
@Override
protected CloneMethodMustBePublic clone() throws CloneNotSupportedException {
return ((CloneMethodMustBePublic) super.clone());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package foo;

public class CloneMethodReturnTypeMustMatchClassName implements Cloneable {
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package foo;

public class SimplifiedTernary {
public boolean test() {
return condition ? true : something();
}
}

0 comments on commit b88119d

Please sign in to comment.