Writing automatic tests requiring external resources

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (1)

View Page History
}
{code}

h2. Clearing log records

The log traces can be cleared using the API '{{InMemoryLogHandler.clear()}}':
{code}
public static class HasInMemoryLogHandler {
@Rule
public InMemoryLogHandler inMemoryRealLogHandler = new InMemoryLogHandler();

@Test
public void testUsingInMemoryLogHandler() throws IOException {
// ...
final Logger logger = Logger.getAnonymousLogger();
logger.addHandler(this.inMemoryLogHandler.getHandler());
logger.setLevel(Level.MONIT);
// ...
final List<LogRecord> allLogRecords = this.inMemoryLogHandler.getAllRecords(Level.MONIT);
assertEquals(2, allLogRecords.size());
// ...
this.inMemoryLogHandler.clear();
assertEquals(0, this.inMemoryLogHandler.getAllRecords().size());
}
}
{code}

h2. Setting the log level of the log handler

You can set the log level of the log handler through the API '{{InMemoryLogHandler.getHandler()}}':
{code}
public static class HasInMemoryLogHandler {
@Rule
public InMemoryLogHandler inMemoryRealLogHandler = new InMemoryLogHandler();

@Test
public void testUsingInMemoryLogHandler() throws IOException {
// ...
this.inMemoryLogHandler.getHandler().setLevel(Level.FINEST);
// ...
}
}
{code}