Skip to content

Commit

Permalink
Add eventMap() method to InMemoryAppender (#445)
Browse files Browse the repository at this point in the history
* This method is copied from kiwi-beta, which has its own
  InMemoryAppender class. Eventually, this class can be made
  public and supersede that one.
* Change from collect(toList()) in orderedEvents and
  orderedEventMessages to toList() as the terminal method.
  The returned lists should not be modifiable.
  • Loading branch information
sleberknight authored Dec 17, 2023
1 parent f8191bc commit bea2674
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/test/java/org/kiwiproject/test/logback/InMemoryAppender.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.kiwiproject.test.logback;

import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import lombok.Synchronized;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -62,13 +62,25 @@ public void clearEvents() {
eventMap.clear();
}

/**
* Return a copy of the internal event map.
* <p>
* The keys are the message order starting at one, and the values are the corresponding logging events.
*
* @return an unmodifiable copy of the event map
*/
@SuppressWarnings("unused")
public Map<Integer, ILoggingEvent> eventMap() {
return Map.copyOf(eventMap);
}

/**
* Retrieves a list of logging events ordered by ascending timestamp.
*
* @return the ordered list of logging events
*/
public List<ILoggingEvent> orderedEvents() {
return orderedEventStream().collect(toList());
return orderedEventStream().toList();
}

/**
Expand All @@ -80,7 +92,7 @@ public List<ILoggingEvent> orderedEvents() {
public List<String> orderedEventMessages() {
return orderedEventStream()
.map(ILoggingEvent::getFormattedMessage)
.collect(toList());
.toList();
}

/**
Expand Down

0 comments on commit bea2674

Please sign in to comment.