Created
March 17, 2016 08:42
-
-
Save xsveda/37d3fb8b87f618833923 to your computer and use it in GitHub Desktop.
Hamcrest matchers for Optional class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OptionalMatcher { | |
public static IsPresentMatcher isPresent() { | |
return new IsPresentMatcher(); | |
} | |
public static IsEmptyMatcher isEmpty() { | |
return new IsEmptyMatcher(); | |
} | |
public static class IsPresentMatcher extends TypeSafeDiagnosingMatcher<Optional> { | |
@Override | |
protected boolean matchesSafely(Optional optional, Description description) { | |
return optional.isPresent(); | |
} | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("Optional value should be present"); | |
} | |
} | |
public static class IsEmptyMatcher extends TypeSafeDiagnosingMatcher<Optional> { | |
@Override | |
protected boolean matchesSafely(Optional optional, Description description) { | |
return !optional.isPresent(); | |
} | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("Optional value should be empty"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment