-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
270 additions
and
136 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
*.iml | ||
.idea |
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
package slf4jtest; | ||
|
||
class LogMessage { | ||
final String logName; | ||
final LogLevel level; | ||
final String message; | ||
final String text; | ||
final long timeStamp = System.currentTimeMillis(); | ||
final String threadName = Thread.currentThread().getName(); | ||
|
||
public LogMessage(LogLevel level, String message) { | ||
public LogMessage(String logName, LogLevel level, String formattedMessage) { | ||
this.logName = logName; | ||
this.level = level; | ||
this.message = message; | ||
this.text = formattedMessage; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LogMessage(" + level + "," + message + ")"; | ||
return "LogMessage(" + logName + "," + level + "," + text + ")"; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,43 +1,34 @@ | ||
package slf4jtest; | ||
|
||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.slf4j.ILoggerFactory; | ||
import org.slf4j.Logger; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class BasicExampleUnitTest { | ||
class BasicExample { | ||
|
||
@Test | ||
public void testAMethodThatLogs() throws Exception { | ||
TestLoggerFactory loggerFactory = new TestLoggerFactory(); | ||
|
||
BasicExample sut = new BasicExample(loggerFactory); | ||
sut.aMethodThatLogs(); | ||
private final Logger logger; | ||
|
||
TestLogger logger = loggerFactory.getLogger(BasicExample.class.getName()); | ||
assertTrue(logger.contains(".*Hello.*")); | ||
public BasicExample(ILoggerFactory lf) { | ||
this.logger = lf.getLogger(BasicExample.class.getName()); | ||
} | ||
|
||
@Test | ||
public void testAMethodThatLogsWithAMock() throws Exception { | ||
Logger mockLogger = Mockito.mock(Logger.class); | ||
|
||
Settings cfg = new Settings().delegate(BasicExample.class.getName(), mockLogger); | ||
TestLoggerFactory loggerFactory = new TestLoggerFactory(cfg); | ||
|
||
BasicExample sut = new BasicExample(loggerFactory); | ||
sut.aMethodThatLogs(); | ||
|
||
Mockito.verify(mockLogger).info("Hello World!"); | ||
public void doLogging() { | ||
logger.info("Hello World!"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAMethodThatSuppresses() throws Exception { | ||
public class BasicExampleUnitTest { | ||
|
||
Settings cfg = new Settings().suppressPrinting(".*Pattern to suppress.*"); | ||
TestLoggerFactory loggerFactory = new TestLoggerFactory(cfg); | ||
@Test | ||
public void testBasicDemo() throws Exception { | ||
TestLoggerFactory loggerFactory = new TestLoggerFactory(); | ||
|
||
BasicExample sut = new BasicExample(loggerFactory); | ||
sut.doLogging(); | ||
|
||
TestLogger logger = loggerFactory.getLogger(BasicExample.class); | ||
assertTrue(logger.contains(".*Hello.*")); | ||
} | ||
} |
Oops, something went wrong.