mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 21:20:45 +00:00
Add warnAndThrow and errorAndThrow methods, to slightly simplify catch-blocks that want to do both of those things; also add variant data in session portion of log, when available
This commit is contained in:
@ -43,6 +43,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -67,6 +68,50 @@ class QLoggerTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testLogAndThrowMethods() throws QException
|
||||
{
|
||||
try
|
||||
{
|
||||
LOG.info("Some info");
|
||||
LOG.warnAndThrow(new QException("Something failed"), new LogPair("something", 1));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//////////////
|
||||
// ok, done //
|
||||
//////////////
|
||||
}
|
||||
|
||||
assertThatThrownBy(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
methodThatThrows();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw LOG.errorAndThrow(new QException("I caught, now i errorAndThrow", e), new LogPair("iLove", "logPairs"));
|
||||
}
|
||||
}
|
||||
).isInstanceOf(QException.class).hasMessageContaining("I caught").rootCause().hasMessageContaining("See, I throw");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void methodThatThrows() throws QException
|
||||
{
|
||||
throw (new QException("See, I throw"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user