caio.co/de/cerberus

Package a test jar with a useable Util class

Id
f1d13de4fd6d2586515d467c45aea7495908c9b3
Author
Caio
Commit time
2019-03-01T12:15:25+01:00

Modified pom.xml

@@ -32,7 +32,9
<chronicle.version>3.17.1</chronicle.version>
<mockito.version>2.24.5</mockito.version>
<reactor.version>Californium-SR5</reactor.version>
+
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
+ <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

<dependencyManagement>
@@ -154,9 +156,26
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>${maven-jar-plugin.version}</version>
+ </plugin>
</plugins>
</pluginManagement>
<plugins>
+ <!-- package a test jar so that casserole can use it -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<!-- flatbuffers start -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>

Modified src/test/java/co/caio/cerberus/Util.java

@@ -1,7 +1,9
package co.caio.cerberus;

import co.caio.cerberus.model.Recipe;
import co.caio.cerberus.search.Indexer;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
@@ -30,11 +32,10
}

public static Stream<Recipe> getSampleRecipes() {
- var samplesFile = Util.class.getResource("/sample_recipes.jsonlines").getFile();
+ var samplesStream = Util.class.getResourceAsStream("/sample_recipes.jsonlines");
+ var reader = new BufferedReader(new InputStreamReader(samplesStream));
try {
- return Files.lines(Path.of(samplesFile))
- .map(serializer::readRecipe)
- .flatMap(Optional::stream);
+ return reader.lines().map(serializer::readRecipe).flatMap(Optional::stream);
} catch (Exception e) {
throw new RuntimeException(e);
}