Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 16, 2023
2 parents b1a895e + af9612c commit 3e571c5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.yegor256.tojos.Tojo;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import org.eolang.maven.Coordinates;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.util.Rel;
Expand Down Expand Up @@ -307,4 +308,23 @@ public ForeignTojo withVer(final String ver) {
public String ver() {
return this.delegate.get(ForeignTojos.Attribute.VER.key());
}

@Override
public boolean equals(final Object other) {
final boolean result;
if (this == other) {
result = true;
} else if (other == null || this.getClass() != other.getClass()) {
result = false;
} else {
final ForeignTojo tojo = (ForeignTojo) other;
result = Objects.equals(this.delegate, tojo.delegate);
}
return result;
}

@Override
public int hashCode() {
return Objects.hash(this.delegate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ public ForeignTojo add(final ObjectName name) {
* Find tojo by tojo id.
* @param id The id of the tojo.
* @return The tojo.
* @todo #2331:90min Add unit test for ForeignTojos.find method.
* The test should check that the method returns the tojo with the
* specified id. When the test is ready, remove that puzzle.
*/
public ForeignTojo find(final String id) {
return new ForeignTojo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
package org.eolang.maven.tojos;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

Expand Down Expand Up @@ -79,6 +83,39 @@ void doesNotContain(final String existing, final String considered) {
);
}

@Test
void findsLookingTojoCorrectly() {
final String looking = "looking";
MatcherAssert.assertThat(
"Found tojo should be the same as added",
this.tojos.add(looking),
Matchers.equalTo(this.tojos.find(looking))
);
}

@Test
void throwsExceptionIfTojoWasNotFound() {
final String id = "absent";
Assertions.assertThrows(
IllegalArgumentException.class,
() -> this.tojos.find(id),
String.format("Should throw an exception if tojo with id='%s' was not found", id)
);
}

@Test
void findsAnyTojoIfSeveralTojosWithTheSameIdWereAdded() {
final String same = "same";
final ForeignTojo first = this.tojos.add(same);
final ForeignTojo second = this.tojos.add(same);
final List<ForeignTojo> expected = Arrays.asList(first, second);
MatcherAssert.assertThat(
"We don't care which tojo will be returned, but it should be one of the added tojos",
expected,
Matchers.hasItem(this.tojos.find(same))
);
}

@AfterEach
void tearDown() throws IOException {
this.tojos.close();
Expand Down

1 comment on commit 3e571c5

@0pdd
Copy link

@0pdd 0pdd commented on 3e571c5 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2331-2e1725a8 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java), that's why I closed #2392. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.