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:
2024-05-10 12:42:07 -05:00
parent 196488ad6e
commit c9e9d62098
2 changed files with 104 additions and 1 deletions

View File

@ -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"));
}
/*******************************************************************************
**
*******************************************************************************/