IsUUID extends BaseMatcher<CharSequence> { @Override public boolean matches(final Object arg) { try { UUID.fromString(arg.toString()); }catch (IllegalArgumentException ex) { return false; } return true; }  static Matcher UUID(); @Override boolean matches(final Object arg); @Override void describeTo(final Description description);  }
@Test public void testGivenAUUIDWhenMatchesIsCalledThenTrueIsReturened() throws Exception { Object actual = UUID.nameUUIDFromBytes("Test".getBytes(Charset.forName("UTF-8"))); final boolean matches = isUUIDMatcher.matches(actual); assertMatches(matches); }
@Test public void testGivenAStringRepresentingUUIDWhenMatchesIsCalledThenTrueIsReturened() throws Exception { String actual = UUID.nameUUIDFromBytes("Test".getBytes(Charset.forName("UTF-8"))).toString(); final boolean matches = isUUIDMatcher.matches(actual); assertMatches(matches); }
@Test public void testGivenNotAUUIDWhenMatchesIsCalledThenTrueIsReturened() throws Exception { String actual = "TEST"; final boolean matches = isUUIDMatcher.matches(actual); assertDoesNotMatch(matches); }