### Question:
Check { public static void isLength(final String field, final String string, final int expectedLength) throws ValidationException { if (expectedLength > -1) { if (string == null || string.length() != expectedLength) { final String errorMessage = String.format(INVALID_LENGTH + "[%s], string -> [%s]", expectedLength, string); throw new ValidationException(errorMessage, field); } } else { final String errorMessage = String.format(INVALID_LENGTH_ARG + "[%s], string -> [%s]", expectedLength, string); 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 shouldThrowValidationException_withInvalidLengthArgument() { final String value = Randoms.randomString(10); final int length = -1 - Randoms.randomInt(10); ValidationException actualException = null; try { Check.isLength(field, value, length); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertThat(actualException.getFields()[0], is(field)); }
@Test public void shouldThrowValidationException_withIncorrectLength() { final String value = Randoms.randomString(10); final int length = Randoms.randomInt(8); ValidationException actualException = null; try { Check.isLength(field, value, length); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertThat(actualException.getFields()[0], is(field)); }
@Test public void shouldThrowValidationException_withNullStringForLengthValidation() { final String value = null; final int length = Randoms.randomInt(20); ValidationException actualException = null; try { Check.isLength(field, value, length); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertThat(actualException.getFields()[0], is(field)); }
@Test public void shouldNotThrowValidationException_withCorrectStringLength() { final int length = Randoms.randomInt(20); final String value = Randoms.randomString(length); ValidationException actualException = null; try { Check.isLength(field, value, length); } catch (final ValidationException e) { actualException = e; } assertNull(actualException); }