Skip to content

Commit d98d632

Browse files
committed
fix tests
1 parent 5d531cd commit d98d632

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

code-assert/src/main/java/guru/nidi/codeassert/dependency/DependencyRuler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public DependencyRule rule() {
9595
* Create a rule for a package allowing everything.
9696
* Shortcut for DependencyRule.allowAll(name);
9797
*
98+
* @param name the package name
9899
* @return the rule.
99100
*/
100101
public DependencyRule allowRule(String name) {
@@ -105,6 +106,7 @@ public DependencyRule allowRule(String name) {
105106
* Create a rule for a package denying everything.
106107
* Shortcut for DependencyRule.denyAll(name);
107108
*
109+
* @param name the package name
108110
* @return the rule.
109111
*/
110112
public DependencyRule denyRule(String name) {

code-assert/src/main/java/guru/nidi/codeassert/dependency/DependencyRules.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ private List<DependencyRule> initFields(String basePackage, DependencyRuler rule
185185
}
186186

187187
private DependencyRule initField(String basePackage, DependencyRuler ruler, Field f) throws IllegalAccessException {
188-
final String name = f.getName();
189188
final CodeElement value = (CodeElement) f.get(ruler);
190189
if (value instanceof DependencyRule && !"*".equals(value.pattern.getPattern())) {
191190
return (DependencyRule) value;
192191
}
192+
final String name = f.getName();
193193
deprecationWarnings(name);
194194
final String pack = addPackages(basePackage, "$self".equals(name) ? "" : camelCaseToDotCase(name));
195195
final DependencyRule rule = rule(pack);

code-assert/src/main/java/guru/nidi/codeassert/pmd/CpdMatcher.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020
import net.sourceforge.pmd.cpd.Match;
2121
import org.hamcrest.Description;
2222

23-
import java.util.Iterator;
23+
import java.util.*;
2424

2525
public class CpdMatcher extends ResultMatcher<CpdResult, Match> {
26+
private static final Comparator<Mark> MARK_COMPARATOR = new Comparator<Mark>() {
27+
@Override
28+
public int compare(Mark m1, Mark m2) {
29+
return m1.getFilename().compareTo(m2.getFilename());
30+
}
31+
};
32+
2633
public void describeTo(Description description) {
2734
description.appendText("Has no code duplications");
2835
}
@@ -37,13 +44,21 @@ protected void describeMismatchSafely(CpdResult item, Description description) {
3744
private String printMatch(Match match) {
3845
final StringBuilder s = new StringBuilder();
3946
boolean first = true;
40-
final Iterator<Mark> marks = match.iterator();
41-
while (marks.hasNext()) {
42-
final Mark mark = marks.next();
47+
for (final Mark mark : getMarks(match)) {
4348
s.append(first ? String.format("%-4d ", match.getTokenCount()) : " ");
4449
first = false;
4550
s.append(String.format("%s:%d-%d%n", mark.getFilename(), mark.getBeginLine(), mark.getEndLine()));
4651
}
4752
return s.substring(0, s.length() - 1);
4853
}
54+
55+
private List<Mark> getMarks(Match match) {
56+
final List<Mark> marks = new ArrayList<>();
57+
final Iterator<Mark> iter = match.iterator();
58+
while (iter.hasNext()) {
59+
marks.add(iter.next());
60+
}
61+
Collections.sort(marks, MARK_COMPARATOR);
62+
return marks;
63+
}
4964
}

0 commit comments

Comments
 (0)