0
This repository has been archived on 2022-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
Files
ghast-tools/src/test/java/ghast/logger/LoggerFormatterTest.java
2021-10-07 14:52:29 +03:00

84 lines
3.1 KiB
Java

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());
}
}