Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Last active September 26, 2018 16:41
Show Gist options
  • Save lovasoa/694276ac109627066e8e29a3c2471679 to your computer and use it in GitHub Desktop.
Save lovasoa/694276ac109627066e8e29a3c2471679 to your computer and use it in GitHub Desktop.
package com.company;
import java.io.PrintWriter;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
public class MainTest {
@org.junit.Test
public void testLogNormalError() {
String stackTrace = "fake stack trace";
Throwable e = new Throwable() {
@Override
public void printStackTrace(PrintWriter s) {
s.print(stackTrace);
}
};
assertEquals(stackTrace, Main.log(e));
}
@org.junit.Test
public void testLogSqlError() {
String stackTrace = "fake stack trace";
int errorCode = 123456;
Throwable e = new SQLException() {
@Override
public int getErrorCode() {
return errorCode;
}
@Override
public void printStackTrace(PrintWriter s) {
s.print(stackTrace);
}
};
assertEquals(
"SQL exception error code: " + errorCode + stackTrace,
Main.log(e)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment