-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Identify invalid IBDO data/array modifications.
- Loading branch information
James Cover jdcove2
committed
Aug 17, 2023
1 parent
4bae59a
commit 170619a
Showing
5 changed files
with
201 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/emissary/test/core/junit5/LogbackTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package emissary.test.core.junit5; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import org.apache.commons.lang3.Validate; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class LogbackTester implements Closeable { | ||
public final String name; | ||
public final Logger logger; | ||
public final ListAppender<ILoggingEvent> appender; | ||
|
||
public LogbackTester(final String name) { | ||
Validate.notNull(name, "Required: name != null"); | ||
|
||
this.name = name; | ||
logger = (Logger) LoggerFactory.getLogger(name); | ||
appender = new ListAppender<>(); | ||
|
||
appender.setContext(logger.getLoggerContext()); | ||
appender.start(); | ||
logger.addAppender(appender); | ||
logger.setAdditive(false); | ||
} | ||
|
||
public void checkLogList(final Level[] levels, final String[] messages, final boolean[] throwables) { | ||
Validate.notNull(levels, "Required: levels != null"); | ||
Validate.notNull(messages, "Required: messages != null"); | ||
Validate.notNull(throwables, "Required: throwables != null"); | ||
Validate.isTrue(levels.length == messages.length, "Required: levels.length == messages.length"); | ||
Validate.isTrue(levels.length == throwables.length, "Required: levels.length == throwables.length"); | ||
|
||
assertEquals(levels.length, appender.list.size(), "Expected lengths do not match number of log messages"); | ||
|
||
for (int i = 0; i < appender.list.size(); i++) { | ||
final ILoggingEvent item = appender.list.get(i); | ||
|
||
assertEquals(levels[i], item.getLevel(), "Levels not equal for element " + i); | ||
assertEquals(messages[i], item.getFormattedMessage(), "Messages not equal for element " + i); | ||
assertEquals(throwables[i], item.getThrowableProxy() != null, "Throwables not equal for elmeent " + i); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
logger.detachAndStopAllAppenders(); | ||
} | ||
} |