Skip to content

Commit ac7d9da

Browse files
committed
Add test module and integration tests for JLMap components
- Introduced a new module for testing: io.github.makbn.jlmap.fx.test - Added unit tests for JLJavaFXEngine, JLControlLayer, JLUiLayer, and JLFxMapRenderer. - Implemented integration tests for JLMapView to validate marker, popup, and image overlay functionalities. - Updated module-info.java to include necessary exports and opens for reflection. - Enhanced pom.xml with additional test dependencies and updated Maven Surefire plugin version. Signed-off-by: makbn <[email protected]>
1 parent 722f146 commit ac7d9da

File tree

11 files changed

+2094
-13
lines changed

11 files changed

+2094
-13
lines changed

jlmap-api/src/test/java/io/github/makbn/jlmap/model/builder/JLCircleBuilderTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void builder_withOptions_buildCircle() {
1818
.setLng(20.1)
1919
.setRadius(13)
2020
.setTransporter(() -> transport -> {
21+
return null;
2122
})
2223
.withOptions(JLOptions.DEFAULT)
2324
.withCallbacks(jlCallbackBuilder -> {
@@ -26,29 +27,30 @@ void builder_withOptions_buildCircle() {
2627
jlCallbackBuilder.on(JLAction.REMOVE);
2728
});
2829

29-
assertThat(circleBuilder.buildJsElement()).isEqualTo("""
30+
assertThat(circleBuilder.buildJsElement()
31+
.trim().replaceAll("( +|\r|\n)", " ")).isEqualTo("""
3032
let circle = L.circle([10.200000, 20.100000], { radius: 13.000000, fillOpacity: 0.2, draggable: false, closeButton: true, smoothFactor: 1.0, weight: 3, fill: true, opacity: 1.0, stroke: true, autoClose: true });
3133
this.circle = circle;
3234
circle.uuid = 'circle';
3335
// callback start
3436
this.circle.on('move', e => this.jlMapElement.$server.eventHandler('move', 'jlcircle', e.target.uuid, this.map.getZoom(),
35-
JSON.stringify(e.latlng || {}),
36-
JSON.stringify(this.map.getBounds())
37+
JSON.stringify(e.target.getLatLng() ? { "lat": e.target.getLatLng().lat, "lng": e.target.getLatLng().lng } : {"lat": this.map.getCenter().lat, "lng": this.map.getCenter().lng}),
38+
JSON.stringify(this.map.getBounds())
3739
));
3840
3941
this.circle.on('add', e => this.jlMapElement.$server.eventHandler('add', 'jlcircle', e.target.uuid, this.map.getZoom(),
40-
JSON.stringify(e.latlng || {}),
41-
JSON.stringify(this.map.getBounds())
42+
JSON.stringify(e.target.getLatLng() ? { "lat": e.target.getLatLng().lat, "lng": e.target.getLatLng().lng } : {"lat": this.map.getCenter().lat, "lng": this.map.getCenter().lng}),
43+
JSON.stringify(this.map.getBounds())
4244
));
4345
4446
this.circle.on('remove', e => this.jlMapElement.$server.eventHandler('remove', 'jlcircle', e.target.uuid, this.map.getZoom(),
45-
JSON.stringify(e.latlng || {}),
46-
JSON.stringify(this.map.getBounds())
47+
JSON.stringify(e.target.getLatLng() ? { "lat": e.target.getLatLng().lat, "lng": e.target.getLatLng().lng } : {"lat": this.map.getCenter().lat, "lng": this.map.getCenter().lng}),
48+
JSON.stringify(this.map.getBounds())
4749
));
4850
4951
// callback end
5052
circle.addTo(this.map);
51-
""");
53+
""".trim().replaceAll("( +|\r|\n)", " "));
5254

5355
}
5456
}

