### Question:
Check { public static void isValidPhoneNumber(final String field, final String phoneNumber) throws ValidationException { if (phoneNumber == null || !PHONE_NUMBER_PATTERN.matcher(phoneNumber).matches() || phoneNumber.replaceAll("[^0-9]", "").length() > 15) { final String errorMessage = String.format(INVALID_PHONE_NUMBER + " : value -> [%s]", phoneNumber); throw new ValidationException(errorMessage, field); } }  static void isNotEmptyOrNull(final String field, final String value); static void isNotEmptyOrNull(final String field, final Collection<?> value); static void isNotNull(final String field, final Object value); static void isValidEmail(final String field, final String email); static void isValidPhoneNumber(final String field, final String phoneNumber); static void contains(final String field, final String value, final CharSequence expectedSubsequence); static void isLength(final String field, final String string, final int expectedLength); static void isBetween(final String field, final int value, final int minValue, final int maxValue); static void matchesPattern(final String field, final String value, final Pattern pattern);  }### Answer:
@Test public void shouldCheckPhoneNumber_withValidPhoneNumber() throws Exception { final String phoneNumber = randomPhoneNumber(); ValidationException actualException = null; try { Check.isValidPhoneNumber("phoneNumber", phoneNumber); } catch (final ValidationException e) { actualException = e; } assertNull(actualException); }
@Test public void shouldCheckPhoneNumber_withPhoneNumberWithoutLeadingPlusSign() throws Exception { final String phoneNumber = "020 02020202"; ValidationException actualException = null; try { Check.isValidPhoneNumber("phoneNumber", phoneNumber); } catch (final ValidationException e) { actualException = e; } assertNull(actualException); }
@Test public void shouldCheckPhoneNumber_withNullPhoneNumber() throws Exception { final String phoneNumber = null; ValidationException actualException = null; try { Check.isValidPhoneNumber("phoneNumber", phoneNumber); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertEquals(1, actualException.getFields().length); assertEquals("phoneNumber", actualException.getFields()[0]); }
@Test public void shouldCheckPhoneNumber_withAlphabeticalPhoneNumber() throws Exception { final String phoneNumber = "a" + randomString(10); ValidationException actualException = null; try { Check.isValidPhoneNumber("phoneNumber", phoneNumber); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertEquals(1, actualException.getFields().length); assertEquals("phoneNumber", actualException.getFields()[0]); }
@Test public void shouldCheckPhoneNumber_withLongPhoneNumber() throws Exception { final StringBuilder sb = new StringBuilder(); while (sb.length() < 20) { sb.append(randomInt(Integer.MAX_VALUE)); } final String phoneNumber = "+" + sb.toString(); ValidationException actualException = null; try { Check.isValidPhoneNumber("phoneNumber", phoneNumber); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertEquals(1, actualException.getFields().length); assertEquals("phoneNumber", actualException.getFields()[0]); }