1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.net.server.test;
15
16 import java.io.IOException;
17
18 import ch.qos.logback.core.Context;
19 import ch.qos.logback.core.net.server.Client;
20 import ch.qos.logback.core.net.server.ClientVisitor;
21 import ch.qos.logback.core.net.server.ServerRunner;
22 import ch.qos.logback.core.spi.ContextAwareBase;
23
24
25
26
27
28
29 public class MockServerRunner<T extends Client> extends ContextAwareBase implements ServerRunner<T> {
30
31 private IOException stopException;
32 private int startCount;
33 private boolean contextInjected;
34
35 @Override
36 public void setContext(Context context) {
37 contextInjected = true;
38 super.setContext(context);
39 }
40
41 public void run() {
42 startCount++;
43 }
44
45 public void stop() throws IOException {
46 if (stopException != null) {
47 throw stopException;
48 }
49 startCount--;
50 }
51
52 public boolean isRunning() {
53 return startCount > 0;
54 }
55
56 @SuppressWarnings("rawtypes")
57 public void accept(ClientVisitor visitor) {
58 throw new UnsupportedOperationException();
59 }
60
61 public int getStartCount() {
62 return startCount;
63 }
64
65 public boolean isContextInjected() {
66 return contextInjected;
67 }
68
69 public void setStopException(IOException stopException) {
70 this.stopException = stopException;
71 }
72
73 }