-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#336: Add provides tags for ServiceLoader
- Loading branch information
1 parent
b74acee
commit c1f00de
Showing
9 changed files
with
172 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
/** | ||
* This provides an exporter for the SpecObject XML format. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.exporter.ExporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.exporter.specobject | ||
{ | ||
exports org.itsallcode.openfasttrace.exporter.specobject; | ||
|
||
requires java.logging; | ||
requires java.xml; | ||
requires org.itsallcode.openfasttrace.api; | ||
requires org.itsallcode.openfasttrace.exporter.common; | ||
|
||
provides org.itsallcode.openfasttrace.api.exporter.ExporterFactory | ||
with org.itsallcode.openfasttrace.exporter.specobject.SpecobjectExporterFactory; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
/** | ||
* This provides an importer for the MarkDown format. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.importer.markdown | ||
{ | ||
exports org.itsallcode.openfasttrace.importer.markdown; | ||
|
||
requires java.logging; | ||
requires transitive org.itsallcode.openfasttrace.api; | ||
|
||
provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
with org.itsallcode.openfasttrace.importer.markdown.MarkdownImporterFactory; | ||
} |
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
/** | ||
* This provides an importer for the SpecObject XML format. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.importer.specobject | ||
{ | ||
exports org.itsallcode.openfasttrace.importer.specobject; | ||
exports org.itsallcode.openfasttrace.importer.specobject.handler; | ||
exports org.itsallcode.openfasttrace.importer.specobject.xml; | ||
exports org.itsallcode.openfasttrace.importer.specobject.xml.tree; | ||
exports org.itsallcode.openfasttrace.importer.specobject.xml.event; | ||
|
||
requires java.logging; | ||
requires transitive java.xml; | ||
requires transitive org.itsallcode.openfasttrace.api; | ||
|
||
provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
with org.itsallcode.openfasttrace.importer.specobject.SpecobjectImporterFactory; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
/** | ||
* This provides an importer for coverage tags. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.importer.tag | ||
{ | ||
exports org.itsallcode.openfasttrace.importer.tag; | ||
|
||
requires java.logging; | ||
requires transitive org.itsallcode.openfasttrace.api; | ||
|
||
provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
with org.itsallcode.openfasttrace.importer.tag.TagImporterFactory; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
/** | ||
* This provides an importer for the ZIP files. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.importer.zip | ||
{ | ||
exports org.itsallcode.openfasttrace.importer.zip; | ||
exports org.itsallcode.openfasttrace.importer.zip.input; | ||
|
||
requires transitive org.itsallcode.openfasttrace.api; | ||
|
||
provides org.itsallcode.openfasttrace.api.importer.ImporterFactory | ||
with org.itsallcode.openfasttrace.importer.zip.ZipFileImporterFactory; | ||
} |
132 changes: 132 additions & 0 deletions
132
product/src/test/java/org/itsallcode/openfasttrace/TestAllServicesAvailable.java
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,132 @@ | ||
package org.itsallcode.openfasttrace; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.withSettings; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.ServiceLoader; | ||
import java.util.stream.Stream; | ||
|
||
import org.itsallcode.openfasttrace.api.core.Newline; | ||
import org.itsallcode.openfasttrace.api.core.Trace; | ||
import org.itsallcode.openfasttrace.api.exporter.Exporter; | ||
import org.itsallcode.openfasttrace.api.exporter.ExporterContext; | ||
import org.itsallcode.openfasttrace.api.exporter.ExporterFactory; | ||
import org.itsallcode.openfasttrace.api.importer.ImportEventListener; | ||
import org.itsallcode.openfasttrace.api.importer.Importer; | ||
import org.itsallcode.openfasttrace.api.importer.ImporterContext; | ||
import org.itsallcode.openfasttrace.api.importer.ImporterFactory; | ||
import org.itsallcode.openfasttrace.api.importer.input.InputFile; | ||
import org.itsallcode.openfasttrace.api.importer.input.RealFileInput; | ||
import org.itsallcode.openfasttrace.api.report.Reportable; | ||
import org.itsallcode.openfasttrace.api.report.ReporterContext; | ||
import org.itsallcode.openfasttrace.api.report.ReporterFactory; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.mockito.Answers; | ||
|
||
class TestAllServicesAvailable | ||
{ | ||
private static List<ImporterFactory> importerFactories; | ||
private static List<ExporterFactory> exporterFactories; | ||
private static List<ReporterFactory> reporterFactories; | ||
|
||
@BeforeAll | ||
static void loadFactories() | ||
{ | ||
importerFactories = loadImporterFactories(); | ||
exporterFactories = loadExporterFactories(); | ||
reporterFactories = loadReporterFactories(); | ||
} | ||
|
||
private static List<ImporterFactory> loadImporterFactories() | ||
{ | ||
final ServiceLoader<ImporterFactory> loader = ServiceLoader.load(ImporterFactory.class); | ||
final ImporterContext contextMock = mock(ImporterContext.class, | ||
withSettings().defaultAnswer(Answers.RETURNS_DEEP_STUBS)); | ||
final List<ImporterFactory> importerFactories = loader.stream() // | ||
.map(ServiceLoader.Provider::get).collect(toList()); | ||
importerFactories.forEach(factory -> factory.init(contextMock)); | ||
return importerFactories; | ||
} | ||
|
||
private static List<ExporterFactory> loadExporterFactories() | ||
{ | ||
final ServiceLoader<ExporterFactory> loader = ServiceLoader.load(ExporterFactory.class); | ||
final ExporterContext contextMock = mock(ExporterContext.class, | ||
withSettings().defaultAnswer(Answers.RETURNS_DEEP_STUBS)); | ||
final List<ExporterFactory> exporterFactories = loader.stream() // | ||
.map(ServiceLoader.Provider::get).collect(toList()); | ||
exporterFactories.forEach(factory -> factory.init(contextMock)); | ||
return exporterFactories; | ||
} | ||
|
||
private static List<ReporterFactory> loadReporterFactories() | ||
{ | ||
final ServiceLoader<ReporterFactory> loader = ServiceLoader.load(ReporterFactory.class); | ||
final ReporterContext contextMock = mock(ReporterContext.class, | ||
withSettings().defaultAnswer(Answers.RETURNS_DEEP_STUBS)); | ||
final List<ReporterFactory> reporterFactories = loader.stream() // | ||
.map(ServiceLoader.Provider::get).collect(toList()); | ||
reporterFactories.forEach(factory -> factory.init(contextMock)); | ||
return reporterFactories; | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
{ "md", "oreqm", "java", "zip" }) | ||
void importerAvailable(final String suffix) | ||
{ | ||
final InputFile file = RealFileInput.forPath(Paths.get("file." + suffix)); | ||
final Optional<ImporterFactory> factory = importerFactories.stream() // | ||
.filter(f -> f.supportsFile(file)) // | ||
.findAny(); | ||
if (factory.isEmpty()) | ||
{ | ||
fail("No importer found for file name suffix '" + suffix + "'"); | ||
} | ||
final Importer importer = factory.get().createImporter(file, mock(ImportEventListener.class)); | ||
assertNotNull(importer); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
{ "specobject" }) | ||
void exporterAvailable(final String format) | ||
{ | ||
final Optional<ExporterFactory> factory = exporterFactories.stream() // | ||
.filter(f -> f.supportsFormat(format)) // | ||
.findAny(); | ||
if (factory.isEmpty()) | ||
{ | ||
fail("No exporter found for format '" + format + "'"); | ||
} | ||
final Exporter exporter = factory.get().createExporter(Path.of("file"), format, StandardCharsets.UTF_8, | ||
Newline.UNIX, Stream.empty()); | ||
assertNotNull(exporter); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
{ "aspec", "html", "plain" }) | ||
void reporterAvailable(final String format) | ||
{ | ||
final Optional<ReporterFactory> factory = reporterFactories.stream() // | ||
.filter(f -> f.supportsFormat(format)) // | ||
.findAny(); | ||
if (factory.isEmpty()) | ||
{ | ||
fail("No reporter found for format '" + format + "'"); | ||
} | ||
final Reportable reportable = factory.get().createImporter(Trace.builder().build()); | ||
assertNotNull(reportable); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
/** | ||
* This provides an report generator for the Aspec format. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.report.ReporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.report.aspec | ||
{ | ||
exports org.itsallcode.openfasttrace.report.aspec; | ||
|
||
requires java.xml; | ||
requires java.logging; | ||
requires org.itsallcode.openfasttrace.api; | ||
requires org.itsallcode.openfasttrace.exporter.common; | ||
|
||
provides org.itsallcode.openfasttrace.api.report.ReporterFactory | ||
with org.itsallcode.openfasttrace.report.aspec.ASpecReporterFactory; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/** | ||
* This provides an report generator for the HTML format. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.report.ReporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.report.html | ||
{ | ||
exports org.itsallcode.openfasttrace.report.html; | ||
exports org.itsallcode.openfasttrace.report.html.view; | ||
exports org.itsallcode.openfasttrace.report.html.view.html; | ||
|
||
requires transitive org.itsallcode.openfasttrace.api; | ||
|
||
provides org.itsallcode.openfasttrace.api.report.ReporterFactory | ||
with org.itsallcode.openfasttrace.report.html.HtmlReporterFactory; | ||
} |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
/** | ||
* This provides an report generator for the plain text format. | ||
* | ||
* @provides org.itsallcode.openfasttrace.api.report.ReporterFactory | ||
*/ | ||
module org.itsallcode.openfasttrace.report.plaintext | ||
{ | ||
exports org.itsallcode.openfasttrace.report.plaintext; | ||
|
||
requires transitive org.itsallcode.openfasttrace.api; | ||
|
||
provides org.itsallcode.openfasttrace.api.report.ReporterFactory | ||
with org.itsallcode.openfasttrace.report.plaintext.PlaintextReporterFactory; | ||
} |