3333import java .util .List ;
3434import java .util .Map ;
3535import java .util .Optional ;
36- import java .util .TreeMap ;
37- import java .util .concurrent .atomic .AtomicInteger ;
3836import java .util .function .Function ;
39- import java .util .function .Supplier ;
4037import java .util .stream .Collectors ;
4138
4239import static com .fasterxml .jackson .annotation .JsonInclude .Value .construct ;
4340import static io .cucumber .query .Repository .RepositoryFeature .INCLUDE_GHERKIN_DOCUMENTS ;
41+ import static java .util .Comparator .comparing ;
4442import static java .util .Locale .ROOT ;
4543
4644/**
@@ -106,35 +104,37 @@ private void write(Envelope event) {
106104 }
107105
108106 private void writeTimeLineReport () throws IOException {
109- Map <String , TimeLineGroup > timeLineGroups = new HashMap <>();
110- AtomicInteger nextGroupId = new AtomicInteger ();
107+ Map <String , TimeLineGroup > timeLineGroupsById = new HashMap <>();
111108 List <TimeLineItem > timeLineItems = query .findAllTestCaseFinished ().stream ()
112109 .map (testCaseFinished -> query .findTestCaseStartedBy (testCaseFinished )
113110 .map (testCaseStarted -> createTestData (
114111 testCaseFinished , //
115112 testCaseStarted , //
116- createTimeLineGroup (timeLineGroups , nextGroupId ) //
113+ createTimeLineGroup (timeLineGroupsById ) //
117114 )))
118115 .filter (Optional ::isPresent )
119116 .map (Optional ::get )
120117 .collect (Collectors .toList ());
121118
119+ List <TimeLineGroup > timeLineGroups = timeLineGroupsById .values ().stream ()
120+ .sorted (comparing (TimeLineGroup ::getId ))
121+ .collect (Collectors .toList ());
122+
122123 writeTimeLineReport (timeLineGroups , timeLineItems );
123124 }
124125
125126 private Function <String , TimeLineGroup > createTimeLineGroup (
126- Map <String , TimeLineGroup > timeLineGroups ,
127- AtomicInteger nextGroupId
127+ Map <String , TimeLineGroup > timeLineGroups
128128 ) {
129129
130- return workerId -> timeLineGroups .computeIfAbsent (workerId , createTimeLineGroup (nextGroupId :: incrementAndGet ));
130+ return workerId -> timeLineGroups .computeIfAbsent (workerId , createTimeLineGroup ());
131131 }
132132
133- private Function <String , TimeLineGroup > createTimeLineGroup (Supplier < Integer > nextGroupId ) {
133+ private Function <String , TimeLineGroup > createTimeLineGroup () {
134134 return workerId -> {
135135 TimeLineGroup timeLineGroup = new TimeLineGroup ();
136136 timeLineGroup .setContent (workerId );
137- timeLineGroup .setId (nextGroupId . get () );
137+ timeLineGroup .setId (workerId );
138138 return timeLineGroup ;
139139 };
140140 }
@@ -196,13 +196,13 @@ private String getTagsValue(TestCaseStarted testCaseStarted) {
196196 }).orElse ("" );
197197 }
198198
199- private void writeTimeLineReport (Map < String , TimeLineGroup > timeLineGroups , List <TimeLineItem > timeLineItems )
199+ private void writeTimeLineReport (List < TimeLineGroup > timeLineGroups , List <TimeLineItem > timeLineItems )
200200 throws IOException {
201201 writeReportJs (timeLineGroups , timeLineItems );
202202 copyReportFiles ();
203203 }
204204
205- private void writeReportJs (Map < String , TimeLineGroup > timeLineGroups , List <TimeLineItem > timeLineItems )
205+ private void writeReportJs (List < TimeLineGroup > timeLineGroups , List <TimeLineItem > timeLineItems )
206206 throws IOException {
207207 File reportJsFile = new File (reportDir , "report.js" );
208208 try (BufferedWriter reportJs = Files .newBufferedWriter (reportJsFile .toPath (), StandardCharsets .UTF_8 )) {
@@ -212,7 +212,7 @@ private void writeReportJs(Map<String, TimeLineGroup> timeLineGroups, List<TimeL
212212 reportJs .append ("\n " );
213213 // Need to sort groups by id, so can guarantee output of order in
214214 // rendered timeline
215- appendAsJsonToJs (reportJs , "timelineGroups" , new TreeMap <>( timeLineGroups ). values () );
215+ appendAsJsonToJs (reportJs , "timelineGroups" , timeLineGroups );
216216 reportJs .append ("\n " );
217217 reportJs .append ("});" );
218218 }
@@ -254,18 +254,18 @@ private static void copyFile(InputStream source, File dest) throws IOException {
254254
255255 static class TimeLineGroup {
256256
257- private long id ;
257+ private String id ;
258258 private String content ;
259259
260- public void setId (long id ) {
260+ public void setId (String id ) {
261261 this .id = id ;
262262 }
263263
264264 public void setContent (String content ) {
265265 this .content = content ;
266266 }
267267
268- public long getId () {
268+ public String getId () {
269269 return id ;
270270 }
271271
@@ -281,7 +281,7 @@ static class TimeLineItem {
281281 private String feature ;
282282 private String scenario ;
283283 private long start ;
284- private long group ;
284+ private String group ;
285285 private String content = "" ; // Replaced in JS file
286286 private String tags ;
287287 private long end ;
@@ -303,7 +303,7 @@ public void setStart(long start) {
303303 this .start = start ;
304304 }
305305
306- public void setGroup (long group ) {
306+ public void setGroup (String group ) {
307307 this .group = group ;
308308 }
309309
@@ -339,7 +339,7 @@ public long getStart() {
339339 return start ;
340340 }
341341
342- public long getGroup () {
342+ public String getGroup () {
343343 return group ;
344344 }
345345
0 commit comments