lambda example (#2480)

This commit is contained in:
lor6 2017-08-22 00:03:12 +03:00 committed by Grzegorz Piwowarek
parent 802c0b09e0
commit 822e8682b6
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package com.baeldung.logging.log4j2.tests;
import java.util.Random;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
public class LambdaExpressionsIntegrationTest {
private static final Logger logger = LogManager.getRootLogger();
@Test
public void whenCheckLogMessage_thenOk() {
if (logger.isTraceEnabled()) {
logger.trace("Numer is {}", getRandomNumber());
}
}
@Test
public void whenUseLambdaExpression_thenOk() {
logger.trace("Number is {}", () -> getRandomNumber());
logger.trace("Name is {} and age is {}", () -> getName(), () -> getRandomNumber());
}
private int getRandomNumber() {
return (new Random()).nextInt(10);
}
private String getName() {
return "John";
}
}