Last active
September 26, 2018 16:41
-
-
Save lovasoa/694276ac109627066e8e29a3c2471679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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