diff --git a/build.gradle.kts b/build.gradle.kts index ae4cf541..2a2a5f8f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -104,7 +104,7 @@ tasks.test { testing { suites { // Separate test suite for module testing - val testModular by registering(JvmTestSuite::class) { + val testJavaModule by registering(JvmTestSuite::class) { dependencies { implementation(project) } @@ -116,7 +116,7 @@ testing { if (JavaVersion.current().isJava9Compatible) { tasks.check { @Suppress("UnstableApiUsage") - dependsOn(testing.suites.named("testModular")) + dependsOn(testing.suites.named("testJavaModule")) } } diff --git a/src/main/java-9/module-info.java b/src/main/java-9/module-info.java index b2dbf69e..93bc2312 100644 --- a/src/main/java-9/module-info.java +++ b/src/main/java-9/module-info.java @@ -1,5 +1,22 @@ +/* + * Copyright © 2018-today Peter M. Stahl pemistahl@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + module com.github.pemistahl.lingua { exports com.github.pemistahl.lingua.api; + exports com.github.pemistahl.lingua.api.io; requires kotlin.stdlib; diff --git a/src/testJavaModule/java/module-info.java b/src/testJavaModule/java/module-info.java new file mode 100644 index 00000000..02b757ac --- /dev/null +++ b/src/testJavaModule/java/module-info.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2018-today Peter M. Stahl pemistahl@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Open complete module for reflection to allow JUnit to access the packages +open module test { + requires com.github.pemistahl.lingua; + + requires org.junit.jupiter.api; +} diff --git a/src/testJavaModule/java/test/LinguaTest.java b/src/testJavaModule/java/test/LinguaTest.java new file mode 100644 index 00000000..b6cb21b3 --- /dev/null +++ b/src/testJavaModule/java/test/LinguaTest.java @@ -0,0 +1,74 @@ +/* + * Copyright © 2018-today Peter M. Stahl pemistahl@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.io.TempDir; + +import com.github.pemistahl.lingua.api.Language; +import com.github.pemistahl.lingua.api.LanguageDetector; +import com.github.pemistahl.lingua.api.LanguageDetectorBuilder; +import com.github.pemistahl.lingua.api.io.LanguageModelFilesWriter; + +import static java.util.stream.Collectors.toList; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.condition.OS.WINDOWS; + +import static com.github.pemistahl.lingua.api.Language.ENGLISH; +import static com.github.pemistahl.lingua.api.Language.FRENCH; +import static com.github.pemistahl.lingua.api.Language.SPANISH; + +/** + * Tests basic Lingua functionality. The main purpose of this test is to verify that the + * packages can be accessed from a different module and that Lingua specifies all required + * modules and can be used successfully. + */ +class LinguaTest { + @Test + void testDetector() { + LanguageDetector detector = LanguageDetectorBuilder.fromLanguages(ENGLISH, FRENCH, SPANISH).build(); + Language detectedLanguage = detector.detectLanguageOf("languages are awesome"); + assertEquals(ENGLISH, detectedLanguage); + } + + @Test + @DisabledOnOs(WINDOWS) // TempDir cannot be deleted on Windows + void testLanguageModelFilesWriter(@TempDir Path outputDirectoryPath) throws Exception { + Path inputFilePath = Files.createTempFile(null, null); + + LanguageModelFilesWriter.createAndWriteLanguageModelFiles( + inputFilePath, + StandardCharsets.UTF_8, + outputDirectoryPath, + ENGLISH, + "\\p{L}&&\\p{IsLatin}" + ); + + List filesList = Files.list(outputDirectoryPath).collect(toList()); + + assertEquals(5, filesList.size()); + + inputFilePath.toFile().delete(); + } +} diff --git a/src/testModular/java/module-info.java b/src/testModular/java/module-info.java deleted file mode 100644 index 2069c996..00000000 --- a/src/testModular/java/module-info.java +++ /dev/null @@ -1,6 +0,0 @@ -// Open complete module for reflection to allow JUnit to access the packages -open module test { - requires com.github.pemistahl.lingua; - - requires org.junit.jupiter.api; -} diff --git a/src/testModular/java/test/LinguaTest.java b/src/testModular/java/test/LinguaTest.java deleted file mode 100644 index f06c9fda..00000000 --- a/src/testModular/java/test/LinguaTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package test; - -import com.github.pemistahl.lingua.api.*; -import org.junit.jupiter.api.Test; - -import static com.github.pemistahl.lingua.api.Language.*; -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Tests basic Lingua functionality. The main purpose of this test is to verify that the - * packages can be accessed from a different module and that Lingua specifies all required - * modules and can be used successfully. - */ -class LinguaTest { - @Test - void test() { - LanguageDetector detector = LanguageDetectorBuilder.fromLanguages(ENGLISH, FRENCH, GERMAN, SPANISH).build(); - Language detectedLanguage = detector.detectLanguageOf("languages are awesome"); - assertEquals(ENGLISH, detectedLanguage); - } -}