Skip to content

Commit

Permalink
Add more unit tests, simplify logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed Jul 12, 2015
1 parent b51b5b1 commit b37e8c6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<aggregate>true</aggregate>
<instrumentation>
Expand All @@ -108,6 +107,10 @@
<exclude>**/Superlnk*.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
<plugin>
Expand Down
26 changes: 5 additions & 21 deletions src/main/java/com/github/superav/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.logging.*;

public class Log {
public final class Log {
private enum MessageType { DEBUG, INFO, WARN, ERROR };

private static class LogFormatter extends Formatter {
Expand All @@ -34,14 +34,6 @@ public String format(LogRecord record) {
builder.append("\n");
return builder.toString();
}

public String getHead(Handler handler) {
return super.getHead(handler);
}

public String getTail(Handler handler) {
return super.getTail(handler);
}
}
public static void debug(String param) {
log(MessageType.DEBUG, param);
Expand Down Expand Up @@ -77,19 +69,18 @@ private static void log(MessageType messageType, String localParam) {
handler.setFormatter(new LogFormatter());
logger.addHandler(handler);
}
String param = modifyString(localParam);
switch (messageType) {
case DEBUG:
logger.logp(Level.CONFIG, aClassName, "", param);
logger.logp(Level.CONFIG, aClassName, "", localParam);
break;
case INFO:
logger.logp(Level.INFO, aClassName, "", param);
logger.logp(Level.INFO, aClassName, "", localParam);
break;
case WARN:
logger.logp(Level.WARNING, aClassName, "", param);
logger.logp(Level.WARNING, aClassName, "", localParam);
break;
default:
logger.logp(Level.SEVERE, aClassName, "", param);
logger.logp(Level.SEVERE, aClassName, "", localParam);
break;
}
}
Expand Down Expand Up @@ -119,13 +110,6 @@ private static String problem2String(String aMsg, Throwable aProblem) {
return sb.toString();
}

private static String modifyString(String param) {
if (null == param && "".equals(param)) {
return "";
}
return param;
}

private static void makeGoodTrace(StringBuilder sb, StackTraceElement[] trace) {
for (StackTraceElement entry : trace) {
if (entry.getClassName().startsWith("com.github")) {
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/com/github/superav/LogTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* $Id$
*
* Copyright 2015 Valentyn Kolesnikov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.superav;

import org.junit.Assert;
import org.junit.Test;

public class LogTest {

@Test
public void debug() throws Exception {
Log.debug("");
}

@Test
public void info() throws Exception {
Log.info("");
}

@Test
public void warn() throws Exception {
Log.warn("");
Log.warn(new Exception(""), "");
}

@Test
public void error() throws Exception {
Log.error("");
Log.error(new Exception(""), "");
Log.error(new Exception("", new Exception("")), "");
Log.error(new Exception(""), null);
Log.error(null);
Log.error(new Exception((String) null), null);
}
}
3 changes: 2 additions & 1 deletion src/test/java/com/github/superav/SuperavTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SuperavTest {
@Test
public void main() throws Exception {
Superav.main(new String[] {});
Superav.main(new String[] {".", "--r"});
Superav.main(new String[] {".", "--r", "/*", "/?"});
Superav.main(new String[] {"./src/main/java/com/github", "--*"});
}
}
Binary file modified superav.jar
Binary file not shown.

0 comments on commit b37e8c6

Please sign in to comment.