Skip to content

Commit d798d64

Browse files
Merge pull request #227 from refactorfirst/assemble-links
Assemble links
2 parents 8f00256 + da5c881 commit d798d64

13 files changed

Lines changed: 2112 additions & 1259 deletions

‎.refactorfirst/refactor-first.json‎

Lines changed: 1587 additions & 1012 deletions
Large diffs are not rendered by default.

‎report/src/main/java/org/hjug/refactorfirst/report/JsonGenerator.java‎

Lines changed: 56 additions & 189 deletions
Large diffs are not rendered by default.

‎report/src/main/java/org/hjug/refactorfirst/report/model/ChartJsBubbleDTO.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ public class ChartJsBubbleDTO {
2020
private int changePronenessRank;
2121
private String color;
2222
private String borderColor;
23-
private String url;
23+
private String path;
2424
}

‎report/src/main/java/org/hjug/refactorfirst/report/model/ClassRelationshipDTO.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
public class ClassRelationshipDTO {
1313
private String sourceClass;
1414
private String targetClass;
15+
private String sourceClassPath;
16+
private String targetClassPath;
17+
private String simpleSourceClassName;
18+
private String simpleTargetClassName;
1519
private boolean sourceMarked;
1620
private boolean targetMarked;
1721
private int weight;
18-
private String renderedLabel;
1922
private int priority;
2023
private int cycleCount;
2124
private int effortRank;

‎report/src/main/java/org/hjug/refactorfirst/report/model/CycleBreakdownRowDTO.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
@AllArgsConstructor
1212
public class CycleBreakdownRowDTO {
1313
private String className;
14+
private String classPath;
15+
private boolean marked;
1416
private String edgesHtml;
1517
}

‎report/src/main/java/org/hjug/refactorfirst/report/model/DisharmonyTableCellDTO.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
public class DisharmonyTableCellDTO {
1313
private String content;
1414
private String align;
15+
private String path;
1516
}

‎report/src/main/java/org/hjug/refactorfirst/report/model/PackageRelationshipDTO.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
public class PackageRelationshipDTO {
1515
private String sourcePackage;
1616
private String targetPackage;
17+
private String sourcePackagePath;
18+
private String targetPackagePath;
1719
private boolean sourceMarked;
1820
private boolean targetMarked;
1921
private int weight;
20-
private String renderedLabel;
2122
private int priority;
2223
private int cycleCount;
2324
private int effortRank;

‎report/src/main/resources/templates/refactor-first-report.mustache‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
<tbody>
211211
{{#classRelationshipsToRemove.relationships}}
212212
<tr>
213-
<td align="left">{{renderedLabel}}</td>
213+
<td align="left">{{#sourceClassPath}}<a href="{{project.repoUrl}}{{sourceClassPath}}" target="_blank">{{/sourceClassPath}}{{simpleSourceClassName}}{{#sourceClassPath}}</a>{{/sourceClassPath}}{{#sourceMarked}}*{{/sourceMarked}} &#8594; {{#targetClassPath}}<a href="{{project.repoUrl}}{{targetClassPath}}" target="_blank">{{/targetClassPath}}{{simpleTargetClassName}}{{#targetClassPath}}</a>{{/targetClassPath}}{{#targetMarked}}*{{/targetMarked}}</td>
214214
<td align="right">{{priority}}</td>
215215
<td align="right">{{cycleCount}}</td>
216216
<td align="right">{{effortRank}}</td>
@@ -293,12 +293,12 @@
293293
<tbody>
294294
{{#packageRelationshipsToRemove.relationships}}
295295
<tr>
296-
<td align="left">{{{renderedLabel}}}</td>
296+
<td align="left">{{#sourcePackagePath}}<a href="{{project.repoUrl}}{{sourcePackagePath}}" target="_blank">{{/sourcePackagePath}}{{sourcePackage}}{{#sourcePackagePath}}</a>{{/sourcePackagePath}}{{#sourceMarked}}*{{/sourceMarked}} &#8594; {{#targetPackagePath}}<a href="{{project.repoUrl}}{{targetPackagePath}}" target="_blank">{{/targetPackagePath}}{{targetPackage}}{{#targetPackagePath}}</a>{{/targetPackagePath}}{{#targetMarked}}*{{/targetMarked}}</td>
297297
<td align="right">{{priority}}</td>
298298
<td align="right">{{cycleCount}}</td>
299299
<td align="right">{{effortRank}}</td>
300300
<td align="left">{{#classRelationshipsToBreakPackage}}
301-
{{{renderedLabel}}}<br/>{{/classRelationshipsToBreakPackage}}</td>
301+
{{#sourceClassPath}}<a href="{{project.repoUrl}}{{sourceClassPath}}" target="_blank">{{/sourceClassPath}}{{simpleSourceClassName}}{{#sourceClassPath}}</a>{{/sourceClassPath}}{{#sourceMarked}}*{{/sourceMarked}} &#8594; {{#targetClassPath}}<a href="{{project.repoUrl}}{{targetClassPath}}" target="_blank">{{/targetClassPath}}{{simpleTargetClassName}}{{#targetClassPath}}</a>{{/targetClassPath}}{{#targetMarked}}*{{/targetMarked}} : {{weight}}<br/>{{/classRelationshipsToBreakPackage}}</td>
302302
</tr>
303303
{{/packageRelationshipsToRemove.relationships}}
304304
</tbody>
@@ -349,7 +349,7 @@
349349
{{#table.rows}}
350350
<tr>
351351
{{#cells}}
352-
<td align="{{align}}">{{{content}}}</td>
352+
<td align="{{align}}">{{#path}}<a href="{{project.repoUrl}}{{path}}" target="_blank">{{/path}}{{{content}}}{{#path}}</a>{{/path}}</td>
353353
{{/cells}}
354354
</tr>
355355
{{/table.rows}}
@@ -424,7 +424,7 @@
424424
<tbody>
425425
{{#classCycles.largestCycle.breakdown}}
426426
<tr>
427-
<td align="left">{{{className}}}</td>
427+
<td align="left">{{#classPath}}<a href="{{project.repoUrl}}{{classPath}}" target="_blank">{{/classPath}}{{className}}{{#classPath}}</a>{{/classPath}}{{#marked}}*{{/marked}}</td>
428428
<td align="left">{{{edgesHtml}}}</td>
429429
</tr>
430430
{{/classCycles.largestCycle.breakdown}}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.hjug.refactorfirst.report;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
6+
import java.time.Instant;
7+
import java.util.List;
8+
import org.hjug.cbc.RankedDisharmony;
9+
import org.hjug.refactorfirst.report.model.DisharmonySectionDTO;
10+
import org.hjug.refactorfirst.report.model.DisharmonyTableCellDTO;
11+
import org.junit.jupiter.api.DisplayName;
12+
import org.junit.jupiter.api.Test;
13+
import org.mockito.Mockito;
14+
15+
/**
16+
* Pins the JSON contract of the disharmony table cells: the Class cell carries the
17+
* plain file name and the source path relative to the project root, and no
18+
* server-rendered link — viewers combine the path with project.repoUrl.
19+
*/
20+
class JsonGeneratorDisharmonySectionTest {
21+
22+
/** Creates a ranked God Class finding for the file at the given path. */
23+
private RankedDisharmony mockRankedDisharmony(String fileName, String path) {
24+
RankedDisharmony rd = Mockito.mock(RankedDisharmony.class);
25+
Mockito.when(rd.getFileName()).thenReturn(fileName);
26+
Mockito.when(rd.getPath()).thenReturn(path);
27+
Mockito.when(rd.getPriority()).thenReturn(1);
28+
Mockito.when(rd.getEffortRank()).thenReturn(5);
29+
Mockito.when(rd.getChangePronenessRank()).thenReturn(10);
30+
Mockito.when(rd.getMostRecentCommitTime()).thenReturn(Instant.now());
31+
Mockito.when(rd.getCommitCount()).thenReturn(1);
32+
Mockito.when(rd.getDuplicationPartners()).thenReturn(null);
33+
return rd;
34+
}
35+
36+
@DisplayName("the disharmony Class cell carries the plain file name and the source path, not a rendered link")
37+
@Test
38+
void buildDisharmonySection_classCellCarriesPathAndFileName() {
39+
// Given: one ranked God Class finding
40+
JsonGenerator generator = new JsonGenerator();
41+
RankedDisharmony rd = mockRankedDisharmony("TestClass.java", "src/main/java/com/example/TestClass.java");
42+
43+
// When: the disharmony section is built without detail columns
44+
DisharmonySectionDTO section =
45+
generator.buildDisharmonySection(SimpleHtmlReport.DISHARMONY_SPECS.get(0), false, List.of(rd));
46+
47+
// Then: the Class cell lists the file name and the path relative to the
48+
// project root; the URL is the viewer's to construct
49+
DisharmonyTableCellDTO classCell =
50+
section.getTable().getRows().get(0).getCells().get(0);
51+
assertEquals("TestClass.java", classCell.getContent());
52+
assertEquals("src/main/java/com/example/TestClass.java", classCell.getPath());
53+
assertFalse(classCell.getContent().contains("<a"), "The Class cell must not embed a server-built link");
54+
assertFalse(
55+
classCell.getContent().contains("https://github.com/example/repo"),
56+
"The Class cell must not embed the repository URL");
57+
}
58+
}

0 commit comments

Comments
 (0)