View Javadoc
1   /*
2    * Copyright (C) 2016 Ronald Jack Jenkins Jr.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package util;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.codehaus.plexus.logging.Logger;
22  
23  import edu.emory.mathcs.backport.java.util.Collections;
24  
25  public final class TestLogger implements Logger {
26    public static final class Entry {
27      private final String    message;
28      private final Throwable throwable;
29  
30      private Entry(final String message, final Throwable throwable) {
31        this.message = message;
32        this.throwable = throwable;
33      }
34  
35      public String getMessage() {
36        return this.message;
37      }
38  
39      public Throwable getThrowable() {
40        return this.throwable;
41      }
42    }
43  
44    private final List<Entry> debugLog = new ArrayList<Entry>();
45    private final List<Entry> infoLog  = new ArrayList<Entry>();
46    private final List<Entry> warnLog  = new ArrayList<Entry>();
47    private final List<Entry> errorLog = new ArrayList<Entry>();
48    private final List<Entry> fatalLog = new ArrayList<Entry>();
49  
50    @Override
51    public void debug(final String arg0) {
52      this.debugLog.add(new Entry(arg0, null));
53    }
54  
55    @Override
56    public void debug(final String arg0, final Throwable arg1) {
57      this.debugLog.add(new Entry(arg0, arg1));
58    }
59  
60    @Override
61    public void error(final String arg0) {
62      this.errorLog.add(new Entry(arg0, null));
63    }
64  
65    @Override
66    public void error(final String arg0, final Throwable arg1) {
67      this.errorLog.add(new Entry(arg0, arg1));
68    }
69  
70    @Override
71    public void fatalError(final String arg0) {
72      this.fatalLog.add(new Entry(arg0, null));
73    }
74  
75    @Override
76    public void fatalError(final String arg0, final Throwable arg1) {
77      this.fatalLog.add(new Entry(arg0, arg1));
78    }
79  
80    @Override
81    public Logger getChildLogger(final String arg0) {
82      return null;
83    }
84  
85    @SuppressWarnings("unchecked")
86    public List<Entry> getDebugLog() {
87      return Collections.unmodifiableList(this.debugLog);
88    }
89  
90    @SuppressWarnings("unchecked")
91    public List<Entry> getErrorLog() {
92      return Collections.unmodifiableList(this.errorLog);
93    }
94  
95    @SuppressWarnings("unchecked")
96    public List<Entry> getFatalLog() {
97      return Collections.unmodifiableList(this.fatalLog);
98    }
99  
100   @SuppressWarnings("unchecked")
101   public List<Entry> getInfoLog() {
102     return Collections.unmodifiableList(this.infoLog);
103   }
104 
105   @Override
106   public String getName() {
107     return "TestLogger";
108   }
109 
110   @Override
111   public int getThreshold() {
112     return Logger.LEVEL_DEBUG;
113   }
114 
115   @SuppressWarnings("unchecked")
116   public List<Entry> getWarnLog() {
117     return Collections.unmodifiableList(this.warnLog);
118   }
119 
120   @Override
121   public void info(final String arg0) {
122     this.infoLog.add(new Entry(arg0, null));
123   }
124 
125   @Override
126   public void info(final String arg0, final Throwable arg1) {
127     this.infoLog.add(new Entry(arg0, arg1));
128   }
129 
130   @Override
131   public boolean isDebugEnabled() {
132     return true;
133   }
134 
135   @Override
136   public boolean isErrorEnabled() {
137     return true;
138   }
139 
140   @Override
141   public boolean isFatalErrorEnabled() {
142     return true;
143   }
144 
145   @Override
146   public boolean isInfoEnabled() {
147     return true;
148   }
149 
150   @Override
151   public boolean isWarnEnabled() {
152     return true;
153   }
154 
155   @Override
156   public void setThreshold(final int arg0) {
157     // do nothing
158   }
159 
160   @Override
161   public void warn(final String arg0) {
162     this.warnLog.add(new Entry(arg0, null));
163   }
164 
165   @Override
166   public void warn(final String arg0, final Throwable arg1) {
167     this.warnLog.add(new Entry(arg0, arg1));
168   }
169 }