Skip to content

Instantly share code, notes, and snippets.

@mattnworb
Created September 30, 2010 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattnworb/604664 to your computer and use it in GitHub Desktop.
Save mattnworb/604664 to your computer and use it in GitHub Desktop.
public class GenericsTest {
public void doesNotCompile() {
Container<String> container = new Container<String>();
assertThat(container, hasSomethingWhich(is("foo")));
}
public static class Container<T> {
public boolean hasSomethingMatching(Matcher<? super T> matcher) {
T something = null; // here is some application logic
return matcher.matches(something);
}
}
public static <T> Matcher<Container<T>> hasSomethingWhich(final Matcher<? super T> matcher) {
return new TypeSafeMatcher<Container<T>>() {
@Override
protected boolean matchesSafely(Container<T> container) {
return container.hasSomethingMatching(matcher);
}
@Override
public void describeTo(Description description) {
// TODO Auto-generated method stub
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment