Skip to content
2,599 changes: 1,587 additions & 1,012 deletions .refactorfirst/refactor-first.json

Large diffs are not rendered by default.

245 changes: 56 additions & 189 deletions report/src/main/java/org/hjug/refactorfirst/report/JsonGenerator.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class ChartJsBubbleDTO {
private int changePronenessRank;
private String color;
private String borderColor;
private String url;
private String path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
public class ClassRelationshipDTO {
private String sourceClass;
private String targetClass;
private String sourceClassPath;
private String targetClassPath;
private String simpleSourceClassName;
private String simpleTargetClassName;
private boolean sourceMarked;
private boolean targetMarked;
private int weight;
private String renderedLabel;
private int priority;
private int cycleCount;
private int effortRank;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
@AllArgsConstructor
public class CycleBreakdownRowDTO {
private String className;
private String classPath;
private boolean marked;
private String edgesHtml;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
public class DisharmonyTableCellDTO {
private String content;
private String align;
private String path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
public class PackageRelationshipDTO {
private String sourcePackage;
private String targetPackage;
private String sourcePackagePath;
private String targetPackagePath;
private boolean sourceMarked;
private boolean targetMarked;
private int weight;
private String renderedLabel;
private int priority;
private int cycleCount;
private int effortRank;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<tbody>
{{#classRelationshipsToRemove.relationships}}
<tr>
<td align="left">{{renderedLabel}}</td>
<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>
<td align="right">{{priority}}</td>
<td align="right">{{cycleCount}}</td>
<td align="right">{{effortRank}}</td>
Expand Down Expand Up @@ -293,12 +293,12 @@
<tbody>
{{#packageRelationshipsToRemove.relationships}}
<tr>
<td align="left">{{{renderedLabel}}}</td>
<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>
<td align="right">{{priority}}</td>
<td align="right">{{cycleCount}}</td>
<td align="right">{{effortRank}}</td>
<td align="left">{{#classRelationshipsToBreakPackage}}
{{{renderedLabel}}}<br/>{{/classRelationshipsToBreakPackage}}</td>
{{#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>
</tr>
{{/packageRelationshipsToRemove.relationships}}
</tbody>
Expand Down Expand Up @@ -349,7 +349,7 @@
{{#table.rows}}
<tr>
{{#cells}}
<td align="{{align}}">{{{content}}}</td>
<td align="{{align}}">{{#path}}<a href="{{project.repoUrl}}{{path}}" target="_blank">{{/path}}{{{content}}}{{#path}}</a>{{/path}}</td>
{{/cells}}
</tr>
{{/table.rows}}
Expand Down Expand Up @@ -424,7 +424,7 @@
<tbody>
{{#classCycles.largestCycle.breakdown}}
<tr>
<td align="left">{{{className}}}</td>
<td align="left">{{#classPath}}<a href="{{project.repoUrl}}{{classPath}}" target="_blank">{{/classPath}}{{className}}{{#classPath}}</a>{{/classPath}}{{#marked}}*{{/marked}}</td>
<td align="left">{{{edgesHtml}}}</td>
</tr>
{{/classCycles.largestCycle.breakdown}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.hjug.refactorfirst.report;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.time.Instant;
import java.util.List;
import org.hjug.cbc.RankedDisharmony;
import org.hjug.refactorfirst.report.model.DisharmonySectionDTO;
import org.hjug.refactorfirst.report.model.DisharmonyTableCellDTO;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

/**
* Pins the JSON contract of the disharmony table cells: the Class cell carries the
* plain file name and the source path relative to the project root, and no
* server-rendered link — viewers combine the path with project.repoUrl.
*/
class JsonGeneratorDisharmonySectionTest {

/** Creates a ranked God Class finding for the file at the given path. */
private RankedDisharmony mockRankedDisharmony(String fileName, String path) {
RankedDisharmony rd = Mockito.mock(RankedDisharmony.class);
Mockito.when(rd.getFileName()).thenReturn(fileName);
Mockito.when(rd.getPath()).thenReturn(path);
Mockito.when(rd.getPriority()).thenReturn(1);
Mockito.when(rd.getEffortRank()).thenReturn(5);
Mockito.when(rd.getChangePronenessRank()).thenReturn(10);
Mockito.when(rd.getMostRecentCommitTime()).thenReturn(Instant.now());
Mockito.when(rd.getCommitCount()).thenReturn(1);
Mockito.when(rd.getDuplicationPartners()).thenReturn(null);
return rd;
}

@DisplayName("the disharmony Class cell carries the plain file name and the source path, not a rendered link")
@Test
void buildDisharmonySection_classCellCarriesPathAndFileName() {
// Given: one ranked God Class finding
JsonGenerator generator = new JsonGenerator();
RankedDisharmony rd = mockRankedDisharmony("TestClass.java", "src/main/java/com/example/TestClass.java");

// When: the disharmony section is built without detail columns
DisharmonySectionDTO section =
generator.buildDisharmonySection(SimpleHtmlReport.DISHARMONY_SPECS.get(0), false, List.of(rd));

// Then: the Class cell lists the file name and the path relative to the
// project root; the URL is the viewer's to construct
DisharmonyTableCellDTO classCell =
section.getTable().getRows().get(0).getCells().get(0);
assertEquals("TestClass.java", classCell.getContent());
assertEquals("src/main/java/com/example/TestClass.java", classCell.getPath());
assertFalse(classCell.getContent().contains("<a"), "The Class cell must not embed a server-built link");
assertFalse(
classCell.getContent().contains("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/example/repo"),
"The Class cell must not embed the repository URL");
}
}
Loading
Loading