Skip to content

Commit 99fa74b

Browse files
committed
compute testStatus using generatedLog
1 parent 0df5795 commit 99fa74b

1 file changed

Lines changed: 33 additions & 26 deletions

File tree

  • src/main/java/com/aventstack/extentreports/model

src/main/java/com/aventstack/extentreports/model/Test.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public final class Test implements RunResult, Serializable, BaseEntity, MetaData
6767
private final Set<Device> deviceSet = ConcurrentHashMap.newKeySet();
6868
private final List<Log> generatedLog = Collections.synchronizedList(new ArrayList<>());
6969

70-
public final void addChild(Test child) {
70+
public void addChild(Test child) {
7171
Assert.notNull(child, "Node must not be null");
7272
child.setLevel(level + 1);
7373
child.setParent(this);
@@ -85,68 +85,68 @@ public final void addChild(Test child) {
8585
private void end(Status evtStatus) {
8686
setStatus(Status.max(status, evtStatus));
8787
if (useNaturalConf)
88-
propogateTime();
88+
propagateTime();
8989
}
9090

91-
private void propogateTime() {
91+
private void propagateTime() {
9292
setEndTime(Calendar.getInstance().getTime());
9393
if (parent != null)
94-
parent.propogateTime();
94+
parent.propagateTime();
9595
}
9696

97-
public final void addLog(Log log) {
97+
public void addLog(Log log) {
9898
addLog(log, logs);
9999
}
100100

101-
public final void addGeneratedLog(Log log) {
101+
public void addGeneratedLog(Log log) {
102102
addLog(log, generatedLog);
103103
}
104104

105-
private final void addLog(Log log, List<Log> list) {
105+
private void addLog(Log log, List<Log> list) {
106106
Assert.notNull(log, "Log must not be null");
107107
log.setSeq(list.size());
108108
list.add(log);
109109
end(log.getStatus());
110110
updateResult();
111111
}
112112

113-
public final boolean isBDD() {
113+
public boolean isBDD() {
114114
return getBddType() != null;
115115
}
116116

117-
public final boolean hasLog() {
117+
public boolean hasLog() {
118118
return !logs.isEmpty();
119119
}
120120

121-
public final boolean hasAnyLog() {
121+
public boolean hasAnyLog() {
122122
return !logs.isEmpty() || !generatedLog.isEmpty();
123123
}
124124

125-
public final boolean hasChildren() {
125+
public boolean hasChildren() {
126126
return !children.isEmpty();
127127
}
128128

129-
public final boolean hasAttributes() {
129+
public boolean hasAttributes() {
130130
return hasAuthor() || hasCategory() || hasDevice();
131131
}
132132

133-
public final boolean hasAuthor() {
133+
public boolean hasAuthor() {
134134
return !authorSet.isEmpty();
135135
}
136136

137-
public final boolean hasCategory() {
137+
public boolean hasCategory() {
138138
return !categorySet.isEmpty();
139139
}
140140

141-
public final boolean hasDevice() {
141+
public boolean hasDevice() {
142142
return !deviceSet.isEmpty();
143143
}
144144

145-
public final boolean hasException() {
145+
public boolean hasException() {
146146
return !exceptions.isEmpty();
147147
}
148148

149-
public final String getFullName() {
149+
public String getFullName() {
150150
Test test = this;
151151
StringBuilder sb = new StringBuilder(test.getName());
152152
while (test.getParent() != null) {
@@ -157,18 +157,18 @@ public final String getFullName() {
157157
return sb.toString();
158158
}
159159

160-
public final void addMedia(Media m) {
160+
public void addMedia(Media m) {
161161
if (m != null
162162
&& (m.getPath() != null || m.getResolvedPath() != null || ((ScreenCapture) m).getBase64() != null))
163163
media.add(m);
164164
end(status);
165165
}
166166

167-
public final boolean hasScreenCapture() {
167+
public boolean hasScreenCapture() {
168168
return !media.isEmpty() && media.stream().anyMatch(x -> x instanceof ScreenCapture);
169169
}
170170

171-
public final long timeTaken() {
171+
public long timeTaken() {
172172
return endTime.getTime() - startTime.getTime();
173173
}
174174

@@ -180,7 +180,7 @@ public final long timeTaken() {
180180
*
181181
* @return A formatted time taken string as HH:mm:ss:SSS
182182
*/
183-
public final String timeTakenPretty() {
183+
public String timeTakenPretty() {
184184
Date date = new Date(timeTaken());
185185
DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
186186
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -195,14 +195,14 @@ public List<ExceptionInfo> aggregateExceptions() {
195195
.collect(Collectors.toList());
196196
}
197197

198-
public final Test getAncestor() {
198+
public Test getAncestor() {
199199
Test test = this;
200200
while (test.getParent() != null)
201201
test = test.getParent();
202202
return test;
203203
}
204204

205-
public final void updateResult() {
205+
public void updateResult() {
206206
determinator.computeTestStatus();
207207
}
208208

@@ -231,10 +231,17 @@ private void computeStatus(List<Test> testList) {
231231

232232
private void computeStatus(Test t) {
233233
Set<Status> set = new HashSet<>();
234-
Iterator<Log> iter = new ArrayList<>(t.getLogs()).iterator();
235-
while (iter.hasNext())
236-
set.add(iter.next().getStatus());
237234
set.add(t.getStatus());
235+
synchronized(t.getLogs()) {
236+
set.addAll(t.getLogs().stream()
237+
.map(Log::getStatus)
238+
.collect(Collectors.toSet()));
239+
}
240+
synchronized (t.getGeneratedLog()) {
241+
set.addAll(t.getGeneratedLog().stream()
242+
.map(Log::getStatus)
243+
.collect(Collectors.toSet()));
244+
}
238245
t.setStatus(Status.max(set));
239246
if (t.getParent() != null) {
240247
t.getParent().setStatus(Status.max(t.getStatus(), t.getParent().getStatus()));

0 commit comments

Comments
 (0)