0

test: LoggerFormatter

This commit is contained in:
2021-10-07 14:52:29 +03:00
parent 41fe798757
commit 2e7f95b323
2 changed files with 84 additions and 4 deletions

View File

@@ -0,0 +1,84 @@
package ghast.logger;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class LoggerFormatterTest {
@Test
void arrayFormatNullPattern() {
Exception exception = new Exception("oops!");
FormattingPair formattingPair = LoggerFormatter.arrayFormat(null, null, exception);
assertNotNull(formattingPair);
assertNull(formattingPair.getMessage());
assertNotNull(formattingPair.getThrowable());
assertEquals(exception, formattingPair.getThrowable());
formattingPair = LoggerFormatter.arrayFormat(null, null, null);
assertNotNull(formattingPair);
assertNull(formattingPair.getMessage());
assertNull(formattingPair.getThrowable());
}
@Test
void arrayFormatNullArgs() {
FormattingPair formattingPair = LoggerFormatter.arrayFormat("some pattern", null, null);
assertNotNull(formattingPair);
assertNotNull(formattingPair.getMessage());
assertEquals("some pattern", formattingPair.getMessage());
assertNull(formattingPair.getThrowable());
formattingPair = LoggerFormatter.arrayFormat("some pattern {}", null, null);
assertNotNull(formattingPair);
assertNotNull(formattingPair.getMessage());
assertEquals("some pattern {}", formattingPair.getMessage());
assertNull(formattingPair.getThrowable());
}
@Test
void arrayFormat() {
Exception exception = new Exception("oops!");
FormattingPair formattingPair = LoggerFormatter.arrayFormat("some pattern {}", new Object[]{"item-1"}, exception);
assertNotNull(formattingPair);
assertNotNull(formattingPair.getMessage());
assertEquals("some pattern item-1", formattingPair.getMessage());
assertNotNull(formattingPair.getThrowable());
assertEquals(exception, formattingPair.getThrowable());
}
@Test
void arrayFormatWithoutThrowable() {
FormattingPair formattingPair = LoggerFormatter.arrayFormat("Arg1: {}", new Object[]{ "item-1" });
assertNotNull(formattingPair);
assertNotNull(formattingPair.getMessage());
assertEquals("Arg1: item-1", formattingPair.getMessage());
assertNull(formattingPair.getThrowable());
}
@Test
void arrayFormatWithoutThrowableNullArgs() {
FormattingPair formattingPair = LoggerFormatter.arrayFormat("Arg1: {}", null);
assertNotNull(formattingPair);
assertNotNull(formattingPair.getMessage());
assertEquals("Arg1: {}", formattingPair.getMessage());
assertNull(formattingPair.getThrowable());
}
@Test
void arrayFormatThrowableInArgs() {
Exception exception = new Exception("oops!");
FormattingPair formattingPair = LoggerFormatter.arrayFormat("Arg1: {}", new Object[]{ "item-1", exception });
assertNotNull(formattingPair);
assertNotNull(formattingPair.getMessage());
assertEquals("Arg1: item-1", formattingPair.getMessage());
assertNotNull(formattingPair.getThrowable());
assertEquals(exception, formattingPair.getThrowable());
}
}