Skip to content

Commit 18e2f1f

Browse files
Started adding tests and improving testability of GraphDataGenerator
1 parent 552bf95 commit 18e2f1f

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

graph-data-generator/src/main/java/org/hjug/gdg/GraphDataGenerator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
public class GraphDataGenerator {
1010

11-
private final CostBenefitCalculator costBenefitCalculator = new CostBenefitCalculator();
11+
private final CostBenefitCalculator costBenefitCalculator;
1212
private final List<RankedDisharmony> calculateCostBenefitValues = new ArrayList<>();
1313

14+
public GraphDataGenerator(CostBenefitCalculator costBenefitCalculator) {
15+
this.costBenefitCalculator = costBenefitCalculator;
16+
}
17+
1418
public String getScriptStart() {
1519
return
1620
" google.charts.load('current', {'packages':['corechart']});\n" +
@@ -39,9 +43,7 @@ public String getScriptEnd() {
3943
" }\n";
4044
}
4145

42-
public String generateBubbleChartData(String repositoryPath) {
43-
44-
List<RankedDisharmony> rankedDisharmonies = getRankedDisharmonies(repositoryPath);
46+
public String generateBubbleChartData(List<RankedDisharmony> rankedDisharmonies) {
4547

4648
StringBuilder chartData = new StringBuilder();
4749
chartData.append("[ 'ID', 'Effort', 'Change Proneness', 'Priority', 'Method Count'], ");
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.hjug.gdg;
2+
3+
import org.hjug.cbc.CostBenefitCalculator;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.*;
8+
import static org.mockito.Mockito.mock;
9+
10+
public class GraphDataGeneratorTest {
11+
12+
private GraphDataGenerator graphDataGenerator;
13+
private CostBenefitCalculator costBenefitCalculator = mock(CostBenefitCalculator.class);
14+
15+
@Before
16+
public void setUp() {
17+
graphDataGenerator = new GraphDataGenerator(costBenefitCalculator);
18+
}
19+
20+
@Test
21+
public void getScriptStart() {
22+
String scriptStart =
23+
" google.charts.load('current', {'packages':['corechart']});\n" +
24+
" google.charts.setOnLoadCallback(drawSeriesChart);\n" +
25+
"\n" +
26+
" function drawSeriesChart() {\n" +
27+
"\n" +
28+
" var data = google.visualization.arrayToDataTable([";
29+
assertEquals(scriptStart, graphDataGenerator.getScriptStart());
30+
}
31+
32+
@Test
33+
public void getScriptEnd() {
34+
String scriptEnd =
35+
"]);\n" +
36+
"\n" +
37+
" var options = {\n" +
38+
" title: 'Priority Ranking for Refactoring God Classes - ' +\n" +
39+
" 'Fix Higher Priority Classes First',\n" +
40+
" height: 900, " +
41+
" width: 1200, " +
42+
" hAxis: {title: 'Effort'},\n" +
43+
" vAxis: {title: 'Change Proneness'},\n" +
44+
" colorAxis: {colors: ['blue', 'green']},\n" +
45+
" bubble: {textStyle: {fontSize: 11}} };\n" +
46+
"\n" +
47+
" var chart = new google.visualization.BubbleChart(document.getElementById('series_chart_div'));\n" +
48+
" chart.draw(data, options);\n" +
49+
" }\n";
50+
51+
assertEquals(scriptEnd, graphDataGenerator.getScriptEnd());
52+
}
53+
54+
@Test
55+
public void generateBubbleChartData() {
56+
}
57+
58+
@Test
59+
public void getRankedDisharmonies() {
60+
}
61+
}

refactor-first-maven-plugin/src/main/java/org/hjug/mavenreport/RefactorFirstMavenReport.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.maven.plugins.annotations.ResolutionScope;
1212
import org.apache.maven.reporting.AbstractMavenReport;
1313
import org.apache.maven.reporting.MavenReportException;
14+
import org.hjug.cbc.CostBenefitCalculator;
1415
import org.hjug.cbc.RankedDisharmony;
1516
import org.hjug.gdg.GraphDataGenerator;
1617
import org.hjug.git.GitLogReader;
@@ -100,8 +101,8 @@ protected void executeReport(Locale locale) throws MavenReportException {
100101
return;
101102
}
102103

103-
GraphDataGenerator graphDataGenerator = new GraphDataGenerator();
104-
104+
CostBenefitCalculator costBenefitCalculator = new CostBenefitCalculator();
105+
GraphDataGenerator graphDataGenerator = new GraphDataGenerator(costBenefitCalculator);
105106

106107
List<RankedDisharmony> rankedDisharmonies =
107108
graphDataGenerator.getRankedDisharmonies(projectBaseDir);
@@ -130,7 +131,7 @@ protected void executeReport(Locale locale) throws MavenReportException {
130131
mainSink.text("Refactor First Report for " + projectName + " " + projectVersion);
131132
mainSink.title_();
132133

133-
generateChart(graphDataGenerator, mainSink);
134+
generateChart(graphDataGenerator, rankedDisharmonies, mainSink);
134135

135136
mainSink.head_();
136137

@@ -235,7 +236,7 @@ private void drawTableCell(String cellText, Sink mainSink) {
235236
/**
236237
* @See https://maven.apache.org/doxia/developers/sink.html#How_to_inject_javascript_code_into_HTML
237238
*/
238-
private void generateChart(GraphDataGenerator graphDataGenerator, Sink mainSink) {
239+
private void generateChart(GraphDataGenerator graphDataGenerator, List<RankedDisharmony> rankedDisharmonies, Sink mainSink) {
239240

240241
SinkEventAttributeSet googleChartImport = new SinkEventAttributeSet();
241242
googleChartImport.addAttribute( SinkEventAttributes.TYPE, "text/javascript" );
@@ -245,7 +246,7 @@ private void generateChart(GraphDataGenerator graphDataGenerator, Sink mainSink)
245246
mainSink.unknown(script, new Object[]{HtmlMarkup.TAG_TYPE_START}, googleChartImport);
246247
mainSink.unknown(script, new Object[]{HtmlMarkup.TAG_TYPE_END}, null);
247248
String scriptStart = graphDataGenerator.getScriptStart();
248-
String bubbleChartData = graphDataGenerator.generateBubbleChartData(project.getBasedir().getPath());
249+
String bubbleChartData = graphDataGenerator.generateBubbleChartData(rankedDisharmonies);
249250
String scriptEnd = graphDataGenerator.getScriptEnd();
250251

251252
String javascriptCode = scriptStart + bubbleChartData + scriptEnd;

0 commit comments

Comments
 (0)