jlmap-fx/pom.xml

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,29 @@
9292
<plugin>
9393
<groupId>org.apache.maven.plugins</groupId>
9494
<artifactId>maven-surefire-plugin</artifactId>
95-
<version>3.1.2</version>
95+
<version>3.5.3</version>
9696
<configuration>
97+
<useModulePath>false</useModulePath>
9798
<argLine>
99+
--add-opens javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
100+
--add-opens javafx.graphics/com.sun.javafx.application=org.testfx.junit5
101+
--add-opens javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
102+
--add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
103+
--add-opens javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
98104
--add-opens java.base/java.lang=ALL-UNNAMED
99105
--add-opens java.base/java.util=ALL-UNNAMED
100106
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
101107
--add-opens java.base/java.text=ALL-UNNAMED
102108
--add-opens java.desktop/java.awt.font=ALL-UNNAMED
103109
--add-opens javafx.web/com.sun.javafx.webkit=ALL-UNNAMED
110+
--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
111+
--add-exports javafx.graphics/com.sun.glass.ui=org.testfx.monocle
112+
-Djava.awt.headless=true
113+
-Dtestfx.robot=glass
114+
-Dtestfx.headless=true
115+
-Dprism.order=sw
116+
-Dprism.text=t2k
117+
-Dprism.quantum.multithreaded=false
104118
</argLine>
105119
</configuration>
106120
</plugin>
@@ -119,6 +133,25 @@
119133
</arguments>
120134
</configuration>
121135
</plugin>
136+
<plugin>
137+
<groupId>org.jacoco</groupId>
138+
<artifactId>jacoco-maven-plugin</artifactId>
139+
<version>0.8.8</version>
140+
<executions>
141+
<execution>
142+
<goals>
143+
<goal>prepare-agent</goal>
144+
</goals>
145+
</execution>
146+
<execution>
147+
<id>report</id>
148+
<phase>test</phase>
149+
<goals>
150+
<goal>report</goal>
151+
</goals>
152+
</execution>
153+
</executions>
154+
</plugin>
122155
</plugins>
123156
<sourceDirectory>src/main/java</sourceDirectory>
124157
<testSourceDirectory>src/test/java</testSourceDirectory>
@@ -131,7 +164,11 @@
131164
<artifactId>jlmap-api</artifactId>
132165
<version>${project.version}</version>
133166
</dependency>
134-
167+
<dependency>
168+
<groupId>ch.qos.logback</groupId>
169+
<artifactId>logback-classic</artifactId>
170+
<version>1.5.18</version>
171+
</dependency>
135172
<dependency>
136173
<groupId>org.projectlombok</groupId>
137174
<artifactId>lombok</artifactId>
@@ -171,5 +208,57 @@
171208
<artifactId>javafx-graphics</artifactId>
172209
<version>${javafx.version}</version>
173210
</dependency>
211+
212+
<!-- Test dependencies -->
213+
<dependency>
214+
<groupId>org.junit.jupiter</groupId>
215+
<artifactId>junit-jupiter</artifactId>
216+
<scope>test</scope>
217+
</dependency>
218+
<dependency>
219+
<groupId>org.assertj</groupId>
220+
<artifactId>assertj-core</artifactId>
221+
<version>3.27.4</version>
222+
<scope>test</scope>
223+
</dependency>
224+
<dependency>
225+
<groupId>org.mockito</groupId>
226+
<artifactId>mockito-core</artifactId>
227+
<version>5.7.0</version>
228+
<scope>test</scope>
229+
</dependency>
230+
<dependency>
231+
<groupId>org.mockito</groupId>
232+
<artifactId>mockito-junit-jupiter</artifactId>
233+
<version>5.7.0</version>
234+
<scope>test</scope>
235+
</dependency>
236+
<!-- TestFX for JavaFX testing -->
237+
<dependency>
238+
<groupId>org.testfx</groupId>
239+
<artifactId>testfx-core</artifactId>
240+
<version>4.0.18</version>
241+
<scope>test</scope>
242+
</dependency>
243+
<dependency>
244+
<groupId>org.testfx</groupId>
245+
<artifactId>testfx-junit5</artifactId>
246+
<version>4.0.18</version>
247+
<scope>test</scope>
248+
</dependency>
249+
<!-- TestFX for headless testing -->
250+
<dependency>
251+
<groupId>org.testfx</groupId>
252+
<artifactId>openjfx-monocle</artifactId>
253+
<version>jdk-12.0.1+2</version>
254+
<scope>test</scope>
255+
</dependency>
256+
<!-- Additional utility libraries for testing -->
257+
<dependency>
258+
<groupId>org.awaitility</groupId>
259+
<artifactId>awaitility</artifactId>
260+
<version>4.2.0</version>
261+
<scope>test</scope>
262+
</dependency>
174263
</dependencies>
175264
</project>

