@@ -125,29 +125,90 @@ void testInScope_childScopeCloseThrows() {
125125 inOrder .verify (scope1 ).close ();
126126 }
127127
128+ @ Test
129+ void testInScope_nullChildScope_isSkipped () {
130+ ApiTracer .Scope scope1 =
131+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
132+
133+ when (child1 .inScope ()).thenReturn (scope1 );
134+ when (child2 .inScope ()).thenReturn (null );
135+
136+ ApiTracer .Scope compositeScope = compositeTracer .inScope ();
137+ compositeScope .close ();
138+
139+ verify (scope1 ).close ();
140+ }
141+
128142 @ Test
129143 void testOperationSucceeded () {
144+ ApiTracer .Scope scope1 =
145+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
146+ ApiTracer .Scope scope2 =
147+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
148+ when (child1 .inScope ()).thenReturn (scope1 );
149+ when (child2 .inScope ()).thenReturn (scope2 );
150+
130151 compositeTracer .operationSucceeded ();
131- InOrder inOrder = inOrder (child2 , child1 );
152+
153+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
154+ inOrder .verify (child1 ).inScope ();
155+ inOrder .verify (child2 ).inScope ();
132156 inOrder .verify (child2 ).operationSucceeded ();
133157 inOrder .verify (child1 ).operationSucceeded ();
158+ inOrder .verify (scope2 ).close ();
159+ inOrder .verify (scope1 ).close ();
134160 }
135161
136162 @ Test
137163 void testOperationCancelled () {
164+ ApiTracer .Scope scope1 =
165+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
166+ ApiTracer .Scope scope2 =
167+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
168+ when (child1 .inScope ()).thenReturn (scope1 );
169+ when (child2 .inScope ()).thenReturn (scope2 );
170+
138171 compositeTracer .operationCancelled ();
139- InOrder inOrder = inOrder (child2 , child1 );
172+
173+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
174+ inOrder .verify (child1 ).inScope ();
175+ inOrder .verify (child2 ).inScope ();
140176 inOrder .verify (child2 ).operationCancelled ();
141177 inOrder .verify (child1 ).operationCancelled ();
178+ inOrder .verify (scope2 ).close ();
179+ inOrder .verify (scope1 ).close ();
142180 }
143181
144182 @ Test
145183 void testOperationFailed () {
184+ ApiTracer .Scope scope1 =
185+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
186+ ApiTracer .Scope scope2 =
187+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
188+ when (child1 .inScope ()).thenReturn (scope1 );
189+ when (child2 .inScope ()).thenReturn (scope2 );
190+
146191 Throwable error = new RuntimeException ("test error" );
147192 compositeTracer .operationFailed (error );
148- InOrder inOrder = inOrder (child2 , child1 );
193+
194+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
195+ inOrder .verify (child1 ).inScope ();
196+ inOrder .verify (child2 ).inScope ();
149197 inOrder .verify (child2 ).operationFailed (error );
150198 inOrder .verify (child1 ).operationFailed (error );
199+ inOrder .verify (scope2 ).close ();
200+ inOrder .verify (scope1 ).close ();
201+ }
202+
203+ @ Test
204+ void testOperationSucceeded_whenInScopeThrows_stillNotifiesChildren () {
205+ when (child1 .inScope ()).thenThrow (new RuntimeException ("scope failure" ));
206+
207+ compositeTracer .operationSucceeded ();
208+
209+ InOrder inOrder = inOrder (child2 , child1 );
210+ inOrder .verify (child2 ).operationSucceeded ();
211+ inOrder .verify (child1 ).operationSucceeded ();
151212 }
152213
153214 @ Test
@@ -176,57 +237,129 @@ void testAttemptStarted() {
176237
177238 @ Test
178239 void testAttemptSucceeded () {
240+ ApiTracer .Scope scope1 =
241+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
242+ ApiTracer .Scope scope2 =
243+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
244+ when (child1 .inScope ()).thenReturn (scope1 );
245+ when (child2 .inScope ()).thenReturn (scope2 );
246+
179247 compositeTracer .attemptSucceeded ();
180- InOrder inOrder = inOrder (child2 , child1 );
248+
249+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
250+ inOrder .verify (child1 ).inScope ();
251+ inOrder .verify (child2 ).inScope ();
181252 inOrder .verify (child2 ).attemptSucceeded ();
182253 inOrder .verify (child1 ).attemptSucceeded ();
254+ inOrder .verify (scope2 ).close ();
255+ inOrder .verify (scope1 ).close ();
183256 }
184257
185258 @ Test
186259 void testAttemptCancelled () {
260+ ApiTracer .Scope scope1 =
261+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
262+ ApiTracer .Scope scope2 =
263+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
264+ when (child1 .inScope ()).thenReturn (scope1 );
265+ when (child2 .inScope ()).thenReturn (scope2 );
266+
187267 compositeTracer .attemptCancelled ();
188- InOrder inOrder = inOrder (child2 , child1 );
268+
269+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
270+ inOrder .verify (child1 ).inScope ();
271+ inOrder .verify (child2 ).inScope ();
189272 inOrder .verify (child2 ).attemptCancelled ();
190273 inOrder .verify (child1 ).attemptCancelled ();
274+ inOrder .verify (scope2 ).close ();
275+ inOrder .verify (scope1 ).close ();
191276 }
192277
193278 @ Test
194279 @ SuppressWarnings ("deprecation" )
195280 void testAttemptFailedDeprecated () {
281+ ApiTracer .Scope scope1 =
282+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
283+ ApiTracer .Scope scope2 =
284+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
285+ when (child1 .inScope ()).thenReturn (scope1 );
286+ when (child2 .inScope ()).thenReturn (scope2 );
287+
196288 Throwable error = new RuntimeException ("test error" );
197289 org .threeten .bp .Duration delay = org .threeten .bp .Duration .ofSeconds (1 );
198290 compositeTracer .attemptFailed (error , delay );
199- InOrder inOrder = inOrder (child2 , child1 );
291+
292+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
293+ inOrder .verify (child1 ).inScope ();
294+ inOrder .verify (child2 ).inScope ();
200295 inOrder .verify (child2 ).attemptFailed (error , delay );
201296 inOrder .verify (child1 ).attemptFailed (error , delay );
297+ inOrder .verify (scope2 ).close ();
298+ inOrder .verify (scope1 ).close ();
202299 }
203300
204301 @ Test
205302 void testAttemptFailedDuration () {
303+ ApiTracer .Scope scope1 =
304+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
305+ ApiTracer .Scope scope2 =
306+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
307+ when (child1 .inScope ()).thenReturn (scope1 );
308+ when (child2 .inScope ()).thenReturn (scope2 );
309+
206310 Throwable error = new RuntimeException ("test error" );
207311 java .time .Duration delay = java .time .Duration .ofSeconds (1 );
208312 compositeTracer .attemptFailedDuration (error , delay );
209- InOrder inOrder = inOrder (child2 , child1 );
313+
314+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
315+ inOrder .verify (child1 ).inScope ();
316+ inOrder .verify (child2 ).inScope ();
210317 inOrder .verify (child2 ).attemptFailedDuration (error , delay );
211318 inOrder .verify (child1 ).attemptFailedDuration (error , delay );
319+ inOrder .verify (scope2 ).close ();
320+ inOrder .verify (scope1 ).close ();
212321 }
213322
214323 @ Test
215324 void testAttemptFailedRetriesExhausted () {
325+ ApiTracer .Scope scope1 =
326+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
327+ ApiTracer .Scope scope2 =
328+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
329+ when (child1 .inScope ()).thenReturn (scope1 );
330+ when (child2 .inScope ()).thenReturn (scope2 );
331+
216332 Throwable error = new RuntimeException ("test error" );
217333 compositeTracer .attemptFailedRetriesExhausted (error );
218- InOrder inOrder = inOrder (child2 , child1 );
334+
335+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
336+ inOrder .verify (child1 ).inScope ();
337+ inOrder .verify (child2 ).inScope ();
219338 inOrder .verify (child2 ).attemptFailedRetriesExhausted (error );
220339 inOrder .verify (child1 ).attemptFailedRetriesExhausted (error );
340+ inOrder .verify (scope2 ).close ();
341+ inOrder .verify (scope1 ).close ();
221342 }
222343
223344 @ Test
224345 void testAttemptPermanentFailure () {
346+ ApiTracer .Scope scope1 =
347+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
348+ ApiTracer .Scope scope2 =
349+ mock (ApiTracer .Scope .class , Mockito .withSettings ().withoutAnnotations ());
350+ when (child1 .inScope ()).thenReturn (scope1 );
351+ when (child2 .inScope ()).thenReturn (scope2 );
352+
225353 Throwable error = new RuntimeException ("test error" );
226354 compositeTracer .attemptPermanentFailure (error );
227- InOrder inOrder = inOrder (child2 , child1 );
355+
356+ InOrder inOrder = inOrder (child1 , child2 , scope2 , scope1 );
357+ inOrder .verify (child1 ).inScope ();
358+ inOrder .verify (child2 ).inScope ();
228359 inOrder .verify (child2 ).attemptPermanentFailure (error );
229360 inOrder .verify (child1 ).attemptPermanentFailure (error );
361+ inOrder .verify (scope2 ).close ();
362+ inOrder .verify (scope1 ).close ();
230363 }
231364
232365 @ Test
0 commit comments