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 package org.perfidix.socketadapter;
28
29
30 import static org.junit.Assert.assertTrue;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33
34 import java.lang.reflect.Method;
35
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.perfidix.element.BenchmarkMethod;
39 import org.perfidix.exceptions.SocketViewException;
40 import org.perfidix.meter.AbstractMeter;
41 import org.perfidix.meter.Time;
42 import org.perfidix.meter.TimeMeter;
43
44
45
46
47
48
49
50 public class SocketListenerTest {
51
52 private transient SocketListener socketListener;
53
54 private IUpdater updater;
55
56
57
58
59
60
61 @Before
62 public void setUp() throws Exception {
63 updater = mock(IUpdater.class);
64 socketListener = new SocketListener(updater);
65 }
66
67
68
69
70
71 @Test(expected = UnsupportedOperationException.class)
72 public void testVisitBenchmark() {
73 socketListener = new SocketListener(updater);
74 socketListener.visitBenchmark(null);
75 }
76
77
78
79
80
81
82
83
84
85
86 @Test
87 public void testListenToResultSet() throws InterruptedException, SocketViewException {
88 final Method[] methods = BenchWithException.class.getMethods();
89 BenchmarkMethod method1 = null;
90 for (Method method : methods) {
91 if (method.getName().equals("benchMe")) {
92 method1 = new BenchmarkMethod(method);
93 }
94 }
95 final AbstractMeter meter = new TimeMeter(Time.MilliSeconds);
96 final String methodName =
97 method1.getMethodToBench().getDeclaringClass().getName() + "."
98 + method1.getMethodToBench().getName();
99
100 when(updater.updateCurrentElement(meter, methodName)).thenReturn(true);
101
102 SocketListener myInstance = new SocketListener(updater);
103 assertTrue(myInstance.listenToResultSet(method1.getMethodToBench(), meter, 0));
104 }
105
106
107
108
109
110
111
112
113
114 @Test
115 public void testListenToException() throws InterruptedException, SocketViewException {
116 final Method[] methods = BenchWithException.class.getMethods();
117 BenchmarkMethod method1 = null;
118 for (Method method : methods) {
119 if (method.getName().equals("benchMe")) {
120 method1 = new BenchmarkMethod(method);
121 }
122 }
123 final AbstractMeter meter = new TimeMeter(Time.MilliSeconds);
124 final String methodName =
125 method1.getMethodToBench().getDeclaringClass().getName() + "."
126 + method1.getMethodToBench().getName();
127
128 when(updater.updateCurrentElement(meter, methodName)).thenReturn(true);
129
130 SocketListener myInstance = new SocketListener(updater);
131 assertTrue(myInstance.listenToResultSet(method1.getMethodToBench(), meter, 0));
132
133 }
134 }