| 5 | import java.util.function.Predicate; |
| 6 | |
| 7 | class TestLogger implements Logger { |
| 8 | final List<List<LogEntry>> events = new ArrayList<>(); |
| 9 | |
| 10 | synchronized boolean hasEventLog(String value) { |
| 11 | return hasLog(ents -> ents.stream().anyMatch(e -> e.key().equals("event") && e.value().equals(value))); |
| 12 | } |
| 13 | |
| 14 | synchronized long countEventLogs(String value) { |
| 15 | return countLogs(ents -> ents.stream().anyMatch(e -> e.key().equals("event") && e.value().equals(value))); |
| 16 | } |
| 17 | |
| 18 | synchronized boolean hasLog(Predicate<List<LogEntry>> predicate) { |
| 19 | return events.stream().anyMatch(predicate); |
| 20 | } |
| 21 | |
| 22 | synchronized long countLogs(Predicate<List<LogEntry>> predicate) { |
| 23 | return events.stream().filter(predicate).count(); |
| 24 | } |
| 25 | |
| 26 | synchronized void clear() { |
| 27 | events.clear(); |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public synchronized boolean enabled() { |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public synchronized void log(LogEntry... entries) { |
| 37 | events.add(List.of(entries)); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public synchronized void log(Exception e, LogEntry... entries) { |
| 42 | log(entries); |
| 43 | } |
| 44 | } |
nothing calls this directly
no outgoing calls
no test coverage detected