diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ChTextTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ChTextTest.java index 5aca7cfd69a..3b28a4aad14 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ChTextTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ChTextTest.java @@ -14,7 +14,7 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -31,15 +31,14 @@ final class ChTextTest { /** * Test file path in temp dir. */ - private static Path file; + private Path file; - @BeforeAll - @ExtendWith(MktmpResolver.class) - static void setUp(@Mktmp final Path dir) throws IOException { - ChTextTest.file = dir.resolve("tags.txt"); + @BeforeEach + void setUp(@Mktmp final Path dir) throws IOException { + this.file = dir.resolve("tags.txt"); new Saved( new ResourceOf("org/eolang/maven/commits/tags.txt"), - ChTextTest.file + this.file ).value(); } @@ -72,7 +71,7 @@ void readsCorrectHashByTagFromFile( ) { MatcherAssert.assertThat( "ChText should read the correct hash by tag from the file, but it didn't", - new ChText(ChTextTest.file, tag).value(), + new ChText(this.file, tag).value(), Matchers.equalTo(hash) ); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java index 81a9cd1bf9d..f55feac3ff4 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java @@ -25,32 +25,13 @@ @SuppressWarnings("PMD.TooManyMethods") @ExtendWith(MktmpResolver.class) final class FpDefaultTest { - /** - * Lambda content. - */ - private static final String LAMBDA_CONTENT = "Footprint content"; - - /** - * Target content. - */ - private static final String TARGET_CONTENT = "Target content"; - - /** - * Cache content. - */ - private static final String CACHE_CONTENT = "Cache content"; - - /** - * Snapshot. - */ - private static final String SNAPSHOT = "SNAPSHOT"; @Test void failsIfSourcePathNotExists() { Assertions.assertThrows( IllegalStateException.class, () -> new FpDefault( - src -> FpDefaultTest.LAMBDA_CONTENT, + src -> this.footprintContent(), Paths.get("/file-doesnt-exist"), "", "", @@ -66,7 +47,7 @@ void doesNothingWhenTargetIsOlderThanSource(@Mktmp final Path temp) throws Excep final Path target = FpDefaultTest.existedTarget(temp); FpDefaultTest.makeOlder(target); final Path result = new FpDefault( - src -> FpDefaultTest.LAMBDA_CONTENT, + src -> this.footprintContent(), temp, "1.2.3", "abcdef", @@ -80,7 +61,7 @@ void doesNothingWhenTargetIsOlderThanSource(@Mktmp final Path temp) throws Excep MatcherAssert.assertThat( "The content of target file has not to be changed", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.TARGET_CONTENT) + Matchers.equalTo("Target content") ); } @@ -92,20 +73,20 @@ void updatesOnlyTargetFromSourceIfNoTargetAndCacheIsNotCacheable( final Path target = FpDefaultTest.notExistedTarget(temp); assert Files.notExists(target); new FpDefault( - src -> FpDefaultTest.LAMBDA_CONTENT, + src -> this.footprintContent(), temp, - FpDefaultTest.SNAPSHOT, + "SNAPSHOT", "", Paths.get("cache1.txt") ).apply(source, target); MatcherAssert.assertThat( "Target file must be updated from content function, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); MatcherAssert.assertThat( "Cache file has not to be updated", - temp.resolve(FpDefaultTest.SNAPSHOT).resolve("cache.txt").toFile().exists(), + temp.resolve("SNAPSHOT").resolve("cache.txt").toFile().exists(), Matchers.equalTo(false) ); } @@ -118,20 +99,20 @@ void updatesOnlyTargetFromSourceIfYoungerTargetAndCacheIsNotCacheable( final Path target = FpDefaultTest.existedTarget(temp); FpDefaultTest.makeOlder(source); new FpDefault( - src -> FpDefaultTest.LAMBDA_CONTENT, + src -> this.footprintContent(), temp, - FpDefaultTest.SNAPSHOT, + "SNAPSHOT", "", Paths.get("cache2.txt") ).apply(source, target); MatcherAssert.assertThat( "Target file must be updated from content function, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); MatcherAssert.assertThat( "Cache file has not to be updated", - temp.resolve(FpDefaultTest.SNAPSHOT).resolve("cache.txt").toFile().exists(), + temp.resolve("SNAPSHOT").resolve("cache.txt").toFile().exists(), Matchers.equalTo(false) ); } @@ -149,12 +130,12 @@ void updatesBothIfTargetYoungerAndNotExistedCacheableCache( MatcherAssert.assertThat( "Target content must be updated from lambda, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); MatcherAssert.assertThat( "Cache content must be updated from lambda, but it didn't", new TextOf(cache.path()).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); } @@ -168,12 +149,12 @@ void updatesBothNoTargetAndNotExistedCacheableCache(@Mktmp final Path temp) thro MatcherAssert.assertThat( "Target content must be updated from lambda, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); MatcherAssert.assertThat( "Cache content must be updated from lambda, but it didn't", new TextOf(cache.path()).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); } @@ -190,12 +171,12 @@ void updatesBothIfTargetYoungerAndExistedCacheableCacheIsYounger( MatcherAssert.assertThat( "Target content must be updated from lambda, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); MatcherAssert.assertThat( "Cache content must be updated from lambda, but it didn't", new TextOf(cache.path()).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); } @@ -212,12 +193,12 @@ void updatesBothIfNoTargetAndExistedCacheableCacheIsYounger( MatcherAssert.assertThat( "Target content must be updated from lambda, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); MatcherAssert.assertThat( "Cache content must be updated from lambda, but it didn't", new TextOf(cache.path()).asString(), - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT) + Matchers.equalTo(this.footprintContent()) ); } @@ -234,12 +215,12 @@ void copiesFromCacheIfTargetYoungerAndExistedCacheableCacheOlder( MatcherAssert.assertThat( "Target content must be updated from cache, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.CACHE_CONTENT) + Matchers.equalTo(this.cacheContent()) ); MatcherAssert.assertThat( "Cache content must not be changed, but it did", new TextOf(cache.path()).asString(), - Matchers.equalTo(FpDefaultTest.CACHE_CONTENT) + Matchers.equalTo(this.cacheContent()) ); } @@ -257,12 +238,12 @@ void copiesFromCacheIfNoTaretAndExistedCacheableCacheOlder( MatcherAssert.assertThat( "Target content must be updated from cache, but it didn't", new TextOf(target).asString(), - Matchers.equalTo(FpDefaultTest.CACHE_CONTENT) + Matchers.equalTo(this.cacheContent()) ); MatcherAssert.assertThat( "Cache content must not be changed, but it did", new TextOf(cache.path()).asString(), - Matchers.equalTo(FpDefaultTest.CACHE_CONTENT) + Matchers.equalTo(this.cacheContent()) ); } @@ -275,7 +256,7 @@ void skipsCacheIfItIsNotEnabled(@Mktmp final Path temp) throws Exception { FpDefaultTest.makeOlder(source); FpDefaultTest.makeOlder(cache.path(), 100_000); new FpDefault( - src -> FpDefaultTest.LAMBDA_CONTENT, + src -> this.footprintContent(), cache.base, cache.semver, () -> cache.hash, @@ -286,8 +267,8 @@ void skipsCacheIfItIsNotEnabled(@Mktmp final Path temp) throws Exception { "Global cache must be skipped because of the boolean flag", new TextOf(target).asString(), Matchers.allOf( - Matchers.equalTo(FpDefaultTest.LAMBDA_CONTENT), - Matchers.not(Matchers.equalTo(FpDefaultTest.CACHE_CONTENT)) + Matchers.equalTo(this.footprintContent()), + Matchers.not(Matchers.equalTo(this.cacheContent())) ) ); } @@ -300,7 +281,7 @@ void throwsNpeIfHashIsNull(@Mktmp final Path temp) throws IOException { Assertions.assertThrows( NullPointerException.class, () -> new FpDefault( - src1 -> FpDefaultTest.LAMBDA_CONTENT, + src1 -> this.footprintContent(), cache.base, cache.semver, null, @@ -310,6 +291,20 @@ void throwsNpeIfHashIsNull(@Mktmp final Path temp) throws IOException { ); } + /** + * Returns the cache content. + */ + private String cacheContent() { + return "Cache content"; + } + + /** + * Returns the footprint content. + */ + private String footprintContent() { + return "Footprint content"; + } + /** * Apply default footprint. * @param cache Cache @@ -320,8 +315,9 @@ void throwsNpeIfHashIsNull(@Mktmp final Path temp) throws IOException { private static void defaultFootprint( final Cache cache, final Path source, final Path target ) throws Exception { + final String footprint = "Footprint content"; new FpDefault( - src -> FpDefaultTest.LAMBDA_CONTENT, + src -> footprint, cache.base, cache.semver, cache.hash, @@ -368,7 +364,7 @@ private static Path notExistedSource(final Path temp) { */ private static Path existedTarget(final Path temp) throws IOException { final Path source = FpDefaultTest.notExistedTarget(temp); - return FpDefaultTest.existedFile(source, FpDefaultTest.TARGET_CONTENT); + return FpDefaultTest.existedFile(source, "Target content"); } /** @@ -410,7 +406,7 @@ private static void makeOlder(final Path file, final long time) throws IOExcepti */ private static Cache existedCache(final Path temp) throws IOException { final Cache cache = FpDefaultTest.notExistedCache(temp); - FpDefaultTest.existedFile(cache.path(), FpDefaultTest.CACHE_CONTENT); + FpDefaultTest.existedFile(cache.path(), "Cache content"); return cache; } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/MjPlaceTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/MjPlaceTest.java index d76a5ff5345..6d041d4178d 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/MjPlaceTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/MjPlaceTest.java @@ -26,16 +26,6 @@ @ExtendWith(MktmpResolver.class) final class MjPlaceTest { - /** - * The default folder for placed binaries. - */ - private static final String TARGET_CLASSES = "target/classes"; - - /** - * Test library for all binaries. - */ - private static final String LIBRARY = "foo/hello/-/0.1"; - @Test void placesBinaries(@Mktmp final Path temp) throws Exception { MjPlaceTest.saveBinary(temp, "EObar/x.bin"); @@ -67,13 +57,13 @@ void skipsAlreadyPlacedBinaries(@Mktmp final Path temp) throws IOException { "PlaceMojo must skip already placed binaries, but it doesn't", new FakeMaven(temp) .withPlacedBinary( - temp.resolve(MjPlaceTest.TARGET_CLASSES).resolve(binary) + temp.resolve(this.targetClasses()).resolve(binary) ) - .execute(MjPlace.class) - .result() - .get("target/classes/org/eolang/f/x.a.class") - .toFile() - .lastModified(), + .execute(MjPlace.class) + .result() + .get("target/classes/org/eolang/f/x.a.class") + .toFile() + .lastModified(), Matchers.equalTo(before) ); } @@ -105,12 +95,12 @@ void placesWithoutBinaries(@Mktmp final Path temp) throws IOException { MatcherAssert.assertThat( String.format( "PlaceMojo must not place binaries from %s", - MjPlaceTest.TARGET_CLASSES + this.targetClasses() ), new FakeMaven(temp) .execute(MjPlace.class) .result(), - Matchers.not(Matchers.hasKey(MjPlaceTest.TARGET_CLASSES)) + Matchers.not(Matchers.hasKey(this.targetClasses())) ); } @@ -123,7 +113,7 @@ void placesDefaultJnaBinaries(@Mktmp final Path temp) throws Exception { .with("ignoreRuntime", true) .execute(new FakeMaven.Place()) .result() - .get(MjPlaceTest.TARGET_CLASSES), + .get(this.targetClasses()), new ContainsFiles("**/jna-*.class") ); } @@ -137,12 +127,12 @@ void placesWithoutResolveDirectory(@Mktmp final Path temp) throws IOException { "PlaceMojo must not place binaries from %s", "if the resolve directory does not exist" ), - MjPlaceTest.TARGET_CLASSES + this.targetClasses() ), new FakeMaven(temp) .execute(MjPlace.class) .result(), - Matchers.not(Matchers.hasKey(MjPlaceTest.TARGET_CLASSES)) + Matchers.not(Matchers.hasKey(this.targetClasses())) ); } @@ -182,7 +172,7 @@ void placesAllEoRuntimeClasses(@Mktmp final Path temp) throws IOException { .with("resolveJna", false) .execute(new FakeMaven.Place()) .result() - .get(MjPlaceTest.TARGET_CLASSES), + .get(this.targetClasses()), new ContainsFiles("**/eo-runtime-*.class") ); MatcherAssert.assertThat( @@ -202,7 +192,7 @@ void placesWithoutEoRuntimeClasses(@Mktmp final Path temp) throws IOException { .with("resolveJna", false) .execute(new FakeMaven.Place()) .result() - .get(MjPlaceTest.TARGET_CLASSES), + .get(this.targetClasses()), Matchers.not(new ContainsFiles("**/eo-runtime-*.class")) ); } @@ -240,11 +230,18 @@ void placesAgainIfWasUnplaced(@Mktmp final Path temp) throws Exception { ); } + /** + * Returns the target classes. + */ + private String targetClasses() { + return "target/classes"; + } + /** * Save binary to {@link MjResolve#DIR} folder. * The method emulates the situation when we have some resolved binaries. * - * @param temp Temp test directory. + * @param temp Temp test directory. * @param binary Binary name. * @throws IOException In case of error. */ @@ -256,9 +253,9 @@ private static void saveBinary(final Path temp, final String binary) throws IOEx * Save binary to {@link MjResolve#DIR} folder. * The method emulates the situation when we have some resolved binaries. * - * @param temp Temp test directory. + * @param temp Temp test directory. * @param content Content of the binary. - * @param binary Binary name. + * @param binary Binary name. * @throws IOException In case of error. */ private static void saveBinary( @@ -269,7 +266,7 @@ private static void saveBinary( new Saved( content, temp.resolve("target").resolve(MjResolve.DIR).resolve( - Paths.get(String.format("%s/%s", MjPlaceTest.LIBRARY, binary)) + Paths.get(String.format("%s/%s", "foo/hello/-/0.1", binary)) ) ).value(); } @@ -278,7 +275,7 @@ private static void saveBinary( * Save binary to classes folder. * The method emulates the situation when we already have some placed binaries. * - * @param temp Temp test directory. + * @param temp Temp test directory. * @param binary Binary name. * @throws IOException In case of error. */ @@ -293,9 +290,9 @@ private static void saveAlreadyPlacedBinary( * Save binary to classes folder. * The method emulates the situation when we already have some placed binaries. * - * @param temp Temp test directory. + * @param temp Temp test directory. * @param content Content of the binary. - * @param binary Binary name. + * @param binary Binary name. * @throws IOException In case of error. */ private static void saveAlreadyPlacedBinary( @@ -303,19 +300,21 @@ private static void saveAlreadyPlacedBinary( final String content, final String binary ) throws IOException { + final String targets = "target/classes"; new Saved( content, - temp.resolve(MjPlaceTest.TARGET_CLASSES).resolve(binary) + temp.resolve(targets).resolve(binary) ).value(); } /** * Path to the placed binary. - * @param temp Temp test directory + * + * @param temp Temp test directory * @param binary Binary name. * @return Path to the placed binary. */ private static Path pathToPlacedBinary(final Path temp, final String binary) { - return temp.resolve(MjPlaceTest.TARGET_CLASSES).resolve(binary); + return temp.resolve("target/classes").resolve(binary); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/MjPullTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/MjPullTest.java index 7a94ef5dfc1..6ada1f15e27 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/MjPullTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/MjPullTest.java @@ -33,21 +33,17 @@ @ExtendWith(WeAreOnline.class) @ExtendWith(MktmpResolver.class) final class MjPullTest { - /** - * Stdout. - */ - private static final String STDOUT = "org.eolang.io.stdout"; @Test void pullsSuccessfully(@Mktmp final Path temp) throws IOException { final FakeMaven maven = new FakeMaven(temp); maven.foreignTojos() - .add(MjPullTest.STDOUT) + .add(this.stdout()) .withVersion("*.*.*"); maven.with("skip", false).execute(MjPull.class); MatcherAssert.assertThat( "PullMojo should have pulled stdout object, but didn't", - MjPullTest.exists(temp, MjPullTest.STDOUT), + MjPullTest.exists(temp, this.stdout()), Matchers.is(true) ); } @@ -66,7 +62,7 @@ void pullsFromProbes(@Mktmp final Path temp) throws IOException { .execute(new FakeMaven.Pull()); MatcherAssert.assertThat( "PullMojo should have pulled from probes, but it didn't", - MjPullTest.exists(temp, MjPullTest.STDOUT), + MjPullTest.exists(temp, this.stdout()), Matchers.is(true) ); } @@ -79,7 +75,7 @@ void pullsUsingOfflineHashFile(@Mktmp final Path temp) throws IOException { ).value(); final FakeMaven maven = new FakeMaven(temp); maven.foreignTojos() - .add(MjPullTest.STDOUT) + .add(this.stdout()) .withVersion("*.*.*"); maven.with("skip", false) .with( @@ -98,7 +94,7 @@ void pullsUsingOfflineHashFile(@Mktmp final Path temp) throws IOException { void pullsUsingOfflineHash(@Mktmp final Path temp) throws IOException { final FakeMaven maven = new FakeMaven(temp); maven.foreignTojos() - .add(MjPullTest.STDOUT) + .add(this.stdout()) .withVersion("*.*.*"); maven.with("skip", false) .with( @@ -117,14 +113,14 @@ void pullsUsingOfflineHash(@Mktmp final Path temp) throws IOException { void skipsPullMojo(@Mktmp final Path temp) throws IOException { final FakeMaven maven = new FakeMaven(temp); maven.foreignTojos() - .add(MjPullTest.STDOUT) + .add(this.stdout()) .withScope("compile") .withVersion("*.*.*"); maven.with("skip", true) .execute(MjPull.class); MatcherAssert.assertThat( "PullMojo must skip pulling, but it doesn't", - MjPullTest.exists(temp, MjPullTest.STDOUT), + MjPullTest.exists(temp, this.stdout()), Matchers.is(false) ); } @@ -242,6 +238,13 @@ void getsAlreadyPulledResultsFromCache(@Mktmp final Path temp) throws Exception ); } + /** + * Returns the stdout path. + */ + private String stdout() { + return "org.eolang.io.stdout"; + } + /** * Check if the given source file exists in the target directory. * diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/MjRegisterTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/MjRegisterTest.java index 4081e1facb2..f447d5b529d 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/MjRegisterTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/MjRegisterTest.java @@ -22,15 +22,6 @@ */ @ExtendWith(MktmpResolver.class) final class MjRegisterTest { - /** - * Parameter for source directory. - */ - private static final String PARAM = "sourcesDir"; - - /** - * Source directory. - */ - private static final String SOURCES = "src/eo"; @Test void registersOkNames(@Mktmp final Path temp) throws IOException { @@ -39,7 +30,7 @@ void registersOkNames(@Mktmp final Path temp) throws IOException { temp.resolve("src/eo/org/eolang/maven/abc-def.eo") ).value(); final FakeMaven maven = new FakeMaven(temp) - .with(MjRegisterTest.PARAM, temp.resolve(MjRegisterTest.SOURCES).toFile()) + .with("sourcesDir", temp.resolve("src/eo").toFile()) .execute(new FakeMaven.Register()); MatcherAssert.assertThat( "The resource must exist, but it doesn't", @@ -55,7 +46,7 @@ void doesNotFailWhenNoStrictNames(@Mktmp final Path temp) throws IOException { temp.resolve("src/eo/org/eolang/maven/.abc.eo") ).value(); final FakeMaven maven = new FakeMaven(temp) - .with(MjRegisterTest.PARAM, temp.resolve(MjRegisterTest.SOURCES).toFile()) + .with("sourcesDir", temp.resolve("src/eo").toFile()) .with("strictFileNames", false) .execute(new FakeMaven.Register()); MatcherAssert.assertThat( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/MjResolveTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/MjResolveTest.java index f7870288862..2ea228727bc 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/MjResolveTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/MjResolveTest.java @@ -28,16 +28,6 @@ @SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"}) final class MjResolveTest { - /** - * The message that the .class file must exist. - */ - private static final String CLASS_MUST_EXIST = "The class file must exist, but it doesn't"; - - /** - * The message that the .class file must not exist. - */ - private static final String CLASS_NOT_EXIST = "The class file must not exist, but it doesn't"; - @Test void resolvesWithSingleDependency(@Mktmp final Path temp) throws IOException { new FakeMaven(temp) @@ -58,7 +48,7 @@ void resolvesWithSingleDependency(@Mktmp final Path temp) throws IOException { FileMatchers.anExistingDirectory() ); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", path.resolve("eo-runtime-0.7.0.class").toFile(), FileMatchers.anExistingFile() ); @@ -99,7 +89,7 @@ void resolvesWithoutAnyDependencies(@Mktmp final Path temp) throws IOException { FileMatchers.anExistingDirectory() ); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", path, new ContainsFiles("**/eo-runtime-*.class") ); @@ -110,7 +100,7 @@ void resolvesWithEoRuntimeDependency(@Mktmp final Path temp) throws IOException final FakeMaven maven = new FakeMaven(temp); maven.withHelloWorld().execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", maven.targetPath(), new ContainsFiles("**/eo-runtime-*.class") ); @@ -123,7 +113,7 @@ void resolvesWithoutEoRuntimeDependency(@Mktmp final Path temp) throws IOExcepti .with("ignoreRuntime", true) .execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_NOT_EXIST, + "The class file must not exist, but it doesn't", maven.targetPath(), Matchers.not(new ContainsFiles("**/eo-runtime-*.class")) ); @@ -140,7 +130,7 @@ void resolvesIfRuntimeDependencyComesFromTojos(@Mktmp final Path temp) throws IO "[] > main" ).execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", maven.targetPath(), new ContainsFiles("**/eo-runtime-0.22.1.class") ); @@ -157,7 +147,7 @@ void resolvesIfRuntimeDependencyComesFromTojosButParamIsFalse(@Mktmp final Path "[] > main" ).with("ignoreRuntime", true).execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_NOT_EXIST, + "The class file must not exist, but it doesn't", maven.targetPath(), Matchers.not(new ContainsFiles("**/eo-runtime-*.class")) ); @@ -176,7 +166,7 @@ void resolvesWithRuntimeDependencyFromPom(@Mktmp final Path temp) throws IOExcep .with("project", project) .execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", maven.targetPath(), new ContainsFiles("**/eo-runtime-0.7.0.class") ); @@ -193,7 +183,7 @@ void resolvesWithoutTransitiveDependencies(@Mktmp final Path temp) throws IOExce ) .execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", maven.targetPath(), new ContainsFiles("**/eo-runtime-*.class") ); @@ -277,7 +267,7 @@ void resolvesWithConflictingDependenciesNoFail(@Mktmp final Path temp) throws IO maven.with("ignoreVersionConflicts", true) .execute(new FakeMaven.Resolve()); MatcherAssert.assertThat( - MjResolveTest.CLASS_MUST_EXIST, + "The class file must exist, but it doesn't", maven.targetPath(), new ContainsFiles("**/eo-runtime-*.class") ); diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/OyIndexedTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OyIndexedTest.java index 1ee7235953f..71d0079b3de 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/OyIndexedTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/OyIndexedTest.java @@ -20,11 +20,6 @@ */ final class OyIndexedTest { - /** - * Object name for stdout. - */ - private static final String STDOUT_OBJECT = "org.eolang.io.stdout"; - @Test void getsFromDelegate() throws Exception { MatcherAssert.assertThat( @@ -41,7 +36,7 @@ void getsFromDelegate() throws Exception { void containsInRealIndex() throws IOException { MatcherAssert.assertThat( "OyIndexed must contain stdout object, but it doesn't", - new OyIndexed(new Objectionary.Fake()).contains(OyIndexedTest.STDOUT_OBJECT), + new OyIndexed(new Objectionary.Fake()).contains(this.stdout()), Matchers.is(true) ); } @@ -52,8 +47,8 @@ void containsInFakeIndex() throws IOException { "OyIndexed with fake index must contain stdout object, but it doesn't", new OyIndexed( new Objectionary.Fake(), - new ObjectsIndex(() -> Collections.singleton(OyIndexedTest.STDOUT_OBJECT)) - ).contains(OyIndexedTest.STDOUT_OBJECT), + new ObjectsIndex(() -> Collections.singleton(this.stdout())) + ).contains(this.stdout()), Matchers.is(true) ); } @@ -69,7 +64,7 @@ void checksContainsInDelegateIfExceptionHappensInIndex() throws IOException { throw new IllegalStateException("Fake exception"); } ) - ).contains(OyIndexedTest.STDOUT_OBJECT), + ).contains(this.stdout()), Matchers.is(true) ); } @@ -79,7 +74,7 @@ void checksContainsInDelegateIfExceptionHappensInIndex() throws IOException { void checksIsDirectoryForObject() throws IOException { MatcherAssert.assertThat( "OyIndexed must contain stdout object, but it doesn't", - new OyIndexed(new Objectionary.Fake()).isDirectory(OyIndexedTest.STDOUT_OBJECT), + new OyIndexed(new Objectionary.Fake()).isDirectory(this.stdout()), Matchers.is(false) ); } @@ -93,4 +88,11 @@ void checksIsDirectoryForDirectory() throws IOException { Matchers.is(false) ); } + + /** + * Returns the stdout path. + */ + private String stdout() { + return "org.eolang.io.stdout"; + } } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnk/EOsocketTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnk/EOsocketTest.java index 9b86619647b..be04edf7438 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnk/EOsocketTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnk/EOsocketTest.java @@ -54,22 +54,13 @@ "JTCOP.RuleAllTestsHaveProductionClass" }) final class EOsocketTest { - /** - * Localhost IP. - */ - private static final String LOCALHOST = "127.0.0.1"; - - /** - * Random. - */ - private static final Random RANDOM = new Random(); @Test void connectsToLocalServerViaSocketObject() throws IOException { final RandomServer server = new RandomServer().started(); try { final Phi socket = Phi.Φ.take("org.eolang.nk.socket").copy(); - socket.put(0, new Data.ToPhi(EOsocketTest.LOCALHOST)); + socket.put(0, new Data.ToPhi(this.localhost())); socket.put(1, new Data.ToPhi(server.port)); final Phi connected = socket.take("connect").copy(); connected.put(0, new Simple()); @@ -98,7 +89,7 @@ void sendsAndReceivesMessageViaSocketObject() throws InterruptedException, IOExc final Thread server = new Thread( () -> { final Phi socket = Phi.Φ.take("org.eolang.nk.socket").copy(); - socket.put(0, new Data.ToPhi(EOsocketTest.LOCALHOST)); + socket.put(0, new Data.ToPhi(this.localhost())); socket.put(1, new Data.ToPhi(port)); final Phi listened = socket.take("listen").copy(); listened.put(0, new Server(msg.length())); @@ -108,7 +99,7 @@ void sendsAndReceivesMessageViaSocketObject() throws InterruptedException, IOExc server.start(); Thread.sleep(2000); final Phi socket = Phi.Φ.take("org.eolang.nk.socket").copy(); - socket.put(0, new Data.ToPhi(EOsocketTest.LOCALHOST)); + socket.put(0, new Data.ToPhi(this.localhost())); socket.put(1, new Data.ToPhi(port)); final Phi connected = socket.take("connect").copy(); connected.put(0, new Client(msg)); @@ -126,6 +117,13 @@ void sendsAndReceivesMessageViaSocketObject() throws InterruptedException, IOExc ); } + /** + * Returns the localhost address. + */ + private String localhost() { + return "127.0.0.1"; + } + /** * Convert port number from host to network byte order (htons). * @param port Port number @@ -142,7 +140,7 @@ private static short htons(final int port) { private static int randomPort() { final int min = 10_000; final int max = 20_000; - return EOsocketTest.RANDOM.nextInt((max - min) + 1) + min; + return new Random().nextInt((max - min) + 1) + min; } /** @@ -500,7 +498,7 @@ private SockaddrIn sockaddr(final int port) throws UnknownHostException { return new SockaddrIn( (short) Winsock.AF_INET, EOsocketTest.htons(port), - this.inetAddr(EOsocketTest.LOCALHOST) + this.inetAddr("127.0.0.1") ); } } @@ -793,7 +791,7 @@ private SockaddrIn sockaddr(final int port) { return new SockaddrIn( (short) CStdLib.AF_INET, EOsocketTest.htons(port), - this.inetAddr(EOsocketTest.LOCALHOST) + this.inetAddr("127.0.0.1") ); } } @@ -824,7 +822,7 @@ RandomServer started() { try { this.socket = new ServerSocket(); this.socket.setReuseAddress(true); - this.socket.bind(new InetSocketAddress(EOsocketTest.LOCALHOST, this.port)); + this.socket.bind(new InetSocketAddress("127.0.0.1", this.port)); bound = true; Logger.debug(this, "Server started on port %d", this.port); } catch (final IOException exception) { diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/HeapsTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/HeapsTest.java index f6b92c81a77..ad53010d051 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/HeapsTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/HeapsTest.java @@ -27,62 +27,58 @@ */ @SuppressWarnings("PMD.TooManyMethods") final class HeapsTest { - /** - * Heaps. - */ - private static final Heaps HEAPS = Heaps.INSTANCE; @Test void allocatesMemory() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 10); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 10); Assertions.assertDoesNotThrow( - () -> HeapsTest.HEAPS.read(idx, 0, 10), + () -> Heaps.INSTANCE.read(idx, 0, 10), "Heaps should successfully read from allocated memory, but it didn't" ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void failsOnDoubleAllocation() { final Phi phi = new HeapsTest.PhFake(); - final int idx = HeapsTest.HEAPS.malloc(phi, 10); + final int idx = Heaps.INSTANCE.malloc(phi, 10); Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.malloc(phi, 10), + () -> Heaps.INSTANCE.malloc(phi, 10), "Heaps should throw an exception on attempting to allocate already allocated memory, but it didn't" ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void allocatesAndReadsEmptyBytes() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); MatcherAssert.assertThat( "Heaps should return empty bytes after memory allocation, but it didn't", - HeapsTest.HEAPS.read(idx, 0, 5), + Heaps.INSTANCE.read(idx, 0, 5), Matchers.equalTo(new byte[] {0, 0, 0, 0, 0}) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void writesAndReads() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); final byte[] bytes = {1, 2, 3, 4, 5}; - HeapsTest.HEAPS.write(idx, 0, bytes); + Heaps.INSTANCE.write(idx, 0, bytes); MatcherAssert.assertThat( "Heaps should successfully read exactly same bytes that were written, but it didn't", - HeapsTest.HEAPS.read(idx, 0, bytes.length), + Heaps.INSTANCE.read(idx, 0, bytes.length), Matchers.equalTo(bytes) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void failsOnWriteToEmptyBlock() { Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.write(new HeapsTest.PhFake().hashCode(), 0, new byte[] {0x01}), + () -> Heaps.INSTANCE.write(new HeapsTest.PhFake().hashCode(), 0, new byte[] {0x01}), "Heaps should throw an exception on writing to an unallocated block, but it didn't" ); } @@ -91,76 +87,76 @@ void failsOnWriteToEmptyBlock() { void failsOnReadFromEmptyBlock() { Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.read(new HeapsTest.PhFake().hashCode(), 0, 1), + () -> Heaps.INSTANCE.read(new HeapsTest.PhFake().hashCode(), 0, 1), "Heaps should throw an exception on reading from an unallocated block, but it didn't" ); } @Test void failsOnReadIfOutOfBounds() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 2); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 2); Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.read(idx, 1, 3), + () -> Heaps.INSTANCE.read(idx, 1, 3), "Heaps should throw an exception on out-of-bounds read, but it didn't" ); } @Test void readsByOffsetAndLength() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); - HeapsTest.HEAPS.write(idx, 0, new byte[] {1, 2, 3, 4, 5}); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); + Heaps.INSTANCE.write(idx, 0, new byte[] {1, 2, 3, 4, 5}); MatcherAssert.assertThat( "Heaps should successfully read correct slice when reading with offset and length, but it didn't", - HeapsTest.HEAPS.read(idx, 1, 3), + Heaps.INSTANCE.read(idx, 1, 3), Matchers.equalTo(new byte[] {2, 3, 4}) ); } @Test void failsOnWriteMoreThanAllocated() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 2); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 2); final byte[] bytes = {1, 2, 3, 4, 5}; Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.write(idx, 0, bytes), + () -> Heaps.INSTANCE.write(idx, 0, bytes), "Heaps should throw an exception on writing more bytes than allocated size, but it didn't" ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void failsToWriteMoreThanAllocatedWithOffset() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 3); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 3); final byte[] bytes = {1, 2, 3}; Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.write(idx, 1, bytes), + () -> Heaps.INSTANCE.write(idx, 1, bytes), "Heaps should throw an exception on writing past allocated block using offset, but it didn't" ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void concatsOnWriteLessThanAllocated() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); - HeapsTest.HEAPS.write(idx, 0, new byte[] {1, 1, 3, 4, 5}); - HeapsTest.HEAPS.write(idx, 2, new byte[] {2, 2}); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); + Heaps.INSTANCE.write(idx, 0, new byte[] {1, 1, 3, 4, 5}); + Heaps.INSTANCE.write(idx, 2, new byte[] {2, 2}); MatcherAssert.assertThat( "Heaps should return correct bytes after partial overwrite, but it didn't", - HeapsTest.HEAPS.read(idx, 0, 5), + Heaps.INSTANCE.read(idx, 0, 5), Matchers.equalTo(new byte[] {1, 1, 2, 2, 5}) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void freesSuccessfully() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); - HeapsTest.HEAPS.free(idx); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); + Heaps.INSTANCE.free(idx); Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.read(idx, 0, 5), + () -> Heaps.INSTANCE.read(idx, 0, 5), "Heaps should throw an exception on reading from a freed block, but it didn't" ); } @@ -169,7 +165,7 @@ void freesSuccessfully() { void failsOnClearingEmptyBlock() { Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.free(new HeapsTest.PhFake().hashCode()), + () -> Heaps.INSTANCE.free(new HeapsTest.PhFake().hashCode()), "Heaps should throw an exception on attempting to free a non-existent block, but it didn't" ); } @@ -178,82 +174,82 @@ void failsOnClearingEmptyBlock() { void throwsOnGettingSizeOfEmptyBlock() { Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.size(new HeapsTest.PhFake().hashCode()), + () -> Heaps.INSTANCE.size(new HeapsTest.PhFake().hashCode()), "Heaps should throw an exception on trying to get size of an empty block, but it didn't" ); } @Test void returnsValidSize() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); MatcherAssert.assertThat( "Heaps should return valid size of allocated block, but it didn't", - HeapsTest.HEAPS.size(idx), + Heaps.INSTANCE.size(idx), Matchers.equalTo(5) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void throwsOnChangingSizeToNegative() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.resize(idx, -1), + () -> Heaps.INSTANCE.resize(idx, -1), "Heaps should throw an exception on trying to changing size to negative, but it didn't" ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void throwsOnChangeSizeOfEmtpyBlock() { Assertions.assertThrows( ExFailure.class, - () -> HeapsTest.HEAPS.resize(new HeapsTest.PhFake().hashCode(), 10), + () -> Heaps.INSTANCE.resize(new HeapsTest.PhFake().hashCode(), 10), "Heaps should throw an exception on changing size of empty block, but it didn't" ); } @Test void increasesSizeSuccessfully() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); final byte[] bytes = {1, 2, 3, 4, 5}; - HeapsTest.HEAPS.write(idx, 0, bytes); - HeapsTest.HEAPS.resize(idx, 7); + Heaps.INSTANCE.write(idx, 0, bytes); + Heaps.INSTANCE.resize(idx, 7); MatcherAssert.assertThat( "Heaps should successfully increase size of allocated block, but it didn't", - HeapsTest.HEAPS.read(idx, 0, 7), + Heaps.INSTANCE.read(idx, 0, 7), Matchers.equalTo(new byte[] {1, 2, 3, 4, 5, 0, 0}) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void decreasesSizeSuccessfully() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); final byte[] bytes = {1, 2, 3, 4, 5}; - HeapsTest.HEAPS.write(idx, 0, bytes); - HeapsTest.HEAPS.resize(idx, 3); + Heaps.INSTANCE.write(idx, 0, bytes); + Heaps.INSTANCE.resize(idx, 3); MatcherAssert.assertThat( "Heaps should successfully decrease size of allocated block, but it didn't", - HeapsTest.HEAPS.read(idx, 0, 3), + Heaps.INSTANCE.read(idx, 0, 3), Matchers.equalTo(new byte[] {1, 2, 3}) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } @Test void returnsValidSizeAfterDecreasing() { - final int idx = HeapsTest.HEAPS.malloc(new HeapsTest.PhFake(), 5); + final int idx = Heaps.INSTANCE.malloc(new HeapsTest.PhFake(), 5); final byte[] bytes = {1, 2, 3, 4, 5}; - HeapsTest.HEAPS.write(idx, 0, bytes); - HeapsTest.HEAPS.resize(idx, 3); + Heaps.INSTANCE.write(idx, 0, bytes); + Heaps.INSTANCE.resize(idx, 3); MatcherAssert.assertThat( "Heaps should return valid size after decreasing, but it didn't", - HeapsTest.HEAPS.size(idx), + Heaps.INSTANCE.size(idx), Matchers.equalTo(3) ); - HeapsTest.HEAPS.free(idx); + Heaps.INSTANCE.free(idx); } /** diff --git a/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java b/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java index f8e68cfb27d..f47c23c141a 100644 --- a/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java @@ -19,17 +19,6 @@ */ @SuppressWarnings({"PMD.TooManyMethods", "PMD.GodClass"}) final class PhDefaultTest { - /** - * Name of attribute. - * @since 0.1 - */ - private static final String PLUS_ATT = "plus"; - - /** - * Name of attribute. - * @since 0.1 - */ - private static final String VOID_ATT = "void"; @Test void comparesTwoObjects() { @@ -70,7 +59,7 @@ void doesNotHaveRhoWhenFormed() { @Test void setsRhoAfterDispatch() { - final Phi kid = new PhDefaultTest.Int().take(PhDefaultTest.PLUS_ATT); + final Phi kid = new PhDefaultTest.Int().take(this.plus()); Assertions.assertDoesNotThrow( () -> kid.take(Phi.RHO), String.format("Kid of should have %s attribute after dispatch", Phi.RHO) @@ -90,8 +79,8 @@ void doesNotHaveRhoAfterCopying() { @Test void copiesKid() { final Phi phi = new PhDefaultTest.Int(); - final Phi first = phi.take(PhDefaultTest.PLUS_ATT); - final Phi second = phi.copy().take(PhDefaultTest.PLUS_ATT); + final Phi first = phi.take(this.plus()); + final Phi second = phi.copy().take(this.plus()); MatcherAssert.assertThat( "Child attributes should be copied after copying main object", first, @@ -106,9 +95,9 @@ void takesDifferentAbstractKidsEveryDispatch() { final Phi phi = new PhDefaultTest.Int(); MatcherAssert.assertThat( "Child attributes should be copied on every dispatch", - phi.take(PhDefaultTest.PLUS_ATT), + phi.take(this.plus()), Matchers.not( - Matchers.equalTo(phi.take(PhDefaultTest.PLUS_ATT)) + Matchers.equalTo(phi.take(this.plus())) ) ); } @@ -116,7 +105,7 @@ void takesDifferentAbstractKidsEveryDispatch() { @Test void hasKidWithSetRhoAfterCopying() { final Phi phi = new PhDefaultTest.Int().copy(); - final Phi plus = phi.take(PhDefaultTest.PLUS_ATT); + final Phi plus = phi.take(this.plus()); Assertions.assertDoesNotThrow( () -> plus.take(Phi.RHO), String.format( @@ -141,9 +130,9 @@ void hasDifferentKidsAfterDoubleCopying() { final Phi second = first.copy(); MatcherAssert.assertThat( "Child objects after double copying should be different", - first.take(PhDefaultTest.PLUS_ATT), + first.take(this.plus()), Matchers.not( - Matchers.equalTo(second.take(PhDefaultTest.PLUS_ATT)) + Matchers.equalTo(second.take(this.plus())) ) ); } @@ -156,15 +145,15 @@ void changesKidRhoAfterSelfCopying() { String.format( "%s attribute of original object kid should refer to original object", Phi.RHO ), - phi.take(PhDefaultTest.PLUS_ATT).take(Phi.RHO), - Matchers.not(Matchers.equalTo(copy.take(PhDefaultTest.PLUS_ATT).take(Phi.RHO))) + phi.take(this.plus()).take(Phi.RHO), + Matchers.not(Matchers.equalTo(copy.take(this.plus()).take(Phi.RHO))) ); MatcherAssert.assertThat( String.format( "%s attribute of copied object kid should refer to copied object", Phi.RHO ), - copy.take(PhDefaultTest.PLUS_ATT).take(Phi.RHO), + copy.take(this.plus()).take(Phi.RHO), Matchers.equalTo(copy) ); } @@ -172,7 +161,7 @@ void changesKidRhoAfterSelfCopying() { @Test void doesNotChangeRhoAfterDirectKidCopying() { final Phi phi = new PhDefaultTest.Int(); - final Phi first = phi.take(PhDefaultTest.PLUS_ATT); + final Phi first = phi.take(this.plus()); final Phi second = first.copy(); MatcherAssert.assertThat( String.format( @@ -189,7 +178,7 @@ void doesNotChangeRhoAfterDirectKidCopying() { @Test void doesNotCopyRhoWhileDispatch() { final Phi phi = new PhDefaultTest.Int(); - final Phi plus = phi.take(PhDefaultTest.PLUS_ATT); + final Phi plus = phi.take(this.plus()); MatcherAssert.assertThat( String.format("%s attributes should not be copied while dispatch", Phi.RHO), plus.take(Phi.RHO), @@ -203,7 +192,7 @@ void copiesUnsetVoidAttribute() { final Phi copy = phi.copy(); Assertions.assertThrows( ExAbstract.class, - () -> copy.take(PhDefaultTest.VOID_ATT), + () -> copy.take(this.getVoid()), "Unset void attribute should be copied with unset value" ); } @@ -211,13 +200,13 @@ void copiesUnsetVoidAttribute() { @Test void copiesSetVoidAttributeOnCopy() { final Phi phi = new PhDefaultTest.Int(); - phi.put(PhDefaultTest.VOID_ATT, new Data.ToPhi(10L)); + phi.put(this.getVoid(), new Data.ToPhi(10L)); final Phi copy = phi.copy(); MatcherAssert.assertThat( "Copied set void attribute should be different from original one", - phi.take(PhDefaultTest.VOID_ATT), + phi.take(this.getVoid()), Matchers.not( - Matchers.equalTo(copy.take(PhDefaultTest.VOID_ATT)) + Matchers.equalTo(copy.take(this.getVoid())) ) ); } @@ -225,11 +214,11 @@ void copiesSetVoidAttributeOnCopy() { @Test void doesNotCopySetVoidAttributeWithRho() { final Phi phi = new PhDefaultTest.Int(); - phi.put(PhDefaultTest.VOID_ATT, new Data.ToPhi(10L)); + phi.put(this.getVoid(), new Data.ToPhi(10L)); MatcherAssert.assertThat( "Void attribute should not be copied with rho, but it did", - phi.take(PhDefaultTest.VOID_ATT), - Matchers.equalTo(phi.take(PhDefaultTest.VOID_ATT)) + phi.take(this.getVoid()), + Matchers.equalTo(phi.take(this.getVoid())) ); } @@ -251,7 +240,7 @@ void hasAccessToDependentOnContextAttribute() { () -> phi.take(Phi.PHI), "Phi should not be accessible without setting void attribute, but it did" ); - phi.put(PhDefaultTest.VOID_ATT, new Data.ToPhi(10L)); + phi.put(this.getVoid(), new Data.ToPhi(10L)); Assertions.assertDoesNotThrow( () -> phi.take(Phi.PHI), "Phi should be accessible after setting void attribute, but it didn't" @@ -412,7 +401,7 @@ void hasDifferentFormaWithBoundedMethod() { Matchers.not( Matchers.equalTo( new PhWith( - five.take(PhDefaultTest.PLUS_ATT).copy(), + five.take(this.plus()).copy(), "x", new Data.ToPhi(5) ).forma() @@ -426,13 +415,13 @@ void hasTheSameFormaWithDifferentInstances() { MatcherAssert.assertThat( "Similar Phis with different data should have the same forma, but they didn't", new PhWith( - new Data.ToPhi(5L).take(PhDefaultTest.PLUS_ATT).copy(), + new Data.ToPhi(5L).take(this.plus()).copy(), "x", new Data.ToPhi(5L) ).forma(), Matchers.equalTo( new PhWith( - new Data.ToPhi(6L).take(PhDefaultTest.PLUS_ATT).copy(), + new Data.ToPhi(6L).take(this.plus()).copy(), "x", new Data.ToPhi(6L) ).forma() @@ -457,11 +446,11 @@ void doesNotCalculateRandomTwice() { new PhMethod( new PhWith( new PhMethod( - new Rnd(), PhDefaultTest.PLUS_ATT + new Rnd(), this.plus() ), 0, new Data.ToPhi(1.2) ), - PhDefaultTest.PLUS_ATT + this.plus() ), 0, new Data.ToPhi(1.2) ); @@ -574,6 +563,20 @@ private Phi phiWithContextAttribute(final String attribute) { return phi; } + /** + * Returns the 'plus' literal. + */ + private String plus() { + return "plus"; + } + + /** + * Returns the 'void' literal. + */ + private String getVoid() { + return "void"; + } + @SuppressWarnings("PMD.AvoidAccessibilityAlteration") private static void cleansUpNesting() { try { @@ -617,14 +620,14 @@ private static class Int extends PhDefault { */ @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") Int() { - this.add(PhDefaultTest.VOID_ATT, new PhVoid(PhDefaultTest.VOID_ATT)); - this.add(PhDefaultTest.PLUS_ATT, new PhSimple(new PhDefault())); + this.add("void", new PhVoid("void")); + this.add("plus", new PhSimple(new PhDefault())); this.add( Phi.PHI, new PhCached( new PhComposite( this, - rho -> rho.take(PhDefaultTest.VOID_ATT) + rho -> rho.take("void") ) ) ); @@ -635,7 +638,7 @@ private static class Int extends PhDefault { this, rho -> { final Phi plus = new Data.ToPhi(5L).take( - PhDefaultTest.PLUS_ATT + "plus" ).copy(); plus.put(0, new Data.ToPhi(6L)); return plus; diff --git a/eo-runtime/src/test/java/org/eolang/PhPackageTest.java b/eo-runtime/src/test/java/org/eolang/PhPackageTest.java index 7f46a68bff4..48bca2f634c 100644 --- a/eo-runtime/src/test/java/org/eolang/PhPackageTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhPackageTest.java @@ -24,11 +24,6 @@ @SuppressWarnings("PMD.TooManyMethods") final class PhPackageTest { - /** - * Default test package. - */ - private static final String DEFAULT_PACKAGE = "Φ.org.eolang"; - @Test void copiesObject() { MatcherAssert.assertThat( @@ -94,7 +89,7 @@ void findsLongClass() { @ParameterizedTest @MethodSource("attributes") void retrievesAttribute(final String attribute, final Class expected) { - final Phi parent = new PhPackage(PhPackageTest.DEFAULT_PACKAGE); + final Phi parent = new PhPackage(this.phiPackageName()); final Phi actual = parent.take(attribute); MatcherAssert.assertThat( String.format( @@ -110,14 +105,14 @@ void retrievesAttribute(final String attribute, final Class expected) { void throwsExceptionIfCantInstantiateObject() { Assertions.assertThrows( ExFailure.class, - () -> new PhPackage(PhPackageTest.DEFAULT_PACKAGE).take("failed"), + () -> new PhPackage(this.phiPackageName()).take("failed"), "Should throw if object cannot be instantiated, but it was" ); } @Test void returnsSelfOnCopy() { - final Phi pckg = new PhPackage(PhPackageTest.DEFAULT_PACKAGE); + final Phi pckg = new PhPackage(this.phiPackageName()); MatcherAssert.assertThat( "Package object should return itself on copying", pckg.copy(), @@ -129,8 +124,8 @@ void returnsSelfOnCopy() { void returnsForma() { MatcherAssert.assertThat( "Should return valid forma", - new PhPackage(PhPackageTest.DEFAULT_PACKAGE).forma(), - Matchers.equalTo(PhPackageTest.DEFAULT_PACKAGE) + new PhPackage(this.phiPackageName()).forma(), + Matchers.equalTo(this.phiPackageName()) ); } @@ -138,14 +133,14 @@ void returnsForma() { void returnsLocator() { MatcherAssert.assertThat( "locator of the DEFAULT_PACKAGE must be ?:?:?, but is wasn't", - new PhPackage(PhPackageTest.DEFAULT_PACKAGE).locator(), + new PhPackage(this.phiPackageName()).locator(), Matchers.equalTo("?:?:?") ); } @Test void findsAttributesInThreads() { - final PhPackage pckg = new PhPackage(PhPackageTest.DEFAULT_PACKAGE); + final PhPackage pckg = new PhPackage(this.phiPackageName()); MatcherAssert.assertThat( "Should take an attribute in multiple threads", new Together<>( @@ -157,6 +152,13 @@ void findsAttributesInThreads() { ); } + /** + * Returns the phi package name. + */ + private String phiPackageName() { + return "Φ.org.eolang"; + } + private static Stream attributes() { return Stream.of( Arguments.of("bytes$eq", EObytes$EOeq.class), diff --git a/pom.xml b/pom.xml index 84bd40944e4..ba43bbca2ec 100644 --- a/pom.xml +++ b/pom.xml @@ -502,7 +502,7 @@ com.github.volodya-lombrozo jtcop-maven-plugin - 1.3.5 + 1.4.1 true