Skip to content

Commit 92c3733

Browse files
committed
docs: asciidoc for Java Util Logging
1 parent 0045bca commit 92c3733

File tree

11 files changed

+363
-0
lines changed

11 files changed

+363
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
<modules>
7373
<module>turbo-unit-core</module>
74+
<module>turbo-unit-docs</module>
7475
</modules>
7576

7677
<dependencies>

turbo-unit-docs/pom.xml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.fugerit.java.demo</groupId>
7+
<artifactId>turbo-unit</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>turbo-unit-docs</artifactId>
12+
13+
<packaging>jar</packaging>
14+
15+
<properties>
16+
<!-- asciidoc properties -->
17+
<asciidoctor.maven.plugin.version>3.2.0</asciidoctor.maven.plugin.version>
18+
<asciidoctorj.pdf.version>2.3.19</asciidoctorj.pdf.version>
19+
<asciidoctorj.version>3.0.0</asciidoctorj.version>
20+
<asciidoctorj.diagram.version>2.3.2</asciidoctorj.diagram.version>
21+
<asciidoctorj.diagram-plantuml.version>1.2025.2</asciidoctorj.diagram-plantuml.version>
22+
<asciidoctorj.diagram-ditaamini.version>1.0.3</asciidoctorj.diagram-ditaamini.version>
23+
<jruby.version>9.4.12.0</jruby.version>
24+
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
25+
<pdf-output-folder>${project.build.directory}/generated-pdf</pdf-output-folder>
26+
<html-output-folder>${project.build.directory}/generated-html5</html-output-folder>
27+
</properties>
28+
29+
<build>
30+
<defaultGoal>process-resources</defaultGoal>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.asciidoctor</groupId>
34+
<artifactId>asciidoctor-maven-plugin</artifactId>
35+
<version>${asciidoctor.maven.plugin.version}</version>
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.asciidoctor</groupId>
39+
<artifactId>asciidoctorj-pdf</artifactId>
40+
<version>${asciidoctorj.pdf.version}</version>
41+
</dependency>
42+
<!-- Comment this section to use the default jruby artifact provided by the plugin -->
43+
<dependency>
44+
<groupId>org.jruby</groupId>
45+
<artifactId>jruby</artifactId>
46+
<version>${jruby.version}</version>
47+
</dependency>
48+
<!-- Comment this section to use the default AsciidoctorJ artifact provided by the plugin -->
49+
<dependency>
50+
<groupId>org.asciidoctor</groupId>
51+
<artifactId>asciidoctorj</artifactId>
52+
<version>${asciidoctorj.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.asciidoctor</groupId>
56+
<artifactId>asciidoctorj-diagram</artifactId>
57+
<version>${asciidoctorj.diagram.version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.asciidoctor</groupId>
61+
<artifactId>asciidoctorj-diagram-plantuml</artifactId>
62+
<version>${asciidoctorj.diagram-plantuml.version}</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.asciidoctor</groupId>
66+
<artifactId>asciidoctorj-diagram-ditaamini</artifactId>
67+
<version>${asciidoctorj.diagram-ditaamini.version}</version>
68+
</dependency>
69+
</dependencies>
70+
<configuration>
71+
<requires>
72+
<require>asciidoctor-diagram</require>
73+
</requires>
74+
<resources>
75+
<resource>
76+
<directory>src/main/docs/asciidoc</directory>
77+
<excludes>
78+
<exclude>resources/themes/**</exclude>
79+
</excludes>
80+
</resource>
81+
</resources>
82+
<sourceDirectory>src/main/docs/asciidoc</sourceDirectory>
83+
<enableVerbose>true</enableVerbose>
84+
<logHandler>
85+
<outputToConsole>true</outputToConsole>
86+
</logHandler>
87+
<!-- Attributes common to all output formats -->
88+
<attributes>
89+
<attribute-missing>warn</attribute-missing>
90+
<allow-uri-read>true</allow-uri-read>
91+
<source-highlighter>rouge</source-highlighter>
92+
<imagesdir>./resources/images</imagesdir>
93+
<themesdir>./resources/themes</themesdir>
94+
<revnumber>${project.version}</revnumber>
95+
<revdate>${maven.build.timestamp}</revdate>
96+
<revremark>Digital Version</revremark>
97+
<organization>${project.organization.name}</organization>
98+
</attributes>
99+
</configuration>
100+
<executions>
101+
<execution>
102+
<id>asciidoc-to-pdf</id>
103+
<phase>generate-resources</phase>
104+
<goals>
105+
<goal>process-asciidoc</goal>
106+
</goals>
107+
<configuration>
108+
<backend>pdf</backend>
109+
<doctype>book</doctype>
110+
<sourceDocumentName>index.adoc</sourceDocumentName>
111+
<outputDirectory>${pdf-output-folder}</outputDirectory>
112+
<outputFile>${project.artifactId}-${project.version}.pdf</outputFile>
113+
<attributes>
114+
<pdf-theme>basic</pdf-theme>
115+
<pdf-themesdir>${project.basedir}/src/main/docs/asciidoc/resources/themes</pdf-themesdir>
116+
<icons>font</icons>
117+
<pagenums/>
118+
<toc/>
119+
<idprefix/>
120+
<idseparator>-</idseparator>
121+
</attributes>
122+
</configuration>
123+
</execution>
124+
<execution>
125+
<id>asciidoc-to-html</id>
126+
<phase>generate-resources</phase>
127+
<goals>
128+
<goal>process-asciidoc</goal>
129+
</goals>
130+
<configuration>
131+
<backend>html5</backend>
132+
<outputDirectory>${html-output-folder}</outputDirectory>
133+
<!--
134+
Scenarios for linking vs embedding assets:
135+
136+
Link to both stylesheets and images::
137+
138+
- don't set embedAssets option
139+
- set linkcss attribute to true
140+
- set imagesdir attribute to path relative to AsciiDoc source file
141+
142+
<attributes>
143+
<linkcss>true</linkcss>
144+
<imagesdir>./images</imagesdir>
145+
</attributes>
146+
147+
Embed stylesheets and images::
148+
149+
- set embedAssets option to true
150+
- don't set linkcss attribute
151+
- set imagesdir attribute to path relative to project root
152+
153+
<embedAssets>true</embedAssets>
154+
<attributes>
155+
<imagesdir>src/docs/asciidoc/images</imagesdir>
156+
</attributes>
157+
158+
Link to stylesheets but embed images::
159+
160+
- set embedAssets option to true
161+
- set linkcss attribute to true
162+
- set imagesdir attribute to path relative to project root
163+
164+
<embedAssets>true</embedAssets>
165+
<attributes>
166+
<linkcss>true</linkcss>
167+
<imagesdir>src/docs/asciidoc/images</imagesdir>
168+
</attributes>
169+
170+
Embed stylesheets but link images (default)::
171+
172+
- don't set embedAssets option
173+
- don't set linkcss attribute
174+
- set imagesdir attribute to path relative to AsciiDoc source file
175+
176+
<attributes>
177+
<imagesdir>./images</imagesdir>
178+
</attributes>
179+
180+
IMPORTANT: When you enable image embedding, you must qualify the path with imagesdir, as shown above.
181+
-->
182+
<attributes>
183+
<source-highlighter>rouge</source-highlighter>
184+
<imagesdir>resources/images</imagesdir>
185+
<toc>left</toc>
186+
<icons>font</icons>
187+
<sectanchors>true</sectanchors>
188+
<!-- set the idprefix to blank -->
189+
<idprefix/>
190+
<idseparator>-</idseparator>
191+
<docinfo1>true</docinfo1>
192+
</attributes>
193+
</configuration>
194+
</execution>
195+
</executions>
196+
</plugin>
197+
</plugins>
198+
</build>
199+
200+
<dependencies>
201+
202+
</dependencies>
203+
204+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
body {
2+
font-family: Arial, Helvetica, sans-serif;
3+
background-color: #303030;
4+
color: #90DD90;
5+
}
6+
7+
/* unvisited link */
8+
a:link {
9+
color: #EE6096;
10+
}
11+
12+
/* visited link */
13+
a:visited {
14+
color: #EE6096;
15+
}
16+
17+
/* mouse over link */
18+
a:hover {
19+
color: #EE6096;
20+
}
21+
22+
/* selected link */
23+
a:active {
24+
color: #EE6096;
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
:author: Matteo Franci
2+
:revnumber: v1.0.0
3+
:revdate: October 15, 2024
4+
:email: m@fugerit.org
5+
:description: Turbo Unit : a range of complex use case on unit testing (based on Junit 5)
6+
:keywords: java, xml, json, yaml, kotlin, pdf, html, xlsx, csv, document generation
7+
:encoding: utf-8
8+
:lang: en
9+
:toc: left
10+
:hardbreaks-option:
11+
:sectnums:
12+
:sectnumlevels: 3
13+
:!figure-caption:
14+
:!chapter-signifier:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:doctype: book
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[#unit-logging]
2+
== Unit test for logging
3+
4+
This chapter describes how to test if a specific line of code has been tested.
5+
6+
[#unit-logging-jul]
7+
=== Unit test for Java Util Logging (JUL)
8+
9+
Here is a simple class we want to test :
10+
11+
[source,java]
12+
----
13+
public class ExampleJavaUtilLogging {
14+
15+
public static final String HELLO = "Hello Turbo!";
16+
17+
private static Logger log = Logger.getLogger(ExampleJavaUtilLogging.class.getName());
18+
19+
public void logHello() {
20+
log.info( HELLO );
21+
}
22+
23+
}
24+
----
25+
26+
Here is the full link:https://github.com/fugerit-org/turbo-unit/blob/main/turbo-unit-core/src/main/java/org/fugerit/java/turbo/unit/core/jul/ExampleJavaUtilLogging.java[ExampleJavaUtilLogging.java] java code.
27+
28+
And we want to test if the line "Hello Turbo!" has been actually logged :
29+
30+
[source,java]
31+
----
32+
@Test
33+
void testLogHello() {
34+
ExampleJavaUtilLogging log = new ExampleJavaUtilLogging();
35+
log.logHello();
36+
Assertions.assertTrue( LOG_MESSAGE_INTERCEPTOR_HANDLER.containsLogMessage(ExampleJavaUtilLogging.HELLO) );
37+
}
38+
----
39+
40+
This is achieved using an implementation of _java.util.loggin.Handler_ :
41+
42+
[source,java]
43+
----
44+
public static class LogMessageInterceptorHandler extends Handler {
45+
46+
private Set<String> messages = new HashSet<>();
47+
48+
@Override
49+
public void publish(LogRecord lr) {
50+
// add log messages to a set
51+
this.messages.add(lr.getMessage());
52+
}
53+
54+
@Override
55+
public boolean isLoggable(LogRecord lr) {
56+
return super.isLoggable(lr);
57+
}
58+
59+
public boolean containsLogMessage(String message) {
60+
// check if a message has been logged
61+
return this.messages.contains(message);
62+
}
63+
64+
}
65+
----
66+
67+
Here is the full link:https://github.com/fugerit-org/turbo-unit/blob/main/turbo-unit-core/src/test/java/org/fugerit/java/turbo/unit/core/jul/TestExampleJavaUtilLogging.java[TestExampleJavaUtilLogging.java] sample code.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
= Turbo Unit shows a range of complex use case on unit testing (based on Junit 5)
2+
// format attributes inclusions
3+
include::attributes/_attributes-pdf.adoc[]
4+
include::attributes/_attributes-common.adoc[]
5+
6+
// Chapters inclusions
7+
8+
include::chapters/001-logging.adoc[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
images go here
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
extends:
2+
- default-with-fallback-font
3+
cover:
4+
front:
5+
image: image:book_cover_basic_v1.0.0.png[page=2]
6+
back:
7+
image: image:book_cover_back_basic_v1.0.0.png[fit=fill]
8+
title-page: false
9+
page:
10+
margin: [ 0.75in, 0.75in, 0.75in, 0.75in ]
11+
base:
12+
line-height-length: 20
13+
heading:
14+
font-color: #C50505
15+
font-size: 12
16+
line-height: 1.2
17+
link:
18+
font-color: #0e86d8
19+
header:
20+
height: 0.75in
21+
line-height: 1
22+
recto:
23+
right:
24+
content: '{document-title} | v{revnumber}'
25+
verso:
26+
left:
27+
content: '{document-title} | v{revnumber}'
28+
footer:
29+
height: 0.75in
30+
line-height: 1
31+
recto:
32+
right:
33+
content: '{chapter-title} | *{page-number}*'
34+
verso:
35+
left:
36+
content: '*{page-number}* | {chapter-title}'
37+
image:
38+
align: center
39+
caption:
40+
align: center
41+
font-color: #C50505
42+
font-size: 10
26.7 KB
Loading

0 commit comments

Comments
 (0)