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

OptionalSubject<String> comparison failure message ignores custom name #156

Closed
kaibolay opened this issue Nov 15, 2014 · 2 comments
Closed
Assignees
Labels
type=defect Bug, not working as expected

Comments

@kaibolay
Copy link

assertThat(someOptionalFoobarString).named("FroBar").hasValue(expected);

results in "Optional has an incorrect value. expected: but was:".

What happened to the custom name "FooBar"? Looks like it's simply ignored:

https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalSubject.java#L61-L64

  if (!getSubject().get().equals(expected)) {
    if (getSubject().get() instanceof String) {
      this.failureStrategy.failComparing("Optional<String> has an incorrect value.",
          (String) expected, (String) actual);
@kluever kluever self-assigned this Nov 15, 2014
@kluever kluever added S2 - Useful type=defect Bug, not working as expected labels Nov 15, 2014
@cgruber
Copy link
Contributor

cgruber commented Nov 15, 2014

Fix in progress

On Sat, Nov 15, 2014, 04:59 kaibolay notifications@github.com wrote:

assertThat(someOptionalFoobarString).named("FroBar").hasValue(expected);

results in "Optional has an incorrect value. expected: but was:".

What happened to the custom name "FooBar"? Looks like it's simply ignored:

https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalSubject.java#L61-L64

if (!getSubject().get().equals(expected)) {
if (getSubject().get() instanceof String) {
this.failureStrategy.failComparing("Optional has an incorrect value.",
(String) expected, (String) actual);


Reply to this email directly or view it on GitHub
#156.

@kluever
Copy link
Member

kluever commented Nov 18, 2014

Fix submitted internally . Should be mirror out soon.

@kluever kluever closed this as completed Nov 18, 2014
kluever added a commit that referenced this issue Nov 20, 2014
…lue().

See #156
Remove String special casing and include actual output in isPresent()/isAbsent() failure messages.
Update throw/catch expected/fail pattern to avoid fail() / catch (AssertionError) trickiness.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=80217696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants