1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc.metric;
import com.yahoo.jdisc.Metric;
import com.yahoo.jdisc.application.MetricConsumer;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
*/
public class ForwardingMetricConsumerTest {
@Test
public void requireThatAllMethodsAreForwarded() {
MetricConsumer fooConsumer = Mockito.mock(MetricConsumer.class);
Metric.Context fooCtx = Mockito.mock(Metric.Context.class);
Mockito.when(fooConsumer.createContext(Mockito.<Map<String, ?>>any())).thenReturn(fooCtx);
MetricConsumer barConsumer = Mockito.mock(MetricConsumer.class);
Metric.Context barCtx = Mockito.mock(Metric.Context.class);
Mockito.when(barConsumer.createContext(Mockito.<Map<String, ?>>any())).thenReturn(barCtx);
MetricConsumer fwdConsumer = new ForwardingMetricConsumer(new MetricConsumer[] { fooConsumer, barConsumer });
Map<String, ?> properties = new HashMap<>();
Metric.Context ctx = fwdConsumer.createContext(properties);
assertNotNull(ctx);
Mockito.verify(fooConsumer, Mockito.times(1)).createContext(properties);
Mockito.verify(barConsumer, Mockito.times(1)).createContext(properties);
fwdConsumer.add("a", 69, ctx);
Mockito.verify(fooConsumer, Mockito.times(1)).add("a", 69, fooCtx);
Mockito.verify(barConsumer, Mockito.times(1)).add("a", 69, barCtx);
fwdConsumer.set("b", 96, ctx);
Mockito.verify(fooConsumer, Mockito.times(1)).set("b", 96, fooCtx);
Mockito.verify(barConsumer, Mockito.times(1)).set("b", 96, barCtx);
}
}
|