Skip to content

Commit

Permalink
feat(objectionary#2148): Move OyFake into Objectionary.Fake
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Jun 16, 2023
1 parent df80a84 commit 3542890
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
*/
package org.eolang.maven.objectionary;

import com.jcabi.log.Logger;
import java.io.IOException;
import org.cactoos.Func;
import org.cactoos.Input;
import org.cactoos.io.InputOf;

/**
* Objectionary.
Expand Down Expand Up @@ -55,4 +58,88 @@ public interface Objectionary {
* @throws IOException If fails to fetch.
*/
boolean contains(String name) throws IOException;

/**
* Objectionary with lambda-function Ctor-s for testing.
*
* @since 0.28.11
* @checkstyle IllegalCatchCheck (150 lines)
*/
@SuppressWarnings("PMD.AvoidCatchingGenericException")
final class Fake implements Objectionary {

/**
* Function that emulates 'get()' method in {@link Objectionary}.
*/
private final Func<String, Input> getter;

/**
* Function that emulates 'contains()' method in {@link Objectionary}.
*/
private final Func<String, Boolean> container;

/**
* Ctor.
*/
public Fake() {
this(
s -> new InputOf("[] > sprintf\n")
);
}

/**
* Ctor.
*
* @param gett Lambda func for get()
*/
Fake(final Func<String, Input> gett) {
this(
gett,
s -> true
);
}

/**
* Ctor.
*
* @param gett Lambda func for get()
* @param cont Lambda func for contains()
*/
public Fake(
final Func<String, Input> gett,
final Func<String, Boolean> cont
) {
this.getter = gett;
this.container = cont;
}

@Override
public Input get(final String name) {
try {
return this.getter.apply(name);
} catch (final Exception ex) {
Logger.debug(
this, "Invalid lambda function for get() method in OyFake!"
);
throw new IllegalArgumentException(ex);
}
}

@Override
public boolean contains(final String name) {
try {
return this.container.apply(name);
} catch (final Exception ex) {
Logger.debug(
this, "Invalid lambda function for contains() method in OyFake!"
);
throw new IllegalArgumentException(ex);
}
}

@Override
public String toString() {
return "OyFake";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.set.SetOf;
import org.eolang.maven.objectionary.OyFake;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -74,7 +74,7 @@ void assemblesTogether(@TempDir final Path temp) throws Exception {
.with("ignoreTransitive", true)
.with(
"objectionary",
new OyFake()
new Objectionary.Fake()
)
.execute();
MatcherAssert.assertThat(
Expand Down Expand Up @@ -138,7 +138,7 @@ void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws Except
.with("plugin", FakeMaven.pluginDescriptor())
.with(
"objectionary",
new OyFake()
new Objectionary.Fake()
)
.execute();
MatcherAssert.assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.set.SetOf;
import org.eolang.maven.objectionary.OyFake;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -94,7 +94,7 @@ void makesFullCompilingLifecycleSuccessfully(@TempDir final Path temp) throws IO
.with("plugin", FakeMaven.pluginDescriptor())
.with(
"objectionary",
new OyFake()
new Objectionary.Fake()
)
.execute();
new Moja<>(CleanMojo.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.cactoos.text.UncheckedText;
import org.eolang.maven.hash.ChCached;
import org.eolang.maven.hash.ChRemote;
import org.eolang.maven.objectionary.OyFake;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.objectionary.OyRemote;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
Expand All @@ -57,7 +57,7 @@ void findsProbes(@TempDir final Path temp) throws Exception {
ProbeMojoTest.firstEntry(
new FakeMaven(temp)
.with("foreignFormat", "json")
.with("objectionary", new OyFake())
.with("objectionary", new Objectionary.Fake())
.withProgram(ProbeMojoTest.program())
.execute(new FakeMaven.Probe())
.foreignPath(),
Expand All @@ -77,7 +77,7 @@ void findsProbesViaOfflineHashFile(@TempDir final Path temp) throws IOException
ProbeMojoTest.firstEntry(
new FakeMaven(temp)
.with("offlineHashFile", temp.resolve("tags.txt"))
.with("objectionary", new OyFake())
.with("objectionary", new Objectionary.Fake())
.withProgram(ProbeMojoTest.program())
.execute(new FakeMaven.Probe())
.foreignPath(),
Expand All @@ -94,7 +94,7 @@ void findsProbesViaOfflineHash(@TempDir final Path temp) throws IOException {
new FakeMaven(temp)
.with("tag", "1.0.0")
.with("offlineHash", "*.*.*:abcdefg")
.with("objectionary", new OyFake())
.with("objectionary", new Objectionary.Fake())
.withProgram(ProbeMojoTest.program())
.execute(new FakeMaven.Probe())
.foreignPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.cactoos.io.ResourceOf;
import org.eolang.maven.hash.ChCompound;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.objectionary.OyFake;
import org.eolang.maven.objectionary.OyRemote;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
Expand All @@ -55,7 +54,7 @@ void pullsSuccessfully(@TempDir final Path temp) throws IOException {
maven.foreignTojos()
.add("org.eolang.io.stdout")
.withVersion("*.*.*");
maven.with("objectionary", new OyFake())
maven.with("objectionary", new Objectionary.Fake())
.execute(PullMojo.class);
MatcherAssert.assertThat(
new Home(temp.resolve("target")).exists(
Expand Down Expand Up @@ -111,7 +110,7 @@ void pullsUsingOfflineHashFile(@TempDir final Path temp) throws IOException {
maven.foreignTojos()
.add("org.eolang.io.stdout")
.withVersion("*.*.*");
maven.with("objectionary", new OyFake())
maven.with("objectionary", new Objectionary.Fake())
.with("offlineHashFile", temp.resolve("tags.txt"))
.execute(PullMojo.class);
MatcherAssert.assertThat(
Expand All @@ -131,7 +130,7 @@ void pullsUsingOfflineHash(@TempDir final Path temp) throws IOException {
maven.foreignTojos()
.add("org.eolang.io.stdout")
.withVersion("*.*.*");
maven.with("objectionary", new OyFake())
maven.with("objectionary", new Objectionary.Fake())
.with("tag", "1.0.0")
.with("offlineHash", "*.*.*:abcdefg")
.execute(PullMojo.class);
Expand Down
4 changes: 2 additions & 2 deletions eo-maven-plugin/src/test/java/org/eolang/maven/SkipTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eolang.maven.objectionary.OyFake;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -105,7 +105,7 @@ private void executePullMojo(
.withScope("compile")
.withVersion("*.*.*");
maven.with("skip", skip)
.with("objectionary", new OyFake())
.with("objectionary", new Objectionary.Fake())
.execute(PullMojo.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void putsObjectToLocalCache(@TempDir final Path path) throws Exception {
new OyCaching(
"master",
path,
new OyFake(s -> new InputOf(content))
new Objectionary.Fake(s -> new InputOf(content))
).get("org.example.main")
).asString(),
Matchers.is(content)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void getsWithFallbackNoSwapOy() throws Exception {
MatcherAssert.assertThat(
new TextOf(
new OyFallbackSwap(
new OyFake(s -> new InputOf("[] > local\n")),
new OyFake(s -> new InputOf("[] > remote\n")),
new Objectionary.Fake(s -> new InputOf("[] > local\n")),
new Objectionary.Fake(s -> new InputOf("[] > remote\n")),
false
).get("")
).asString(),
Expand All @@ -56,8 +56,8 @@ void getsWithFallbackSwapOyFail() throws Exception {
MatcherAssert.assertThat(
new TextOf(
new OyFallbackSwap(
new OyFake(s -> new InputOf("[] > local\n")),
new OyFake(
new Objectionary.Fake(s -> new InputOf("[] > local\n")),
new Objectionary.Fake(
s -> {
throw new IOException("Can't get object");
}
Expand All @@ -74,8 +74,8 @@ void getsWithFallbackSwapOy() throws Exception {
MatcherAssert.assertThat(
new TextOf(
new OyFallbackSwap(
new OyFake(s -> new InputOf("[] > local\n")),
new OyFake(s -> new InputOf("[] > remote\n")),
new Objectionary.Fake(s -> new InputOf("[] > local\n")),
new Objectionary.Fake(s -> new InputOf("[] > remote\n")),
true
).get("")
).asString(),
Expand All @@ -92,7 +92,7 @@ void checksPresenceOfObject(@TempDir final Path path) throws Exception {
final Objectionary cache = new OyCaching(
"master",
path,
new OyFake(
new Objectionary.Fake(
s -> new InputOf("[] > main\n"),
s -> false
)
Expand Down

0 comments on commit 3542890

Please sign in to comment.