jlmap-fx/src/main/java/module-info.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
exports io.github.makbn.jlmap.fx.demo;
3030

3131
// Opens for reflection (if needed by frameworks)
32-
opens io.github.makbn.jlmap.fx to javafx.graphics;
33-
opens io.github.makbn.jlmap.fx.engine to javafx.graphics;
34-
opens io.github.makbn.jlmap.fx.demo to javafx.graphics;
32+
opens io.github.makbn.jlmap.fx to javafx.graphics, io.github.makbn.jlmap.fx.test;
33+
opens io.github.makbn.jlmap.fx.engine to javafx.graphics, io.github.makbn.jlmap.fx.test;
34+
opens io.github.makbn.jlmap.fx.demo to javafx.graphics, io.github.makbn.jlmap.fx.test;
35+
opens io.github.makbn.jlmap.fx.layer to javafx.graphics, io.github.makbn.jlmap.fx.test;
36+
opens io.github.makbn.jlmap.fx.internal to javafx.graphics, io.github.makbn.jlmap.fx.test;
37+
exports io.github.makbn.jlmap.fx.engine;
38+
exports io.github.makbn.jlmap.fx.layer;
39+
exports io.github.makbn.jlmap.fx.internal;
3540
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.github.makbn.jlmap.fx.test.engine;
2+
3+
import io.github.makbn.jlmap.fx.engine.JLJavaFXEngine;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
/**
9+
* Test for JLJavaFXEngine class.
10+
* Note: These tests focus on testing the constructor and basic functionality without JavaFX mocking.
11+
*/
12+
class JLJavaFXEngineTest {
13+
14+
@Test
15+
void constructor_withNullWebEngine_shouldAcceptNullEngine() {
16+
// When/Then - Constructor validation is not implemented in the actual class
17+
// This test documents the current behavior
18+
JLJavaFXEngine engine = new JLJavaFXEngine(null);
19+
assertThat(engine).isNotNull();
20+
}
21+
22+
@Test
23+
void jlJavaFXEngine_shouldExtendJLWebEngine() {
24+
// This test verifies the inheritance hierarchy without requiring JavaFX initialization
25+
Class<?> engineClass = JLJavaFXEngine.class;
26+
27+
// Then
28+
assertThat(engineClass.getSuperclass().getSimpleName()).isEqualTo("JLWebEngine");
29+
}
30+
31+
@Test
32+
void jlJavaFXEngine_shouldHaveCorrectConstructorParameter() {
33+
// This test verifies the constructor exists with correct parameter types
34+
boolean hasCorrectConstructor = false;
35+
36+
try {
37+
JLJavaFXEngine.class.getConstructor(javafx.scene.web.WebEngine.class);
38+
hasCorrectConstructor = true;
39+
} catch (NoSuchMethodException e) {
40+
// Constructor not found
41+
}
42+
43+
// Then
44+
assertThat(hasCorrectConstructor).isTrue();
45+
}
46+
47+
@Test
48+
void jlJavaFXEngine_shouldImplementRequiredMethods() {
49+
// This test verifies required methods exist without requiring JavaFX initialization
50+
Class<?> engineClass = JLJavaFXEngine.class;
51+
52+
boolean hasExecuteScriptMethod = false;
53+
boolean hasGetStatusMethod = false;
54+
55+
try {
56+
engineClass.getDeclaredMethod("executeScript", String.class, Class.class);
57+
hasExecuteScriptMethod = true;
58+
} catch (NoSuchMethodException e) {
59+
// Method not found
60+
}
61+
62+
try {
63+
engineClass.getDeclaredMethod("getStatus");
64+
hasGetStatusMethod = true;
65+
} catch (NoSuchMethodException e) {
66+
// Method not found
67+
}
68+
69+
// Then
70+
assertThat(hasExecuteScriptMethod).isTrue();
71+
assertThat(hasGetStatusMethod).isTrue();
72+
}
73+
}

0 commit comments

Comments
 (0)