Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Sep 26, 2018
2 parents 7b33460 + d38aa54 commit dd6967d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/main/java/org/cactoos/text/TextEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,23 @@ public final int hashCode() {
return new UncheckedScalar<>(this.origin).value().hashCode();
}

// @todo #942:30min Refactor TextEnvelope.equals(). Current implementation
// of TextEnvelope.equals() uses some things that we must avoid, like more
// than one return on method, instance of usage and typecasting. Refactor
// this method so we can get rid of these smelly things.
//
@Override
@SuppressWarnings("PMD.OnlyOneReturn")
public final boolean equals(final Object obj) {
return new UncheckedScalar<>(this.origin).value().equals(obj);
if (this == obj) {
return true;
}
if (!(obj instanceof Text)) {
return false;
}
final Text that = (Text) obj;
return new UncheckedText(this).asString().equals(
new UncheckedText(that).asString()
);
}
}
23 changes: 20 additions & 3 deletions src/test/java/org/cactoos/text/TextEnvelopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,32 @@ public void testAsString() throws Exception {
}
/**
* Test for {@link TextEnvelope#equals(Object)} method. Must assert
* that the envelope value is equal to its string value.
* that the envelope value is equal another text representing the same
* value.
*/
@Test
public void testEquals() {
final String text = "equals";
MatcherAssert.assertThat(
"Envelope value does not match its represented String value",
"Envelope does not match text representing the same value",
new TextEnvelopeDummy(text),
new IsEqual<>(text)
new IsEqual<>(new TextOf(text))
);
}

/**
* Test for {@link TextEnvelope#equals(Object)} method. Must assert
* that the envelope value is equal another text representing the same
* value (in this case a {@link JoinedText}).
*/
@Test
public void testEqualsOtherText() {
MatcherAssert.assertThat(
"Envelope does not match another text representing the same value",
new TextEnvelopeDummy("isequaltoanothertext"),
new IsEqual<>(
new JoinedText("", "is", "equal", "to", "another", "text")
)
);
}
/**
Expand Down

1 comment on commit dd6967d

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on dd6967d Sep 26, 2018

Choose a reason for hiding this comment

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

Puzzle 942-9caf1821 discovered in src/main/java/org/cactoos/text/TextEnvelope.java and submitted as #955. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.