Skip to content

Commit 8087541

Browse files
committed
Tests
1 parent 6d41cc4 commit 8087541

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

lib/pmdtester/builders/diff_report/violations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def diff_fragments(doc, violation)
6868
end
6969

7070
def display_line(violation)
71-
if violation.changed && violation.old_line != violation.line
71+
if violation.changed && violation.old_line && violation.old_line != violation.line
7272
"#{violation.old_line} => #{violation.line}"
7373
else
7474
violation.line

lib/pmdtester/pmd_violation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def line_move?(other)
6767

6868
def try_merge?(other)
6969
if branch != BASE && branch != other.branch && rule_name == other.rule_name &&
70+
!changed && # not already changed
7071
(line == other.line || line_move?(other))
7172
@changed = true
7273
@attrs['oldMessage'] = other.text
7374
@attrs['oldLine'] = other.line
74-
puts "Merged #{self} into #{other}"
7575
true
7676
else
7777
false
@@ -83,15 +83,15 @@ def old_message
8383
end
8484

8585
def old_line
86-
@attrs['oldLine']
86+
@attrs['oldLine']&.to_i
8787
end
8888

8989
def info_url
9090
@attrs['externalInfoUrl']
9191
end
9292

9393
def line
94-
@attrs['beginline']
94+
@attrs['beginline'].to_i
9595
end
9696

9797
def rule_name

test/resources/html_report_builder/expected_diff_report_index.html

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ <h2>Summary:</h2>
2525
</tr>
2626
<tr>
2727
<td class="c"><a href="#Violations">number of violations</a></td>
28-
<td class="b">5</td>
29-
<td class="a">8</td>
28+
<td class="b">6</td>
29+
<td class="a">10</td>
3030
<td class="c">
31-
<span class="removed">-1</span> | <span class="changed">~1</span> | <span class="added">+4</span>
31+
<span class="removed">-1</span> | <span class="changed">~2</span> | <span class="added">+5</span>
3232
</td>
3333
</tr>
3434
<tr>
@@ -74,7 +74,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
7474
</table>
7575
</div>
7676
<div class="section">
77-
<h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java">spring-framework/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java</a></h3>
77+
<h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java">spring-framework/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java</a></h3>
7878
<table class="bodyTable" border="0">
7979
<thead><tr>
8080
<th></th>
@@ -85,12 +85,37 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
8585
<tbody>
8686
<tr class="d">
8787
<td><a id="A2" href="#A2">#</a></td>
88+
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#somerule">SomeRule</a></td>
89+
<td>Some message</td>
90+
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java#L39">40 =&gt; 39</a></td>
91+
</tr>
92+
<tr class="a">
93+
<td><a id="A3" href="#A3">#</a></td>
94+
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#somerule">SomeRule</a></td>
95+
<td>Some message</td>
96+
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java#L41">41</a></td>
97+
</tr>
98+
</tbody>
99+
</table>
100+
</div>
101+
<div class="section">
102+
<h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java">spring-framework/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java</a></h3>
103+
<table class="bodyTable" border="0">
104+
<thead><tr>
105+
<th></th>
106+
<th>Rule</th>
107+
<th>Message</th>
108+
<th>Line</th>
109+
</tr></thead>
110+
<tbody>
111+
<tr class="d">
112+
<td><a id="A4" href="#A4">#</a></td>
88113
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#godclass">GodClass</a></td>
89114
<td>Possible God Class (WMC=101, ATFD=29, TCC=<del class="differ">4</del><ins class="differ">3</ins>.<del class="differ">000</del><ins class="differ">374</ins>%)</td>
90115
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L63">63</a></td>
91116
</tr>
92117
<tr class="a">
93-
<td><a id="A3" href="#A3">#</a></td>
118+
<td><a id="A5" href="#A5">#</a></td>
94119
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
95120
<td>Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.</td>
96121
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L96">96</a></td>
@@ -108,7 +133,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
108133
<th>Line</th>
109134
</tr></thead>
110135
<tbody><tr class="a">
111-
<td><a id="A4" href="#A4">#</a></td>
136+
<td><a id="A6" href="#A6">#</a></td>
112137
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
113138
<td>Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.</td>
114139
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/ClassFilter.java#L44">44</a></td>
@@ -125,7 +150,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
125150
<th>Line</th>
126151
</tr></thead>
127152
<tbody><tr class="a">
128-
<td><a id="A5" href="#A5">#</a></td>
153+
<td><a id="A7" href="#A7">#</a></td>
129154
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
130155
<td>Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.</td>
131156
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java#L97">97</a></td>
@@ -142,7 +167,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
142167
<th>Line</th>
143168
</tr></thead>
144169
<tbody><tr class="a">
145-
<td><a id="A6" href="#A6">#</a></td>
170+
<td><a id="A8" href="#A8">#</a></td>
146171
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal">ClassWithOnlyPrivateConstructorsShouldBeFinal</a></td>
147172
<td>A class which only has private constructors should be final</td>
148173
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/TrueClassFilter.java#L27">27</a></td>

test/resources/html_report_builder/test_html_report_builder_base.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Fields should be declared at the top of the class, before any method declaration
1717
<violation beginline="30" endline="73" begincolumn="1" endcolumn="1" rule="ClassWithOnlyPrivateConstructorsShouldBeFinal" ruleset="Design" package="org.springframework.aop" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal" priority="1">
1818
A class which only has private constructors should be final
1919
</violation>
20+
<violation beginline="40" endline="60" begincolumn="1" endcolumn="1" rule="SomeRule" ruleset="Design" package="org.springframework.aop" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#somerule" priority="1">
21+
Some message
22+
</violation>
2023
</file>
2124
<file name="SHOULD_BE_REPLACED/target/repositories/spring-framework/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java">
2225
<violation beginline="63" endline="742" begincolumn="17" endcolumn="1" rule="GodClass" ruleset="Design" package="org.springframework.aop.aspectj" class="AbstractAspectJAdvice" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#godclass" priority="3">

test/resources/html_report_builder/test_html_report_builder_patch.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ A class which only has private constructors should be final
2727
<violation beginline="30" endline="73" begincolumn="1" endcolumn="1" rule="ClassWithOnlyPrivateConstructorsShouldBeFinal" ruleset="Design" package="org.springframework.aop" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal" priority="1">
2828
A class which only has private constructors should be final
2929
</violation>
30+
<!-- Moved 1 line forward -->
31+
<violation beginline="41" endline="60" begincolumn="1" endcolumn="1" rule="SomeRule" ruleset="Design" package="org.springframework.aop" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#somerule" priority="1">
32+
Some message
33+
</violation>
34+
<!-- Moved 1 line backwards, but should not be merged twice! -->
35+
<violation beginline="39" endline="60" begincolumn="1" endcolumn="1" rule="SomeRule" ruleset="Design" package="org.springframework.aop" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#somerule" priority="1">
36+
Some message
37+
</violation>
3038
</file>
3139
<file name="SHOULD_BE_REPLACED/target/repositories/spring-framework/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java">
3240
<violation beginline="63" endline="742" begincolumn="17" endcolumn="1" rule="GodClass" ruleset="Design" package="org.springframework.aop.aspectj" class="AbstractAspectJAdvice" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#godclass" priority="3">

0 commit comments

Comments
 (0)