-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implementation * Fix javadoc * Update README * Update README * Update README * Add the integration test * Update README * Update README * Update README * Add the package-info, TOC to README * Impove integration tests for commons-logging, jdk-platform-logging and slf4j * Add an integration test
- Loading branch information
Showing
27 changed files
with
959 additions
and
39 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
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 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,125 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<artifactId>mock-loggers-elf4j</artifactId> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<groupId>org.jacoco</groupId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>mock.loggers.elf4j</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<artifactId>annotations</artifactId> | ||
<groupId>org.jetbrains</groupId> | ||
</dependency> | ||
<dependency> | ||
<artifactId>elf4j</artifactId> | ||
<groupId>io.github.elf4j</groupId> | ||
<version>${elf4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>hamcrest</artifactId> | ||
<groupId>org.hamcrest</groupId> | ||
</dependency> | ||
<dependency> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<groupId>org.junit.jupiter</groupId> | ||
</dependency> | ||
<dependency> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<groupId>org.junit.jupiter</groupId> | ||
</dependency> | ||
<dependency> | ||
<artifactId>mock-loggers-core</artifactId> | ||
<groupId>io.github.vitalijr2.logging</groupId> | ||
<version>1.2.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>mockito-core</artifactId> | ||
<groupId>org.mockito</groupId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<groupId>org.mockito</groupId> | ||
</dependency> | ||
</dependencies> | ||
<description>Mock loggers for Easy Logging Facade for Java backed by Mockito.</description> | ||
<modelVersion>4.0.0</modelVersion> | ||
<name>Mock loggers for elf4j</name> | ||
<parent> | ||
<artifactId>mock-loggers</artifactId> | ||
<groupId>io.github.vitalijr2.logging</groupId> | ||
<version>1.2.0-SNAPSHOT</version> | ||
</parent> | ||
<profiles> | ||
<profile> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<configuration> | ||
<skipCheckLicense>false</skipCheckLicense> | ||
</configuration> | ||
<groupId>org.codehaus.mojo</groupId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<id>prepare-and-check</id> | ||
</profile> | ||
<profile> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<configuration> | ||
<links> | ||
<link>https://javadoc.io/doc/io.github.elf4j/elf4j/${elf4j.version}</link> | ||
</links> | ||
</configuration> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<id>release</id> | ||
</profile> | ||
<profile> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-invoker-plugin</artifactId> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<id>run-its</id> | ||
</profile> | ||
</profiles> | ||
<properties> | ||
<elf4j.version>4.1.0</elf4j.version> | ||
</properties> | ||
<version>1.2.0-SNAPSHOT</version> | ||
</project> |
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,184 @@ | ||
# Mock loggers for elf4j | ||
|
||
[elf4j][] provider with mock loggers backed by [Mockito][]. | ||
|
||
> [!WARNING] | ||
> This library does not support _parallel test execution_. | ||
[![Java Version][java-version]][jdk-download] | ||
![elf4j Version][elf4j-version] | ||
![Mockito Version][mockito-version] | ||
![Maven Central Last Update][maven-central-last-update] | ||
[![Maven Central][maven-central]][maven-central-link] | ||
[![Javadoc][javadoc]][javadoc-link] | ||
|
||
## Table of Contents | ||
|
||
<!--ts--> | ||
* [How to use](#how-to-use) | ||
|
||
<!-- Created by https://github.com/ekalinin/github-markdown-toc --> | ||
<!-- Added by: r2, at: Fri Feb 21 08:39:41 AM EET 2025 --> | ||
|
||
<!--te--> | ||
|
||
## How to use | ||
|
||
Just put a test dependency to your POM: | ||
|
||
```xml | ||
<dependency> | ||
<artifactId>mock-loggers-elf4j</artifactId> | ||
<groupId>io.github.vitalijr2.logging</groupId> | ||
<scope>test</scope> | ||
<version>1.1.1</version> | ||
</dependency> | ||
``` | ||
|
||
The simplest usage example looks like this: | ||
|
||
```java | ||
@Test | ||
void helloWorld() { | ||
var helloService = new HelloService(); | ||
|
||
assertDoesNotThrow(helloService::sayHelloWorld); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello World!"); | ||
} | ||
``` | ||
|
||
See more details at [HelloServiceBasicTest.java](src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceBasicTest.java) | ||
|
||
> [!IMPORTANT] | ||
> Keep in mind that all loggers are initialized only once during the test run. | ||
Therefore, a more complex example cleans the loggers after (or before) | ||
each test: | ||
|
||
```java | ||
// the static logger instance | ||
private static Logger logger; | ||
|
||
// initialize the mock logger once | ||
@BeforeAll | ||
static void setUpClass() { | ||
logger = Logger.instance(); | ||
} | ||
|
||
// clean the mock logger after each test | ||
@AfterEach | ||
void tearDown() { | ||
clearInvocations(logger); | ||
} | ||
|
||
// use the mock logger in a test | ||
@DisplayName("Names") | ||
@ParameterizedTest(name = "<{0}>") | ||
@ValueSource(strings = {"John", "Jane"}) | ||
void names(String name) { | ||
var helloService = new HelloService(); | ||
|
||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
|
||
assertDoesNotThrow(() -> helloService.sayHello(name)); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello " + name + "!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
``` | ||
|
||
See more details at [HelloServiceFullTest.java](src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceFullTest.java) | ||
|
||
To avoid manual cleaning of mock loggers you can use | ||
the [jUnit extension][junit-extension] for automation: | ||
|
||
```java | ||
@ExtendWith(MockLoggerExtension.class) | ||
class HelloServiceExtensionTest { | ||
|
||
private static Logger logger; | ||
|
||
@BeforeAll | ||
static void setUpClass() { | ||
logger = Logger.instance(); | ||
} | ||
|
||
@DisplayName("Names") | ||
@ParameterizedTest(name = "<{0}>") | ||
@ValueSource(strings = {"John", "Jane"}) | ||
void names(String name) { | ||
var helloService = new HelloService(); | ||
|
||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
|
||
assertDoesNotThrow(() -> helloService.sayHello(name)); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello " + name + "!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
|
||
} | ||
``` | ||
|
||
See more details at [HelloServiceExtensionTest.java](src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceExtensionTest.java) | ||
|
||
Also you can use the annotation for automation: | ||
|
||
```java | ||
@MockLoggers | ||
class HelloServiceAnnotationTest { | ||
|
||
private static Logger logger; | ||
|
||
@BeforeAll | ||
static void setUpClass() { | ||
logger = Logger.instance(); | ||
} | ||
|
||
@DisplayName("Names") | ||
@ParameterizedTest(name = "<{0}>") | ||
@ValueSource(strings = {"John", "Jane"}) | ||
void names(String name) { | ||
var helloService = new HelloService(); | ||
|
||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
|
||
assertDoesNotThrow(() -> helloService.sayHello(name)); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello " + name + "!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
|
||
} | ||
``` | ||
|
||
See more details at [HelloServiceAnnotationTest.java](src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceAnnotationTest.java) | ||
|
||
[elf4j]: https://github.com/elf4j/elf4j | ||
|
||
[Mockito]: https://site.mockito.org | ||
|
||
[java-version]: https://img.shields.io/static/v1?label=Java&message=11&color=blue&logoColor=E23D28 | ||
|
||
[jdk-download]: https://www.oracle.com/java/technologies/downloads/#java11 | ||
|
||
[elf4j-version]: https://img.shields.io/static/v1?label=elf4j&message=4.1.0&color=blue&logoColor=E23D28 | ||
|
||
[mockito-version]: https://img.shields.io/static/v1?label=Mockito&message=5.15.2&color=blue&logoColor=E23D28 | ||
|
||
[maven-central-last-update]: https://img.shields.io/maven-central/last-update/io.github.vitalijr2.logging/mock-loggers-elf4j | ||
|
||
[maven-central]: https://img.shields.io/maven-central/v/io.github.vitalijr2.logging/mock-loggers-elf4j | ||
|
||
[maven-central-link]: https://central.sonatype.com/artifact/io.github.vitalijr2.logging/mock-loggers-elf4j?smo=true | ||
|
||
[javadoc]: https://javadoc.io/badge2/io.github.vitalijr2.logging/mock-loggers-elf4j/javadoc.svg | ||
|
||
[javadoc-link]: https://javadoc.io/doc/io.github.vitalijr2.logging/mock-loggers-elf4j | ||
|
||
[junit-extension]: ../core/ |
Oops, something went wrong.