Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Add javadoc amd README
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalijr2 committed Jul 16, 2024
1 parent 4142db8 commit 519f772
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
exclude_paths:
- "**/mock-jdk-platform-logging.css"
- "**/prism.css"
- "**/prism.js"
2 changes: 1 addition & 1 deletion .github/workflows/sonatype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
SIGN_KEY_PASS: ${{ secrets.SIGN_KEY_PASS }}
SONATYPE_TOKEN_USERNAME: ${{ secrets.SONATYPE_TOKEN_USERNAME }}
SONATYPE_TOKEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }}
run: ./mvnw --batch-mode -s .mvn/ci_settings.xml -pl core,logger,json-logger,. -am -ntp -DskipTests -Prelease
run: ./mvnw --batch-mode -s .mvn/ci_settings.xml -am -ntp -DskipTests -Prelease
109 changes: 109 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,54 @@
<artifactId>mock-jdk-platform-logging</artifactId>
<build>
<defaultGoal>clean verify</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalJOptions>
<additionalJOption>
-J-Dhttp.agent=maven-javadoc-plugin_${project.groupId}:${project.artifactId}
</additionalJOption>
</additionalJOptions>
<additionalOptions>
<additionalOption>--allow-script-in-comments</additionalOption>
</additionalOptions>
<bottom><![CDATA[
<script type="text/javascript" src="{@docRoot}/resources/prism.js"></script>
]]></bottom>
<docfilessubdirs>true</docfilessubdirs>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
<links>
<link>https://javadoc.io/doc/org.mockito/mockito-core/${mockito.version}/</link>
</links>
<offline>false</offline>
<show>public</show>
<top><![CDATA[
<link rel="stylesheet" type="text/css" href="{@docRoot}/resources/prism.css"/>
<link rel="stylesheet" type="text/css" href="{@docRoot}/resources/mock-jdk-platform-logging.css"/>
]]></top>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<version>${javadoc-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>sign-maven-plugin</artifactId>
<groupId>org.simplify4u.plugins</groupId>
<version>1.1.0</version>
</plugin>
<plugin>
<artifactId>central-publishing-maven-plugin</artifactId>
<groupId>org.sonatype.central</groupId>
<version>0.4.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
Expand Down Expand Up @@ -269,11 +317,72 @@
</licenses>
<modelVersion>4.0.0</modelVersion>
<name>Mock of JDK Platform Logging</name>
<profiles>
<profile>
<build>
<defaultGoal>clean deploy</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<id>attach-javadocs</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<id>attach-sources</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
</plugin>
<plugin>
<artifactId>sign-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<groupId>org.simplify4u.plugins</groupId>
</plugin>
<plugin>
<artifactId>central-publishing-maven-plugin</artifactId>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
<extensions>true</extensions>
<groupId>org.sonatype.central</groupId>
</plugin>
</plugins>
</build>
<id>release</id>
</profile>
</profiles>
<properties>
<java.version>11</java.version>
<javadoc-plugin.version>3.7.0</javadoc-plugin.version>
<junit-jupiter.version>5.10.3</junit-jupiter.version>
<mockito.version>5.12.0</mockito.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<scm>
<connection>scm:git:https://github.com/vitalijr2/mock-jdk-platform-logging.git</connection>
<developerConnection>scm:git:git@github.com:vitalijr2/mock-jdk-platform-logging.git</developerConnection>
<url>https://github.com/vitalijr2/mock-jdk-platform-logging</url>
</scm>
<url>https://github.com/vitalijr2/mock-jdk-platform-logging</url>
<version>1.0.0-SNAPSHOT</version>
</project>
93 changes: 93 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Mock of JDK Platform Logging

JDK Platform Logging Service with mocked loggers backed by [Mockito][].

## How to use

Just put to your POM:
```xml
<dependencies>
...
<dependency>
<artifactId>mock-jdk-platform-logging</artifactId>
<groupId>io.github.vitalijr2.logging</groupId>
<scope>test</scope>
<version>1.0.0</version>
</dependency>
...
</dependencies>

```

Example:
```java
// the static logger instance
private static Logger logger;

// initialize it once
@BeforeAll
static void setUpClass() {
logger = System.getLogger("test");
}

// clean it after each test
@AfterEach
void tearDown() {
clearInvocations(logger);
}

// use the mock in a test
@DisplayName("Test")
@ParameterizedTest
@ValueSource(strings = {"TRACE", "DEBUG", "INFO", "WARNING", "ERROR"})
void test(Level level) {
// given
var logger = System.getLogger("test")

// when
logger.log(level, "test message");

// then
verify(logger).log(level, "test message");
}
```

## Credits

There are two projects which inspired me to make this library:

- [s4u/slf4j-mock][slf4j-mock]
- [ocarlsen/mock-slf4j-impl][mock-slf4j-impl]

## Contributing

Please read [Contributing](contributing.md).

## History

See [Changelog](changelog.md)

## License

Copyright 2023-2024 Vitalij Berdinskih

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

<https://www.apache.org/licenses/LICENSE-2.0>

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

[Apache License v2.0](LICENSE)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html)

