diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Place.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Place.java index 9a8b5dc7c7..bc418dc1bf 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Place.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Place.java @@ -27,6 +27,7 @@ import java.nio.file.Path; import org.eolang.maven.name.DelimitedName; import org.eolang.maven.name.ObjectName; +import org.eolang.maven.util.JoinedUnderscore; /** * Make the place for the object. @@ -67,8 +68,7 @@ public Path make(final Path dir, final String ext) { out.append(this.name.title().replace(".", File.separator)); this.name.label().ifPresent( version -> { - out.append('_'); - out.append(version); + out.append(new JoinedUnderscore("", version).asString()); }); if (!ext.isEmpty()) { out.append('.').append(ext); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/JoinedUnderscore.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/JoinedUnderscore.java new file mode 100644 index 0000000000..11e107ef70 --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/util/JoinedUnderscore.java @@ -0,0 +1,62 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven.util; + +import java.util.List; +import org.cactoos.Text; +import org.cactoos.list.ListOf; + +/** + * Text joined with underscore. + * + * @since 0.34.1 + */ +public final class JoinedUnderscore implements Text { + + /** + * Strings to join. + */ + private final List strings; + + /** + * Ctor. + * @param strngs Strings to join + */ + public JoinedUnderscore(final String... strngs) { + this(new ListOf<>(strngs)); + } + + /** + * Ctor. + * @param strngs Strings to join + */ + public JoinedUnderscore(final List strngs) { + this.strings = strngs; + } + + @Override + public String asString() { + return String.join("_", this.strings); + } +} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java index ef9c267f98..a4931c2877 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java @@ -36,6 +36,7 @@ import org.eolang.maven.log.Logs; import org.eolang.maven.objectionary.ObjsDefault; import org.eolang.maven.objectionary.OyRemote; +import org.eolang.maven.util.JoinedUnderscore; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; @@ -47,14 +48,6 @@ /** * Test case for {@link AssembleMojo}. * - * @since 0.1 - * @todo #1602:30min Create new object that will join two strings with "_". - * {@link Place} object makes a path for versioned objects using "_" as - * delimiter between name and hash. Here to test stored files after - * {@link AssembleMojo} execution "joinedWithUnderscore" function was - * introduced. So there's a code duplication and an ugly design. Need to - * create a new object that will join two strings with underscore and use it - * here and in {@link Place}. * @todo #1602:30min Make up how to get rid of excessive usage of * {@code ParseMojo.DIR}, {@code ResolveMojo.DIR} and so on. It would be nice * to replace them with corresponding classes, or something similar @@ -68,6 +61,7 @@ * from older repositories are not parsed successfully because of the presence of varargs there. * So we need to make 2-3 releases and then refactor the test with more fresh versions. Don't * forget to remove the puzzle. + * @since 0.1 */ @ExtendWith(WeAreOnline.class) final class AssembleMojoTest { @@ -157,8 +151,8 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { .execute(AssembleMojo.class) .result(); final String stdout = "**/io/stdout"; - final String fifth = AssembleMojoTest.joinedWithUnderscore(stdout, "17f8929.xmir"); - final String sixth = AssembleMojoTest.joinedWithUnderscore(stdout, "9c93528.xmir"); + final String fifth = new JoinedUnderscore(stdout, "17f8929.xmir").asString(); + final String sixth = new JoinedUnderscore(stdout, "9c93528.xmir").asString(); final String path = "target/%s/org/eolang"; final String parse = String.format(path, ParseMojo.DIR); final String optimize = String.format(path, OptimizeMojo.DIR); @@ -167,7 +161,7 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { final String seq = "**/seq.xmir"; final String string = "**/string.xmir"; final String hash = String.join(".", master.value(), "eo"); - final String[] jars = new String[] { + final String[] jars = { "**/eo-runtime-0.28.5.jar", "**/eo-runtime-0.28.6.jar", }; @@ -194,10 +188,10 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { ), result.get(pull).toAbsolutePath(), new ContainsFiles( - AssembleMojoTest.joinedWithUnderscore(stdout, "17f8929.eo"), - AssembleMojoTest.joinedWithUnderscore(stdout, "9c93528.eo"), - AssembleMojoTest.joinedWithUnderscore("**/seq", hash), - AssembleMojoTest.joinedWithUnderscore("**/string", hash) + new JoinedUnderscore(stdout, "17f8929.eo").asString(), + new JoinedUnderscore(stdout, "9c93528.eo").asString(), + new JoinedUnderscore("**/seq", hash).asString(), + new JoinedUnderscore("**/string", hash).asString() ) ); MatcherAssert.assertThat( @@ -272,8 +266,4 @@ void configuresChildParameters(@TempDir final Path temp) throws IOException { ) ); } - - private static String joinedWithUnderscore(final String first, final String second) { - return String.join("_", first, second); - } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java index d03b85d97a..36d1231348 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java @@ -43,6 +43,7 @@ import org.hamcrest.io.FileMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; @@ -112,7 +113,12 @@ void optimizesIfExpired(@TempDir final Path temp) throws Exception { * * @param temp Temporary test directory. * @throws Exception if unexpected error happened. + * @todo #2422:60min This test is unstable for now. + * We should resolve issues with unstable failures and only + * then enable the test. + * Also, see this issue. */ + @Disabled @Test void getsAlreadyOptimizedResultsFromCache(@TempDir final Path temp) throws Exception { final TextOf cached = new TextOf( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java index 97d40790ca..17f684ad45 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java @@ -35,6 +35,7 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.hamcrest.io.FileMatchers; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.xembly.Directives; @@ -44,7 +45,19 @@ * Test case for {@link org.eolang.maven.optimization.OptCached}. * @since 0.28.12 */ -class OptCachedTest { +final class OptCachedTest { + + /** + * Test case for XML program in cache. + * + * @param tmp Temp dir + * @throws IOException if I/O fails + * @todo #2422:60min returnsFromCacheIfXmlAlreadyInCache: this test is unstable. + * We should resolve issues with unstable failures and only + * then enable the test. + * Also, see this issue. + */ + @Disabled @Test void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOException { final XML program = OptCachedTest.program(ZonedDateTime.now()); @@ -78,7 +91,7 @@ void optimizesIfXmlIsAbsentInCache(@TempDir final Path tmp) { } @Test - void optimizesBecauseChacheIsExpired(@TempDir final Path tmp) throws IOException { + void optimizesBecauseCacheIsExpired(@TempDir final Path tmp) throws IOException { final XML outdated = OptCachedTest.program(ZonedDateTime.now().minusMinutes(1)); final XML updated = OptCachedTest.program(ZonedDateTime.now()); OptCachedTest.save(tmp, outdated); diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/util/JoinedUnderscoreTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/util/JoinedUnderscoreTest.java new file mode 100644 index 0000000000..39a27988e7 --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/util/JoinedUnderscoreTest.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven.util; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.core.IsEqual; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link JoinedUnderscore}. + * + * @since 0.34.1 + */ +final class JoinedUnderscoreTest { + + @Test + void readsJoinedString() { + MatcherAssert.assertThat( + "Joined string does not match with expected format", + new JoinedUnderscore("first", "second").asString(), + new IsEqual<>("first_second") + ); + } +}