Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new method contains() in Objectionary and OyFake #1567

Merged
merged 25 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9e1e9e3
new method `contains()` in `Objectionary` and `OyLambda`
MikhailLipanin Dec 15, 2022
bbac384
move test classes to their packages
MikhailLipanin Dec 15, 2022
ca50dbe
added tests
MikhailLipanin Dec 16, 2022
9d7df66
Merge branch 'master' into OyLambda
MikhailLipanin Dec 16, 2022
af21619
Merge branch 'master' into OyLambda
MikhailLipanin Dec 19, 2022
9c7c194
Merge branch 'master' into OyLambda
MikhailLipanin Dec 20, 2022
f2b364c
empty commit
MikhailLipanin Dec 20, 2022
45f7c34
Matchers instead of Assertions + fix names in OyFake
MikhailLipanin Dec 21, 2022
d48a60a
PMD
MikhailLipanin Dec 21, 2022
80bb89b
PMD |B-(
MikhailLipanin Dec 21, 2022
97c277a
default Ctor of `OyFake`
MikhailLipanin Dec 21, 2022
c8822bc
use `Home.save()` instead of `LengthOf().value()`
MikhailLipanin Dec 21, 2022
b7db058
OyEmptyTest + refact
MikhailLipanin Dec 21, 2022
31ba97e
Merge branch 'master' into OyLambda
MikhailLipanin Dec 21, 2022
9a2f291
refact
MikhailLipanin Dec 21, 2022
b8fc4c3
refactoring
MikhailLipanin Dec 21, 2022
a41ca04
Merge branch 'master' into OyLambda
MikhailLipanin Dec 21, 2022
e48fa98
resolved review
MikhailLipanin Dec 22, 2022
fd98fbc
added todo
MikhailLipanin Dec 22, 2022
18ec61a
r3f4c70R
MikhailLipanin Dec 22, 2022
d594bc1
r3f4c70R (another try)
MikhailLipanin Dec 22, 2022
6d97849
Merge branch 'master' into OyLambda
MikhailLipanin Dec 25, 2022
83a667f
set COVEREDRATIO to expected values
MikhailLipanin Dec 25, 2022
2f437ad
set COVEREDRATIO to expected values (again)
MikhailLipanin Dec 25, 2022
36dc630
Merge branch 'master' into OyLambda
MikhailLipanin Dec 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,25 @@
public interface Objectionary {
/**
* Resolve object.
*
* @param name Object name.
* @return Object code.
* @throws IOException If fails to fetch.
*/
Input get(String name) throws IOException;

/**
* Checks whether an Objectionary contains a provided object.
* @param name Object name.
* @return Object code.
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
* @throws IOException If fails to fetch.
*/
/**
* Checks whether an Objectionary contains a provided object.
*
* @param name Object name.
* @return Boolean: "true" if found, "false" if not.
* @throws IOException If fails to fetch.
*/
boolean contains(String name) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ public Input get(final String name) throws IOException {
)
);
}

