2525@ ToString (includeFieldNames = true )
2626public class Report implements Serializable , BaseEntity {
2727 private static final long serialVersionUID = -8667496631392333349L ;
28-
29- private final Object obj = new Object ();
3028
3129 @ Builder .Default
3230 private Date startTime = Calendar .getInstance ().getTime ();
@@ -47,66 +45,93 @@ public final void refresh() {
4745 authorCtx .getSet ().forEach (x -> x .refresh ());
4846 categoryCtx .getSet ().forEach (x -> x .refresh ());
4947 deviceCtx .getSet ().forEach (x -> x .refresh ());
50- stats . update (testList );
51- synchronized ( obj ) {
48+ synchronized (testList ) {
49+ stats . update ( testList );
5250 setEndTime (Calendar .getInstance ().getTime ());
5351 }
5452 }
53+
54+ public void addTest (Test test ) {
55+ testList .add (test );
56+ }
57+
58+ public boolean removeTest (Test test ) {
59+ synchronized (testList ) {
60+ return removeTest (testList , test );
61+ }
62+ }
5563
64+ private boolean removeTest (List <Test > testList , Test test ) {
65+ boolean removed = testList .removeIf (x -> x .getId () == test .getId ());
66+ if (!removed )
67+ testList .forEach (x -> removeTest (x .getChildren (), test ));
68+ return removed ;
69+ }
70+
5671 public final void applyOverrideConf () {
57- Date min = testList . stream ()
58- . map ( t -> t . getStartTime () )
59- . min ( Date :: compareTo )
60- . get ();
61- Date max = testList . stream ()
62- . map ( t -> t . getEndTime () )
63- . max ( Date :: compareTo )
64- . get ();
65- synchronized ( obj ) {
72+ synchronized ( testList ) {
73+ Date min = testList . stream ( )
74+ . map ( t -> t . getStartTime () )
75+ . min ( Date :: compareTo )
76+ . get ();
77+ Date max = testList . stream ( )
78+ . map ( t -> t . getEndTime () )
79+ . max ( Date :: compareTo )
80+ . get ();
6681 setStartTime (min );
6782 setEndTime (max );
6883 }
6984 }
7085
7186 public final boolean isBDD () {
72- return !testList .isEmpty () && testList .stream ().allMatch (Test ::isBDD );
87+ synchronized (testList ) {
88+ return !testList .isEmpty () && testList .stream ().allMatch (Test ::isBDD );
89+ }
7390 }
7491
7592 public final boolean anyTestHasStatus (Status status ) {
76- return testList .stream ()
93+ synchronized (testList ) {
94+ return testList .stream ()
7795 .anyMatch (x -> x .getStatus () == status );
96+ }
7897 }
7998
8099 public Optional <Test > findTest (List <Test > list , String name ) {
81- Optional <Test > test = list .stream ().filter (x -> x .getName ().equals (name )).findFirst ();
82- if (!test .isPresent ())
83- for (Test t : list )
84- return findTest (t .getChildren (), name );
85- return test ;
100+ synchronized (testList ) {
101+ Optional <Test > test = list .stream ().filter (x -> x .getName ().equals (name )).findFirst ();
102+ if (!test .isPresent ())
103+ for (Test t : list )
104+ return findTest (t .getChildren (), name );
105+ return test ;
106+ }
86107 }
87108
88109 public List <ExceptionInfo > aggregateExceptions (List <Test > testList ) {
89- List <ExceptionInfo > list = new ArrayList <>();
90- for (Test test : testList ) {
91- list .addAll (test .aggregateExceptions ());
92- if (!test .getChildren ().isEmpty ())
93- aggregateExceptions (test .getChildren ());
110+ synchronized (testList ) {
111+ List <ExceptionInfo > list = new ArrayList <>();
112+ for (Test test : testList ) {
113+ list .addAll (test .aggregateExceptions ());
114+ if (!test .getChildren ().isEmpty ())
115+ aggregateExceptions (test .getChildren ());
116+ }
117+ return list ;
94118 }
95- return list ;
96119 }
97120
98121 public final long timeTaken () {
99122 return endTime .getTime () - startTime .getTime ();
100123 }
101124
102125 public final Status getStatus () {
103- List <Status > list = testList
126+ synchronized (testList ) {
127+ List <Status > list = testList
104128 .stream ()
105129 .map (x -> x .getStatus ())
106130 .collect (Collectors .toList ());
107- Status s = Status .max (list );
108- if (s == Status .SKIP && anyTestHasStatus (Status .PASS ))
109- s = Status .PASS ;
110- return s ;
131+ Status s = Status .max (list );
132+ if (s == Status .SKIP && anyTestHasStatus (Status .PASS ))
133+ s = Status .PASS ;
134+ return s ;
135+ }
111136 }
112137}
0 commit comments