1 /*
2  * Copyright (C) 2015 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.producers.monitoring.internal;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.ArgumentMatchers.any;
21 import static org.mockito.ArgumentMatchers.nullable;
22 import static org.mockito.Mockito.doThrow;
23 import static org.mockito.Mockito.inOrder;
24 import static org.mockito.Mockito.verifyNoMoreInteractions;
25 import static org.mockito.Mockito.when;
26 
27 import com.google.common.collect.ImmutableList;
28 import dagger.producers.monitoring.ProducerMonitor;
29 import dagger.producers.monitoring.ProducerToken;
30 import dagger.producers.monitoring.ProductionComponentMonitor;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.junit.runners.JUnit4;
35 import org.mockito.InOrder;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 
39 @RunWith(JUnit4.class)
40 public final class MonitorsTest {
41   @Mock private ProductionComponentMonitor.Factory mockProductionComponentMonitorFactory;
42   @Mock private ProductionComponentMonitor mockProductionComponentMonitor;
43   @Mock private ProducerMonitor mockProducerMonitor;
44   @Mock private ProductionComponentMonitor.Factory mockProductionComponentMonitorFactoryA;
45   @Mock private ProductionComponentMonitor.Factory mockProductionComponentMonitorFactoryB;
46   @Mock private ProductionComponentMonitor.Factory mockProductionComponentMonitorFactoryC;
47   @Mock private ProductionComponentMonitor mockProductionComponentMonitorA;
48   @Mock private ProductionComponentMonitor mockProductionComponentMonitorB;
49   @Mock private ProductionComponentMonitor mockProductionComponentMonitorC;
50   @Mock private ProducerMonitor mockProducerMonitorA;
51   @Mock private ProducerMonitor mockProducerMonitorB;
52   @Mock private ProducerMonitor mockProducerMonitorC;
53 
54   @Before
initMocks()55   public void initMocks() {
56     MockitoAnnotations.initMocks(this);
57   }
58 
59   @Test
zeroMonitorsReturnsNoOp()60   public void zeroMonitorsReturnsNoOp() {
61     ProductionComponentMonitor.Factory factory =
62         Monitors.delegatingProductionComponentMonitorFactory(
63             ImmutableList.<ProductionComponentMonitor.Factory>of());
64     assertThat(factory).isSameInstanceAs(ProductionComponentMonitor.Factory.noOp());
65   }
66 
67   @Test
singleMonitor_nullProductionComponentMonitor()68   public void singleMonitor_nullProductionComponentMonitor() {
69     when(mockProductionComponentMonitorFactory.create(any(Object.class))).thenReturn(null);
70     ProductionComponentMonitor.Factory factory =
71         Monitors.delegatingProductionComponentMonitorFactory(
72             ImmutableList.of(mockProductionComponentMonitorFactory));
73     assertThat(factory.create(new Object())).isSameInstanceAs(ProductionComponentMonitor.noOp());
74   }
75 
76   @Test
singleMonitor_throwingProductionComponentMonitorFactory()77   public void singleMonitor_throwingProductionComponentMonitorFactory() {
78     doThrow(new RuntimeException("monkey"))
79         .when(mockProductionComponentMonitorFactory)
80         .create(any(Object.class));
81     ProductionComponentMonitor.Factory factory =
82         Monitors.delegatingProductionComponentMonitorFactory(
83             ImmutableList.of(mockProductionComponentMonitorFactory));
84     assertThat(factory.create(new Object())).isSameInstanceAs(ProductionComponentMonitor.noOp());
85   }
86 
87   @Test
singleMonitor_nullProducerMonitor()88   public void singleMonitor_nullProducerMonitor() {
89     when(mockProductionComponentMonitorFactory.create(any(Object.class)))
90         .thenReturn(mockProductionComponentMonitor);
91     when(mockProductionComponentMonitor.producerMonitorFor(nullable(ProducerToken.class)))
92         .thenReturn(null);
93     ProductionComponentMonitor.Factory factory =
94         Monitors.delegatingProductionComponentMonitorFactory(
95             ImmutableList.of(mockProductionComponentMonitorFactory));
96     ProductionComponentMonitor monitor = factory.create(new Object());
97     assertThat(monitor.producerMonitorFor(ProducerToken.create(Object.class)))
98         .isSameInstanceAs(ProducerMonitor.noOp());
99   }
100 
101   @Test
singleMonitor_throwingProductionComponentMonitor()102   public void singleMonitor_throwingProductionComponentMonitor() {
103     when(mockProductionComponentMonitorFactory.create(any(Object.class)))
104         .thenReturn(mockProductionComponentMonitor);
105     doThrow(new RuntimeException("monkey"))
106         .when(mockProductionComponentMonitor)
107         .producerMonitorFor(nullable(ProducerToken.class));
108     ProductionComponentMonitor.Factory factory =
109         Monitors.delegatingProductionComponentMonitorFactory(
110             ImmutableList.of(mockProductionComponentMonitorFactory));
111     ProductionComponentMonitor monitor = factory.create(new Object());
112     assertThat(monitor.producerMonitorFor(ProducerToken.create(Object.class)))
113         .isSameInstanceAs(ProducerMonitor.noOp());
114   }
115 
116   @Test
singleMonitor_normalProducerMonitorSuccess()117   public void singleMonitor_normalProducerMonitorSuccess() {
118     setUpNormalSingleMonitor();
119     ProductionComponentMonitor.Factory factory =
120         Monitors.delegatingProductionComponentMonitorFactory(
121             ImmutableList.of(mockProductionComponentMonitorFactory));
122     ProductionComponentMonitor monitor = factory.create(new Object());
123     ProducerMonitor producerMonitor =
124         monitor.producerMonitorFor(ProducerToken.create(Object.class));
125     Object o = new Object();
126     producerMonitor.requested();
127     producerMonitor.methodStarting();
128     producerMonitor.methodFinished();
129     producerMonitor.succeeded(o);
130 
131     InOrder order = inOrder(mockProducerMonitor);
132     order.verify(mockProducerMonitor).requested();
133     order.verify(mockProducerMonitor).methodStarting();
134     order.verify(mockProducerMonitor).methodFinished();
135     order.verify(mockProducerMonitor).succeeded(o);
136     verifyNoMoreInteractions(mockProducerMonitor);
137   }
138 
139   @Test
singleMonitor_normalProducerMonitorFailure()140   public void singleMonitor_normalProducerMonitorFailure() {
141     setUpNormalSingleMonitor();
142     ProductionComponentMonitor.Factory factory =
143         Monitors.delegatingProductionComponentMonitorFactory(
144             ImmutableList.of(mockProductionComponentMonitorFactory));
145     ProductionComponentMonitor monitor = factory.create(new Object());
146     ProducerMonitor producerMonitor =
147         monitor.producerMonitorFor(ProducerToken.create(Object.class));
148     Throwable t = new RuntimeException("monkey");
149     producerMonitor.requested();
150     producerMonitor.methodStarting();
151     producerMonitor.methodFinished();
152     producerMonitor.failed(t);
153 
154     InOrder order = inOrder(mockProducerMonitor);
155     order.verify(mockProducerMonitor).requested();
156     order.verify(mockProducerMonitor).methodStarting();
157     order.verify(mockProducerMonitor).methodFinished();
158     order.verify(mockProducerMonitor).failed(t);
159     verifyNoMoreInteractions(mockProducerMonitor);
160   }
161 
162   @Test
singleMonitor_throwingProducerMonitorSuccess()163   public void singleMonitor_throwingProducerMonitorSuccess() {
164     setUpNormalSingleMonitor();
165     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).requested();
166     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).methodStarting();
167     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).methodFinished();
168     doThrow(new RuntimeException("monkey"))
169         .when(mockProducerMonitor)
170         .succeeded(nullable(Object.class));
171     ProductionComponentMonitor.Factory factory =
172         Monitors.delegatingProductionComponentMonitorFactory(
173             ImmutableList.of(mockProductionComponentMonitorFactory));
174     ProductionComponentMonitor monitor = factory.create(new Object());
175     ProducerMonitor producerMonitor =
176         monitor.producerMonitorFor(ProducerToken.create(Object.class));
177     Object o = new Object();
178     producerMonitor.requested();
179     producerMonitor.methodStarting();
180     producerMonitor.methodFinished();
181     producerMonitor.succeeded(o);
182 
183     InOrder order = inOrder(mockProducerMonitor);
184     order.verify(mockProducerMonitor).requested();
185     order.verify(mockProducerMonitor).methodStarting();
186     order.verify(mockProducerMonitor).methodFinished();
187     order.verify(mockProducerMonitor).succeeded(o);
188     verifyNoMoreInteractions(mockProducerMonitor);
189   }
190 
191   @Test
singleMonitor_throwingProducerMonitorFailure()192   public void singleMonitor_throwingProducerMonitorFailure() {
193     setUpNormalSingleMonitor();
194     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).requested();
195     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).methodStarting();
196     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).methodFinished();
197     doThrow(new RuntimeException("monkey")).when(mockProducerMonitor).failed(any(Throwable.class));
198     ProductionComponentMonitor.Factory factory =
199         Monitors.delegatingProductionComponentMonitorFactory(
200             ImmutableList.of(mockProductionComponentMonitorFactory));
201     ProductionComponentMonitor monitor = factory.create(new Object());
202     ProducerMonitor producerMonitor =
203         monitor.producerMonitorFor(ProducerToken.create(Object.class));
204     Throwable t = new RuntimeException("gorilla");
205     producerMonitor.requested();
206     producerMonitor.methodStarting();
207     producerMonitor.methodFinished();
208     producerMonitor.failed(t);
209 
210     InOrder order = inOrder(mockProducerMonitor);
211     order.verify(mockProducerMonitor).requested();
212     order.verify(mockProducerMonitor).methodStarting();
213     order.verify(mockProducerMonitor).methodFinished();
214     order.verify(mockProducerMonitor).failed(t);
215     verifyNoMoreInteractions(mockProducerMonitor);
216   }
217 
218   @Test
multipleMonitors_nullProductionComponentMonitors()219   public void multipleMonitors_nullProductionComponentMonitors() {
220     when(mockProductionComponentMonitorFactoryA.create(any(Object.class))).thenReturn(null);
221     when(mockProductionComponentMonitorFactoryB.create(any(Object.class))).thenReturn(null);
222     when(mockProductionComponentMonitorFactoryC.create(any(Object.class))).thenReturn(null);
223     ProductionComponentMonitor.Factory factory =
224         Monitors.delegatingProductionComponentMonitorFactory(
225             ImmutableList.of(
226                 mockProductionComponentMonitorFactoryA,
227                 mockProductionComponentMonitorFactoryB,
228                 mockProductionComponentMonitorFactoryC));
229     assertThat(factory.create(new Object())).isSameInstanceAs(ProductionComponentMonitor.noOp());
230   }
231 
232   @Test
multipleMonitors_throwingProductionComponentMonitorFactories()233   public void multipleMonitors_throwingProductionComponentMonitorFactories() {
234     doThrow(new RuntimeException("monkey"))
235         .when(mockProductionComponentMonitorFactoryA)
236         .create(any(Object.class));
237     doThrow(new RuntimeException("monkey"))
238         .when(mockProductionComponentMonitorFactoryB)
239         .create(any(Object.class));
240     doThrow(new RuntimeException("monkey"))
241         .when(mockProductionComponentMonitorFactoryC)
242         .create(any(Object.class));
243     ProductionComponentMonitor.Factory factory =
244         Monitors.delegatingProductionComponentMonitorFactory(
245             ImmutableList.of(
246                 mockProductionComponentMonitorFactoryA,
247                 mockProductionComponentMonitorFactoryB,
248                 mockProductionComponentMonitorFactoryC));
249     assertThat(factory.create(new Object())).isSameInstanceAs(ProductionComponentMonitor.noOp());
250   }
251 
252   @Test
multipleMonitors_someNullProductionComponentMonitors()253   public void multipleMonitors_someNullProductionComponentMonitors() {
254     when(mockProductionComponentMonitorFactoryA.create(any(Object.class)))
255         .thenReturn(mockProductionComponentMonitorA);
256     when(mockProductionComponentMonitorFactoryB.create(any(Object.class))).thenReturn(null);
257     when(mockProductionComponentMonitorFactoryC.create(any(Object.class))).thenReturn(null);
258     when(mockProductionComponentMonitorA.producerMonitorFor(nullable(ProducerToken.class)))
259         .thenReturn(mockProducerMonitorA);
260     ProductionComponentMonitor.Factory factory =
261         Monitors.delegatingProductionComponentMonitorFactory(
262             ImmutableList.of(
263                 mockProductionComponentMonitorFactoryA,
264                 mockProductionComponentMonitorFactoryB,
265                 mockProductionComponentMonitorFactoryC));
266     ProductionComponentMonitor monitor = factory.create(new Object());
267     ProducerMonitor producerMonitor =
268         monitor.producerMonitorFor(ProducerToken.create(Object.class));
269 
270     Object o = new Object();
271     producerMonitor.requested();
272     producerMonitor.methodStarting();
273     producerMonitor.methodFinished();
274     producerMonitor.succeeded(o);
275 
276     InOrder order = inOrder(mockProducerMonitorA);
277     order.verify(mockProducerMonitorA).requested();
278     order.verify(mockProducerMonitorA).methodStarting();
279     order.verify(mockProducerMonitorA).methodFinished();
280     order.verify(mockProducerMonitorA).succeeded(o);
281     verifyNoMoreInteractions(mockProducerMonitorA);
282   }
283 
284   @Test
multipleMonitors_someThrowingProductionComponentMonitorFactories()285   public void multipleMonitors_someThrowingProductionComponentMonitorFactories() {
286     when(mockProductionComponentMonitorFactoryA.create(any(Object.class)))
287         .thenReturn(mockProductionComponentMonitorA);
288     doThrow(new RuntimeException("monkey"))
289         .when(mockProductionComponentMonitorFactoryB)
290         .create(any(Object.class));
291     doThrow(new RuntimeException("monkey"))
292         .when(mockProductionComponentMonitorFactoryC)
293         .create(any(Object.class));
294     when(mockProductionComponentMonitorA.producerMonitorFor(nullable(ProducerToken.class)))
295         .thenReturn(mockProducerMonitorA);
296     ProductionComponentMonitor.Factory factory =
297         Monitors.delegatingProductionComponentMonitorFactory(
298             ImmutableList.of(
299                 mockProductionComponentMonitorFactoryA,
300                 mockProductionComponentMonitorFactoryB,
301                 mockProductionComponentMonitorFactoryC));
302     ProductionComponentMonitor monitor = factory.create(new Object());
303     ProducerMonitor producerMonitor =
304         monitor.producerMonitorFor(ProducerToken.create(Object.class));
305 
306     Object o = new Object();
307     producerMonitor.requested();
308     producerMonitor.methodStarting();
309     producerMonitor.methodFinished();
310     producerMonitor.succeeded(o);
311 
312     InOrder order = inOrder(mockProducerMonitorA);
313     order.verify(mockProducerMonitorA).requested();
314     order.verify(mockProducerMonitorA).methodStarting();
315     order.verify(mockProducerMonitorA).methodFinished();
316     order.verify(mockProducerMonitorA).succeeded(o);
317     verifyNoMoreInteractions(mockProducerMonitorA);
318   }
319 
320   @Test
multipleMonitors_normalProductionComponentMonitorSuccess()321   public void multipleMonitors_normalProductionComponentMonitorSuccess() {
322     setUpNormalMultipleMonitors();
323     ProductionComponentMonitor.Factory factory =
324         Monitors.delegatingProductionComponentMonitorFactory(
325             ImmutableList.of(
326                 mockProductionComponentMonitorFactoryA,
327                 mockProductionComponentMonitorFactoryB,
328                 mockProductionComponentMonitorFactoryC));
329     ProductionComponentMonitor monitor = factory.create(new Object());
330     ProducerMonitor producerMonitor =
331         monitor.producerMonitorFor(ProducerToken.create(Object.class));
332 
333     Object o = new Object();
334     producerMonitor.requested();
335     producerMonitor.methodStarting();
336     producerMonitor.methodFinished();
337     producerMonitor.succeeded(o);
338 
339     InOrder order = inOrder(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
340     order.verify(mockProducerMonitorA).requested();
341     order.verify(mockProducerMonitorB).requested();
342     order.verify(mockProducerMonitorC).requested();
343     order.verify(mockProducerMonitorA).methodStarting();
344     order.verify(mockProducerMonitorB).methodStarting();
345     order.verify(mockProducerMonitorC).methodStarting();
346     order.verify(mockProducerMonitorC).methodFinished();
347     order.verify(mockProducerMonitorB).methodFinished();
348     order.verify(mockProducerMonitorA).methodFinished();
349     order.verify(mockProducerMonitorC).succeeded(o);
350     order.verify(mockProducerMonitorB).succeeded(o);
351     order.verify(mockProducerMonitorA).succeeded(o);
352     verifyNoMoreInteractions(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
353   }
354 
355   @Test
multipleMonitors_normalProductionComponentMonitorFailure()356   public void multipleMonitors_normalProductionComponentMonitorFailure() {
357     setUpNormalMultipleMonitors();
358     ProductionComponentMonitor.Factory factory =
359         Monitors.delegatingProductionComponentMonitorFactory(
360             ImmutableList.of(
361                 mockProductionComponentMonitorFactoryA,
362                 mockProductionComponentMonitorFactoryB,
363                 mockProductionComponentMonitorFactoryC));
364     ProductionComponentMonitor monitor = factory.create(new Object());
365     ProducerMonitor producerMonitor =
366         monitor.producerMonitorFor(ProducerToken.create(Object.class));
367 
368     Throwable t = new RuntimeException("chimpanzee");
369     producerMonitor.requested();
370     producerMonitor.methodStarting();
371     producerMonitor.methodFinished();
372     producerMonitor.failed(t);
373 
374     InOrder order = inOrder(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
375     order.verify(mockProducerMonitorA).requested();
376     order.verify(mockProducerMonitorB).requested();
377     order.verify(mockProducerMonitorC).requested();
378     order.verify(mockProducerMonitorA).methodStarting();
379     order.verify(mockProducerMonitorB).methodStarting();
380     order.verify(mockProducerMonitorC).methodStarting();
381     order.verify(mockProducerMonitorC).methodFinished();
382     order.verify(mockProducerMonitorB).methodFinished();
383     order.verify(mockProducerMonitorA).methodFinished();
384     order.verify(mockProducerMonitorC).failed(t);
385     order.verify(mockProducerMonitorB).failed(t);
386     order.verify(mockProducerMonitorA).failed(t);
387     verifyNoMoreInteractions(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
388   }
389 
390   @Test
multipleMonitors_someThrowingProducerMonitorsSuccess()391   public void multipleMonitors_someThrowingProducerMonitorsSuccess() {
392     setUpNormalMultipleMonitors();
393     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorA).requested();
394     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorA).methodStarting();
395     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorB).methodFinished();
396     doThrow(new RuntimeException("monkey"))
397         .when(mockProducerMonitorC)
398         .succeeded(nullable(Object.class));
399     ProductionComponentMonitor.Factory factory =
400         Monitors.delegatingProductionComponentMonitorFactory(
401             ImmutableList.of(
402                 mockProductionComponentMonitorFactoryA,
403                 mockProductionComponentMonitorFactoryB,
404                 mockProductionComponentMonitorFactoryC));
405     ProductionComponentMonitor monitor = factory.create(new Object());
406     ProducerMonitor producerMonitor =
407         monitor.producerMonitorFor(ProducerToken.create(Object.class));
408 
409     Object o = new Object();
410     producerMonitor.requested();
411     producerMonitor.methodStarting();
412     producerMonitor.methodFinished();
413     producerMonitor.succeeded(o);
414 
415     InOrder order = inOrder(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
416     order.verify(mockProducerMonitorA).requested();
417     order.verify(mockProducerMonitorB).requested();
418     order.verify(mockProducerMonitorC).requested();
419     order.verify(mockProducerMonitorA).methodStarting();
420     order.verify(mockProducerMonitorB).methodStarting();
421     order.verify(mockProducerMonitorC).methodStarting();
422     order.verify(mockProducerMonitorC).methodFinished();
423     order.verify(mockProducerMonitorB).methodFinished();
424     order.verify(mockProducerMonitorA).methodFinished();
425     order.verify(mockProducerMonitorC).succeeded(o);
426     order.verify(mockProducerMonitorB).succeeded(o);
427     order.verify(mockProducerMonitorA).succeeded(o);
428     verifyNoMoreInteractions(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
429   }
430 
431   @Test
multipleMonitors_someThrowingProducerMonitorsFailure()432   public void multipleMonitors_someThrowingProducerMonitorsFailure() {
433     setUpNormalMultipleMonitors();
434     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorA).requested();
435     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorA).methodStarting();
436     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorB).methodFinished();
437     doThrow(new RuntimeException("monkey")).when(mockProducerMonitorC).failed(any(Throwable.class));
438     ProductionComponentMonitor.Factory factory =
439         Monitors.delegatingProductionComponentMonitorFactory(
440             ImmutableList.of(
441                 mockProductionComponentMonitorFactoryA,
442                 mockProductionComponentMonitorFactoryB,
443                 mockProductionComponentMonitorFactoryC));
444     ProductionComponentMonitor monitor = factory.create(new Object());
445     ProducerMonitor producerMonitor =
446         monitor.producerMonitorFor(ProducerToken.create(Object.class));
447 
448     Throwable t = new RuntimeException("chimpanzee");
449     producerMonitor.requested();
450     producerMonitor.methodStarting();
451     producerMonitor.methodFinished();
452     producerMonitor.failed(t);
453 
454     InOrder order = inOrder(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
455     order.verify(mockProducerMonitorA).requested();
456     order.verify(mockProducerMonitorB).requested();
457     order.verify(mockProducerMonitorC).requested();
458     order.verify(mockProducerMonitorA).methodStarting();
459     order.verify(mockProducerMonitorB).methodStarting();
460     order.verify(mockProducerMonitorC).methodStarting();
461     order.verify(mockProducerMonitorC).methodFinished();
462     order.verify(mockProducerMonitorB).methodFinished();
463     order.verify(mockProducerMonitorA).methodFinished();
464     order.verify(mockProducerMonitorC).failed(t);
465     order.verify(mockProducerMonitorB).failed(t);
466     order.verify(mockProducerMonitorA).failed(t);
467     verifyNoMoreInteractions(mockProducerMonitorA, mockProducerMonitorB, mockProducerMonitorC);
468   }
469 
setUpNormalSingleMonitor()470   private void setUpNormalSingleMonitor() {
471     when(mockProductionComponentMonitorFactory.create(any(Object.class)))
472         .thenReturn(mockProductionComponentMonitor);
473     when(mockProductionComponentMonitor.producerMonitorFor(nullable(ProducerToken.class)))
474         .thenReturn(mockProducerMonitor);
475   }
476 
setUpNormalMultipleMonitors()477   private void setUpNormalMultipleMonitors() {
478     when(mockProductionComponentMonitorFactoryA.create(any(Object.class)))
479         .thenReturn(mockProductionComponentMonitorA);
480     when(mockProductionComponentMonitorFactoryB.create(any(Object.class)))
481         .thenReturn(mockProductionComponentMonitorB);
482     when(mockProductionComponentMonitorFactoryC.create(any(Object.class)))
483         .thenReturn(mockProductionComponentMonitorC);
484     when(mockProductionComponentMonitorA.producerMonitorFor(nullable(ProducerToken.class)))
485         .thenReturn(mockProducerMonitorA);
486     when(mockProductionComponentMonitorB.producerMonitorFor(nullable(ProducerToken.class)))
487         .thenReturn(mockProducerMonitorB);
488     when(mockProductionComponentMonitorC.producerMonitorFor(nullable(ProducerToken.class)))
489         .thenReturn(mockProducerMonitorC);
490   }
491 }
492