Skip to content

Commit

Permalink
Add io package to Java module
Browse files Browse the repository at this point in the history
  • Loading branch information
pemistahl committed May 30, 2022
1 parent ae953cd commit 1901e6a
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -116,7 +116,7 @@ testing {
if (JavaVersion.current().isJava9Compatible) {
tasks.check {
@Suppress("UnstableApiUsage")
dependsOn(testing.suites.named("testModular"))
dependsOn(testing.suites.named("testJavaModule"))
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/java-9/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
* Copyright © 2018-today Peter M. Stahl [email protected]
*
* 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;

Expand Down
22 changes: 22 additions & 0 deletions src/testJavaModule/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © 2018-today Peter M. Stahl [email protected]
*
* 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;
}
74 changes: 74 additions & 0 deletions src/testJavaModule/java/test/LinguaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright © 2018-today Peter M. Stahl [email protected]
*
* 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<Path> filesList = Files.list(outputDirectoryPath).collect(toList());

assertEquals(5, filesList.size());

inputFilePath.toFile().delete();
}
}
6 changes: 0 additions & 6 deletions src/testModular/java/module-info.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/testModular/java/test/LinguaTest.java

This file was deleted.

0 comments on commit 1901e6a

Please sign in to comment.