test: LoggerFormatter
This commit is contained in:
84
src/test/java/ghast/logger/LoggerFormatterTest.java
Normal file
84
src/test/java/ghast/logger/LoggerFormatterTest.java
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user