### Question:
OptionMatchers { public static <T> Matcher<? super Option<T>> hasValue() { return new OptionHasAnyValueMatcher(); }  static Matcher<? super Option<T>> hasValue(); static Matcher<? super Option<T>> hasValue(final T value); static Matcher<? super Option<T>> hasValueOf(Class<T> valueClass); static Matcher<? super Option<T>> hasNoValue(); static Matcher<? super Option<T>> hasNoValueOf(Class<T> valueClass);  }### Answer:
@Test public void shouldMatchWhenHasValueMatcherEvaluatesOptionWithAnyValue() throws Exception { Option<String> option = Option.option("value"); Matcher<? super Option<String>> matcher = hasValue(); assertThat(matcher, successfullyMatches(option)); }
@Test public void shouldMismatchWithMessageWhenHasValueMatcherEvaluatesOptionWithNoValue() throws Exception { Option<String> option = Option.none(); Matcher<? super Option<String>> matcher = hasValue(); assertThat(matcher, mismatchesSampleWithMessage(option, "Option with no value.")); }
@Test public void shouldProvideAdequateDescriptionWhenHasValueAskedToDescribeItself() throws Exception { Matcher<? super Option<String>> matcher = hasValue(); StringDescription description = new StringDescription(); matcher.describeTo(description); assertThat(description.toString(), is("Option with value.")); }
@Test public void shouldMatchWhenHasValueMatcherEvaluatesOptionWithSpecificValue() throws Exception { Option<String> option = Option.option("matching value"); Matcher<? super Option<String>> matcher = hasValue("matching value"); assertThat(matcher, successfullyMatches(option)); }
@Test public void shouldMatchWhenHasValueMatcherEvaluatesOptionWithNullValueAndOptionWithNullValueExpected() throws Exception { Option<String> option = Option.some(null); Matcher<? super Option<String>> matcher = hasValue(null); assertThat(matcher, successfullyMatches(option)); }
@Test public void shouldMismatchWithMessageWhenHasValueMatcherEvaluatesOptionWithDifferentValue() throws Exception { Option<String> option = Option.option("actual value"); Matcher<? super Option<String>> matcher = hasValue("expected value"); assertThat(matcher, mismatchesSampleWithMessage(option, "Option with value: \"actual value\"")); }
@Test public void shouldMismatchWithMessageWhenHasValueMatcherEvaluatesOptionWithNullValueButAValueIsExpected() throws Exception { Option<String> option = Option.some(null); Matcher<? super Option<String>> matcher = hasValue("expected value"); assertThat(matcher, mismatchesSampleWithMessage(option, "Option with value: null")); }
@Test public void shouldMismatchWithMessageWhenHasValueMatcherEvaluatesOptionWithAValueButNullValueIsExpected() throws Exception { Option<String> option = Option.some("actual value"); Matcher<? super Option<String>> matcher = hasValue(null); assertThat(matcher, mismatchesSampleWithMessage(option, "Option with value: \"actual value\"")); }
@Test public void shouldMismatchWithMessageWhenHasValueMatcherExpectingSpecificValueEvaluatesOptionWithNoValue() throws Exception { Option<String> option = Option.none(); Matcher<? super Option<String>> matcher = hasValue("value"); assertThat(matcher, mismatchesSampleWithMessage(option, "Option with no value.")); }
@Test public void shouldProvideAdequateDescriptionWhenHasValueWithSpecificValueAskedToDescribeItself() throws Exception { Matcher<? super Option<String>> matcher = hasValue("value"); StringDescription description = new StringDescription(); matcher.describeTo(description); assertThat(description.toString(), is("Option with value: \"value\"")); }