View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.checkstyle;
6   
7   import com.puppycrawl.tools.checkstyle.api.AuditEvent;
8   import com.puppycrawl.tools.checkstyle.api.AuditListener;
9   
10  /**
11   * Fake Audit Listener that records every {@code addError} event into a
12   * collaborating {@link AuditCollector}.
13   *
14   * <p>All other lifecycle hooks (audit started/finished, file
15   * started/finished, exceptions) are intentionally no-ops because the
16   * tests only care about the violations emitted by the Checkstyle
17   * {@code Checker} run.</p>
18   *
19   * @since 0.27.0
20   */
21  final class FakeAuditListener implements AuditListener {
22  
23      /**
24       * Mocked collector.
25       */
26      private final AuditCollector collector;
27  
28      FakeAuditListener(final AuditCollector collect) {
29          this.collector = collect;
30      }
31  
32      @Override
33      public void auditStarted(final AuditEvent event) {
34          // intentionally empty: tests only assert on individual errors
35      }
36  
37      @Override
38      public void auditFinished(final AuditEvent event) {
39          // intentionally empty: tests only assert on individual errors
40      }
41  
42      @Override
43      public void fileStarted(final AuditEvent event) {
44          // intentionally empty: tests only assert on individual errors
45      }
46  
47      @Override
48      public void fileFinished(final AuditEvent event) {
49          // intentionally empty: tests only assert on individual errors
50      }
51  
52      @Override
53      public void addError(final AuditEvent event) {
54          this.collector.add(event);
55      }
56  
57      @Override
58      public void addException(
59          final AuditEvent event,
60          final Throwable throwable
61      ) {
62          // intentionally empty: tests only assert on individual errors
63      }
64  }