1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.net.ssl.mock;
15
16 import java.util.LinkedList;
17 import java.util.List;
18
19 import ch.qos.logback.core.spi.ContextAware;
20 import ch.qos.logback.core.spi.ContextAwareBase;
21
22
23
24
25
26
27 public class MockContextAware extends ContextAwareBase implements ContextAware {
28
29 private final List<String> info = new LinkedList<String>();
30 private final List<String> warn = new LinkedList<String>();
31 private final List<String> error = new LinkedList<String>();
32
33 @Override
34 public void addInfo(String msg) {
35 info.add(msg);
36 }
37
38 @Override
39 public void addWarn(String msg) {
40 warn.add(msg);
41 }
42
43 @Override
44 public void addError(String msg) {
45 error.add(msg);
46 }
47
48 public boolean hasInfoMatching(String regex) {
49 return hasMatching(info, regex);
50 }
51
52 public boolean hasWarnMatching(String regex) {
53 return hasMatching(info, regex);
54 }
55
56 public boolean hasErrorMatching(String regex) {
57 return hasMatching(info, regex);
58 }
59
60 private boolean hasMatching(List<String> messages, String regex) {
61 for (String message : messages) {
62 if (message.matches(regex))
63 return true;
64 }
65 return false;
66 }
67
68 }