View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.internal.testmodules;
21  
22  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
23  import com.puppycrawl.tools.checkstyle.api.AuditListener;
24  
25  public final class DebugAuditAdapter implements AuditListener {
26  
27      /** Keeps track whether this {@code AuditListener} was called. */
28      private boolean called;
29  
30      /** Keeps track whether this {@code AuditListener} was given {@code AuditEvent}. */
31      private boolean passedEvent;
32  
33      /** Keeps track of the number of files started. */
34      private int numFilesStarted;
35  
36      /** Keeps track of the number of files finished. */
37      private int numFilesFinished;
38  
39      public int getNumFilesStarted() {
40          return numFilesStarted;
41      }
42  
43      public int getNumFilesFinished() {
44          return numFilesFinished;
45      }
46  
47      public boolean wasCalled() {
48          return called;
49      }
50  
51      public boolean wasEventPassed() {
52          return passedEvent;
53      }
54  
55      public void resetListener() {
56          called = false;
57          passedEvent = false;
58      }
59  
60      @Override
61      public void addError(AuditEvent event) {
62          called = true;
63          if (event != null) {
64              passedEvent = true;
65          }
66      }
67  
68      @Override
69      public void addException(AuditEvent event, Throwable throwable) {
70          called = true;
71          if (event != null) {
72              passedEvent = true;
73          }
74      }
75  
76      @Override
77      public void auditStarted(AuditEvent event) {
78          called = true;
79          if (event != null) {
80              passedEvent = true;
81          }
82      }
83  
84      @Override
85      public void fileStarted(AuditEvent event) {
86          called = true;
87          numFilesStarted++;
88          if (event != null) {
89              passedEvent = true;
90          }
91      }
92  
93      @Override
94      public void auditFinished(AuditEvent event) {
95          called = true;
96          if (event != null) {
97              passedEvent = true;
98          }
99      }
100 
101     @Override
102     public void fileFinished(AuditEvent event) {
103         called = true;
104         numFilesFinished++;
105         if (event != null) {
106             passedEvent = true;
107         }
108     }
109 
110 }