@Override
public boolean contains(final String name) throws IOException {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
return this.primary.contains(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public Input get(final String name) throws IOException {
throw new IOException("Empty objectionary");
}

@Override
public boolean contains(final String name) throws IOException {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
throw new IOException("Empty objectionary");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ public Input get(final String name) throws IOException {
)
).apply(name);
}

@Override
@SuppressWarnings("unchecked")
public boolean contains(final String name) throws IOException {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
return this.first.contains(name) || this.second.contains(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public Input get(final String name) throws IOException {
return this.swapped.value().get(name);
}

@Override
public boolean contains(final String name) throws IOException {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
return this.swapped.value().contains(name);
}

@Override
public String toString() {
return this.swapped.value().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
*/
package org.eolang.maven.objectionary;

import com.jcabi.log.Logger;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import org.cactoos.Input;
import org.cactoos.io.InputOf;
Expand Down Expand Up @@ -82,9 +85,31 @@ public Input get(final String name) throws FileNotFoundException {
.resolve(this.version),
"eo"
);
if (!file.toFile().exists()) {
if (!Files.exists(file)) {
throw new FileNotFoundException(name);
}
return new InputOf(file);
}

@Override
public boolean contains(final String name) {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
boolean ret;
try {
ret = Files.exists(
new Place(name).make(
this.home
.resolve("pulled")
.resolve(this.version),
"eo"
)
);
} catch (final InvalidPathException ex) {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
Logger.debug(
this, "The object '%s' is absent in %s...",
name, this.home
);
ret = false;
}
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

import com.jcabi.log.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.cactoos.Input;
import org.cactoos.io.InputOf;
import org.cactoos.scalar.Unchecked;
import org.eolang.maven.Place;
import org.eolang.maven.hash.CommitHash;

Expand Down Expand Up @@ -71,6 +73,22 @@ public Input get(final String name) throws MalformedURLException {
return new InputOf(url);
}

@Override
public boolean contains(final String name) throws MalformedURLException {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
final URL url = this.template.value(name);
boolean presence;
try (InputStream inputStream = new Unchecked<>(() -> url).value().openStream()) {
presence = true;
} catch (final IOException ex) {
Logger.debug(
this, "The object '%s' is absent in %s...",
name, url
);
presence = false;
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
}
return presence;
}

/**
* Objectionary URL template.
* Assumes two placeholders in terms of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.io.InputOf;
import org.cactoos.set.SetOf;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.eolang.maven.util.Online;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -73,9 +71,7 @@ void assemblesTogether(@TempDir final Path temp) throws Exception {
.with("ignoreTransitive", true)
.with(
"objectionary",
(Objectionary) input -> new InputOf(
"[] > sprintf\n"
)
new OyFake()
)
.execute();
MatcherAssert.assertThat(
Expand Down Expand Up @@ -134,9 +130,7 @@ void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws Except
.with("ignoreTransitive", true)
.with(
"objectionary",
(Objectionary) input -> new InputOf(
"[] > sprintf\n"
)
new OyFake()
)
.execute();
MatcherAssert.assertThat(
Expand All @@ -162,4 +156,5 @@ void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws Except
Matchers.is(true)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.io.InputOf;
import org.cactoos.set.SetOf;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -92,9 +90,7 @@ void fullCompilingLifecycleSuccessfully(@TempDir final Path temp) throws IOExcep
.with("ignoreTransitive", true)
.with(
"objectionary",
(Objectionary) input -> new InputOf(
"[] > sprintf\n"
)
new OyFake()
)
.execute();
new Moja<>(CleanMojo.class)
Expand Down
119 changes: 119 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/OyFake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2022 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;

import com.jcabi.log.Logger;
import org.cactoos.Func;
import org.cactoos.Input;
import org.cactoos.io.InputOf;
import org.eolang.maven.objectionary.Objectionary;

/**
* Objectionary with lambda-function Ctor-s for testing.
*
* @since 0.28.11
* @checkstyle IllegalCatchCheck (150 lines)
*/
public final class OyFake implements Objectionary {

/**
* Function that emulates 'get()' method in {@link Objectionary}.
*
* @checkstyle MemberNameCheck (5 lines)
*/
@SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName")
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
private final Func<String, Input> get;

/**
* Function that emulates 'contains()' method in {@link Objectionary}.
*
* @checkstyle MemberNameCheck (5 lines)
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
*/
@SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName")
private final Func<String, Boolean> contains;

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

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

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

@Override
public String toString() {
MikhailLipanin marked this conversation as resolved.
Show resolved Hide resolved
return "OyFake";
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import org.cactoos.io.InputOf;
import org.cactoos.io.ResourceOf;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
Expand Down Expand Up @@ -135,6 +134,7 @@ void pullsUsingOfflineHash(@TempDir final Path temp) {
* @return Dummy Objectionary.
*/
private Objectionary dummy() {
return input -> new InputOf("[] > hello\n");
return new OyFake();
}

}
4 changes: 1 addition & 3 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,8 +27,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.io.InputOf;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.eolang.maven.util.Online;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -116,7 +114,7 @@ private void executePullMojo(
.with("skip", skip)
.with(
"objectionary",
(Objectionary) input -> new InputOf("[] > hello\n")
new OyFake()
)
.execute();
}
Expand Down
15 changes: 8 additions & 7 deletions eo-maven-plugin/src/test/java/org/eolang/maven/SnippetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.cactoos.list.ListOf;
import org.cactoos.scalar.LengthOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.util.Home;
import org.eolang.maven.util.Walk;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -123,7 +122,7 @@ void runsAllSnippets(final String yml) throws Exception {
* @throws Exception If fails
* @checkstyle ParameterNumberCheck (5 lines)
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "PMD.ExcessiveMethodLength"})
private static int run(final Path tmp, final Input code, final List<String> args,
final Input stdin, final Output stdout) throws Exception {
final Path src = tmp.resolve("src");
Expand Down Expand Up @@ -154,11 +153,13 @@ private static int run(final Path tmp, final Input code, final List<String> args
.with("placed", target.resolve("list").toFile())
.with(
"objectionary",
(Objectionary) name -> new InputOf(
home.resolve(
String.format(
"src/main/eo/%s.eo",
name.replace(".", "/")
new OyFake(
name -> new InputOf(
home.resolve(
String.format(
"src/main/eo/%s.eo",
name.replace(".", "/")
)
)
)
)
Expand Down
Loading