-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
230 additions
and
17 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
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
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
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
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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
spreadsheet-standalone/src/test/java/_test/DependencyResolver.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,61 @@ | ||
package _test; | ||
|
||
import lombok.NonNull; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@lombok.experimental.UtilityClass | ||
public class DependencyResolver { | ||
|
||
public static @NonNull List<GAV> parse(@NonNull Stream<String> lines) { | ||
return lines | ||
.filter(DependencyResolver::isValidLine) | ||
.map(DependencyResolver::removeAnsiControlChars) | ||
.map(DependencyResolver::extract) | ||
.map(GAV::parse) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static final String PREFIX = " "; | ||
private static final String SUFFIX = " -- module"; | ||
|
||
private static boolean isValidLine(String line) { | ||
return line.startsWith(PREFIX); | ||
} | ||
|
||
private static String removeAnsiControlChars(String input) { | ||
return input.replaceAll("\u001B\\[[;\\d]*m", ""); | ||
} | ||
|
||
private static String extract(String input) { | ||
int start = PREFIX.length(); | ||
int end = input.indexOf(SUFFIX, start); | ||
return input.substring(start, end == -1 ? input.length() : end); | ||
} | ||
|
||
@lombok.Value | ||
public static class GAV { | ||
|
||
public static @NonNull GAV parse(@NonNull CharSequence input) { | ||
String[] items = input.toString().split(":", -1); | ||
if (items.length < 4) { | ||
throw new IllegalArgumentException("Invalid GAV: '" + input + "'"); | ||
} | ||
return new GAV(items[0], items[1], items[3]); | ||
} | ||
|
||
@NonNull String groupId; | ||
@NonNull String artifactId; | ||
@NonNull String version; | ||
|
||
public static boolean haveSameVersion(@NonNull List<? extends GAV> list) { | ||
return list | ||
.stream() | ||
.map(GAV::getVersion) | ||
.distinct() | ||
.count() == 1; | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
spreadsheet-standalone/src/test/java/spreadsheet4j/standalone/RuntimeDependenciesTest.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,91 @@ | ||
package spreadsheet4j.standalone; | ||
|
||
import _test.DependencyResolver; | ||
import nbbrd.io.text.TextParser; | ||
import org.assertj.core.api.Condition; | ||
import org.assertj.core.api.ListAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.util.List; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RuntimeDependenciesTest { | ||
|
||
@Test | ||
public void testRuntimeDependencies() throws IOException { | ||
assertThat(getRuntimeDependencies()) | ||
.describedAs("Check runtime dependencies") | ||
.satisfies(RuntimeDependenciesTest::checkJavaIoUtil) | ||
.satisfies(RuntimeDependenciesTest::checkSpreadsheet4j) | ||
.satisfies(RuntimeDependenciesTest::checkFastExcel) | ||
.satisfies(RuntimeDependenciesTest::checkSods) | ||
.satisfies(RuntimeDependenciesTest::checkJsoup) | ||
.hasSize(12); | ||
} | ||
|
||
private static void checkSpreadsheet4j(List<? extends DependencyResolver.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.spreadsheet4j") | ||
.has(sameVersion()) | ||
.extracting(DependencyResolver.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder( | ||
"spreadsheet-api", | ||
"spreadsheet-fastexcel", | ||
"spreadsheet-html", | ||
"spreadsheet-od", | ||
"spreadsheet-xl", | ||
"spreadsheet-xmlss"); | ||
} | ||
|
||
private static void checkJavaIoUtil(List<? extends DependencyResolver.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util") | ||
.has(sameVersion()) | ||
.extracting(DependencyResolver.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("java-io-xml", "java-io-base"); | ||
} | ||
|
||
private static void checkFastExcel(List<? extends DependencyResolver.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "org.dhatim") | ||
.extracting(DependencyResolver.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("fastexcel"); | ||
|
||
assertThatGroupId(coordinates, "com.github.rzymek") | ||
.extracting(DependencyResolver.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("opczip"); | ||
} | ||
|
||
private static void checkSods(List<? extends DependencyResolver.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "com.github.miachm.sods") | ||
.extracting(DependencyResolver.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("SODS"); | ||
} | ||
|
||
private static void checkJsoup(List<? extends DependencyResolver.GAV> coordinates) { | ||
assertThatGroupId(coordinates, "org.jsoup") | ||
.extracting(DependencyResolver.GAV::getArtifactId) | ||
.containsExactlyInAnyOrder("jsoup"); | ||
} | ||
|
||
private static ListAssert<? extends DependencyResolver.GAV> assertThatGroupId(List<? extends DependencyResolver.GAV> coordinates, String groupId) { | ||
return assertThat(coordinates) | ||
.describedAs("Check " + groupId) | ||
.filteredOn(DependencyResolver.GAV::getGroupId, groupId); | ||
} | ||
|
||
private static Condition<List<? extends DependencyResolver.GAV>> sameVersion() { | ||
return new Condition<>(DependencyResolver.GAV::haveSameVersion, "same version"); | ||
} | ||
|
||
private static List<DependencyResolver.GAV> getRuntimeDependencies() throws IOException { | ||
return TextParser.onParsingReader(reader -> DependencyResolver.parse(asBufferedReader(reader).lines())) | ||
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.txt", UTF_8); | ||
} | ||
|
||
private static BufferedReader asBufferedReader(Reader reader) { | ||
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); | ||
} | ||
} |
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
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