Add additional constructors for CapturedLogEvent (#26016)

As requested in PR #25907 - more constructors to cover more simple cases
This commit is contained in:
Josep Prat 2018-12-04 09:54:17 +01:00 committed by Johan Andrén
parent a8d37f5d28
commit 5ccfc12eb5
2 changed files with 29 additions and 1 deletions

View file

@ -31,6 +31,34 @@ final case class CapturedLogEvent(
this(logLevel, message, errorCause.asScala, marker.asScala, mdc.asScala.toMap)
}
/**
* Constructor for Java API
*/
def this(logLevel: LogLevel, message: String) {
this(logLevel, message, Option.empty, Option.empty, Map.empty[String, Any])
}
/**
* Constructor for Java API
*/
def this(logLevel: LogLevel, message: String, errorCause: Throwable) {
this(logLevel, message, Some(errorCause), Option.empty[LogMarker], Map.empty[String, Any])
}
/**
* Constructor for Java API
*/
def this(logLevel: LogLevel, message: String, marker: LogMarker) {
this(logLevel, message, Option.empty[Throwable], Some(marker), Map.empty[String, Any])
}
/**
* Constructor for Java API
*/
def this(logLevel: LogLevel, message: String, errorCause: Throwable, marker: LogMarker) {
this(logLevel, message, Some(errorCause), Some(marker), Map.empty[String, Any])
}
def getMdc: java.util.Map[String, Any] = mdc.asJava
def getErrorCause: Optional[Throwable] = cause.asJava

View file

@ -217,7 +217,7 @@ public class BehaviorTestKitTest extends JUnitSuite {
test.run(new Log(what));
final List<CapturedLogEvent> allLogEntries = test.getAllLogEntries();
assertEquals(1, allLogEntries.size());
assertEquals(new CapturedLogEvent(Logging.InfoLevel(), what, Optional.empty(), Optional.empty(), new HashMap<>()), allLogEntries.get(0));
assertEquals(new CapturedLogEvent(Logging.InfoLevel(), what), allLogEntries.get(0));
}
@Test