/
DataTableScenarioHtmlWriter.java
86 lines (68 loc) · 2.49 KB
/
DataTableScenarioHtmlWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.tngtech.jgiven.report.html;
import java.io.PrintWriter;
import com.tngtech.jgiven.report.model.ScenarioCaseModel;
import com.tngtech.jgiven.report.model.ScenarioModel;
import com.tngtech.jgiven.report.model.StepModel;
import com.tngtech.jgiven.report.model.Word;
public class DataTableScenarioHtmlWriter extends ScenarioHtmlWriter {
public DataTableScenarioHtmlWriter( PrintWriter writer ) {
super( writer );
}
@Override
public void visit( ScenarioCaseModel scenarioCase ) {
if( scenarioCase.caseNr == 1 ) {
super.visit( scenarioCase );
} else {
this.scenarioCase = scenarioCase;
}
}
@Override
void printCaseHeader( ScenarioCaseModel scenarioCase ) {}
@Override
public void visitEnd( ScenarioCaseModel scenarioCase ) {
if( scenarioCase.caseNr == 1 ) {
writer.println( "</ul>" );
writer.println( "<h4>Cases:</h4>" );
writer.println( "<table class='data-table'>" );
writer.println( "<tr>" );
writer.print( "<th>#</th>" );
for( String param : scenarioModel.getDerivedParameters() ) {
writer.print( "<th>" + param + "</th>" );
}
writer.print( "<th>Status</th>" );
writer.println( "</tr>" );
}
writer.println( "<tr>" );
writer.print( "<td>" + scenarioCase.caseNr + "</td>" );
for( String arg : scenarioCase.getDerivedArguments() ) {
writer.print( "<td>" + arg + "</td>" );
}
writer.print( "<td>" );
writeStatusIcon( scenarioCase.getExecutionStatus() );
if( !scenarioCase.success ) {
writer.println( "<div class='failed'>Failed: " + scenarioCase.errorMessage + "</div>" );
}
utils.writeDuration( scenarioCase.durationInNanos );
writer.print( "</td>" );
writer.println( "</tr>" );
}
@Override
public void visitEnd( ScenarioModel scenarioModel ) {
writer.println( "</table>" );
super.visitEnd( scenarioModel );
}
@Override
public void visit( StepModel stepModel ) {
if( scenarioCase.caseNr == 1 ) {
super.visit( stepModel );
}
}
@Override
String formatCaseArgument( Word value ) {
String paramName = findParameterName( value );
return "<" + paramName + ">";
}
private String findParameterName( Word word ) {
return word.getArgumentInfo().getParameterName();
}
}