unruly / java-8-matchers

Hamcrest Matchers for Java 8 features
MIT License
23 stars 5 forks source link

Missing space in mismatch description #15

Open mtc-janheyd opened 5 years ago

mtc-janheyd commented 5 years ago

There is a space character missing in the description of OptionalMatchers.contains(Matcher<T> matcher) before the description of the sub-matcher.

import org.junit.Test;

import java.util.Optional;

import static co.unruly.matchers.OptionalMatchers.contains;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class OptionalMatcherTest {

    @Test
    public void show_the_bug() {
        assertThat(Optional.of("foo"), contains(equalTo("bar")));
    }
}

This produces the following message:

java.lang.AssertionError: 
Expected: Optional with an item that matches"bar"
     but: was <Optional[foo]>
Expected :Optional with an item that matches"bar"

Actual   :<Optional[foo]>

This gets very confusing when using a FeatureMatcher because the FeatureMatcher does not quote its description so it just becomes something like

Expected: Optional with an item that matchesbar

which can be pretty hard to read.