[Mockito]: https://site.mockito.org

[slf4j-mock]: https://github.com/s4u/slf4j-mock

[mock-slf4j-impl]: https://github.com/ocarlsen/mock-slf4j-impl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
import org.jetbrains.annotations.VisibleForTesting;

/**
* Uses {@link org.mockito.Mockito#mock(Class)} to get a logger that is adapted for {@link System.Logger}.
* Uses {@link org.mockito.Mockito#mock(Class, String)} to get a logger that is adapted for {@link System.Logger}.
*/
public class MockitoLoggerFinder extends LoggerFinder {

private final Map<String, Logger> loggers;

/**
* Create a map-based logger finder. The finder uses a concurrent map: a logger name is a key.
*/
public MockitoLoggerFinder() {
this(new ConcurrentHashMap<>());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* JDK Platform Logging Service implementation.
*
* @since 1.0.0
*/
package io.github.vitalijr2.mock.jdk.platform.logging;
55 changes: 55 additions & 0 deletions src/main/javadoc/overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mock of JDK Platform Logging</title>
</head>
<body>
<h1>Mock of JDK Platform Logging</h1>
<p>JDK Platform Logging Service with mocked loggers backed by <a href="https://site.mockito.org/">Mockito</a>.</p>
<p id="badges">
<a href="https://app.codacy.com/gh/vitalijr2/mock-jdk-platform-logging/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img
alt="Codacy Badge" src="https://app.codacy.com/project/badge/Grade/9be380deaf3e40138ad306a40532289c"></a>
<a href="https://app.codacy.com/gh/vitalijr2/mock-jdk-platform-logging/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage"><img
alt="Codacy Coverage" src="https://app.codacy.com/project/badge/Coverage/9be380deaf3e40138ad306a40532289c"></a>
<a href="https://libraries.io/github/vitalijr2/mock-jdk-platform-logging"><img
alt="Libraries.io dependency status for GitHub repo"
src="https://img.shields.io/librariesio/github/vitalijr2/mock-jdk-platform-logging"></a>
<a href="https://www.oracle.com/java/technologies/downloads/#java11"><img
alt="Java Version"
src="https://img.shields.io/static/v1?label=java&message=11&color=blue&logo=java&logoColor=E23D28"></a>
</p>
Example:
<pre><code class="language-java">
// the static logger instance
private static Logger logger;

// initialize it once
{@literal @}BeforeAll
static void setUpClass() {
logger = System.getLogger("test");
}

// clean it after each test
{@literal @}AfterEach
void tearDown() {
clearInvocations(logger);
}

// use the mock in a test
{@literal @}DisplayName("Test")
{@literal @}ParameterizedTest
{@literal @}ValueSource(strings = {"TRACE", "DEBUG", "INFO", "WARNING", "ERROR"})
void test(Level level) {
// given
var logger = System.getLogger("test")

// when
logger.log(level, "test message");

// then
verify(logger).log(level, "test message");
}
</code></pre>
</body>
</html>
27 changes: 27 additions & 0 deletions src/main/javadoc/resources/mock-jdk-platform-logging.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.tooltip {
border-bottom: 1px dotted #4d7a97;
display: inline-block;
position: relative;
}

.tooltip .tooltiptext {
background-color: #f8981d;
border: 1px dotted #4d7a97;
-moz-border-radius: 6px;
-ms-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
color: #253441;
left: 113%;
padding: 5px 3px;
position: absolute;
text-align: center;
top: -5px;
visibility: hidden;
width: 97px;
z-index: 1;
}

.tooltip:hover .tooltiptext {
visibility: visible;
}
4 changes: 4 additions & 0 deletions src/main/javadoc/resources/prism.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 519f772

Please sign in to comment.