Skip to content

Commit 07b790b

Browse files
authored
Fix #68: add SPI module metadata unit tests (#69)
1 parent 7f9513f commit 07b790b

File tree

8 files changed

+232
-0
lines changed

8 files changed

+232
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.jsonp;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest extends TestBase
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = JSONPModule.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expecteed to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.jakarta.mail;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest extends TestBase
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = JakartaMailModule.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expecteed to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.javax.money;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = JavaxMoneyModule.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expected to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.jodamoney;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest extends ModuleTestBase
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = JodaMoneyModule.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expected to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.jsonorg;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest extends ModuleTestBase
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = JsonOrgModule.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expected to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.jsr353;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest extends TestBase
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = JSR353Module.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expected to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.datatype.moneta;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import java.util.ServiceLoader;
8+
9+
public class ModuleSPIMetadataTest
10+
{
11+
@Test
12+
void testModuleSPIMetadata() {
13+
ServiceLoader<com.fasterxml.jackson.databind.Module> loader
14+
= ServiceLoader.load(com.fasterxml.jackson.databind.Module.class);
15+
assertTrue(loader.iterator().hasNext(),
16+
"Expected at least one `Module` implementation to be found via `ServiceLoader`");
17+
final String exp = MonetaMoneyModule.class.getName();
18+
int count = 0;
19+
20+
try {
21+
for (com.fasterxml.jackson.databind.Module service : loader) {
22+
++count;
23+
if (service.getClass().getName().equals(exp)) {
24+
return;
25+
}
26+
}
27+
} catch (Throwable t) {
28+
fail("Expected to find `"+exp+"` Module (found "+count+" so far), problem: "+t);
29+
}
30+
fail("Expected to find `"+exp+"` Module (found "+count+" others)");
31+
assertEquals(1, count);
32+
}
33+
}

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Modules:
1313

1414
2.20.0 (not yet released)
1515

16+
#68: Add unit tests to verify goodness of SPI metadata for Modules
1617
- Generate SBOMs [JSTEP-14]
1718

1819
2.19.0 (24-Apr-2025)

0 commit comments

Comments
 (0)