### Question:
Check { public static void contains(final String field, final String value, final CharSequence expectedSubsequence) throws ValidationException { if (value == null || expectedSubsequence == null || !value.contains(expectedSubsequence)) { final String errorMessage = String.format(DOES_NOT_CONTAIN + "'%s', value -> [%s]", expectedSubsequence, value); 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_givenNullContainingString() { final String string = null; final CharSequence charSequence = Randoms.randomString(15); ValidationException actualException = null; try { Check.contains(field, string, charSequence); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertThat(actualException.getFields()[0], is(field)); }
@Test public void shouldThrowValidationException_givenNullCharSequence() { final String string = Randoms.randomString(15); final CharSequence charSequence = null; ValidationException actualException = null; try { Check.contains(field, string, charSequence); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertThat(actualException.getFields()[0], is(field)); }
@Test public void shouldNotThrowValidationException_givenEmptyCharSequence() { final String string = Randoms.randomString(15); final CharSequence charSequence = ""; ValidationException actualException = null; try { Check.contains(field, string, charSequence); } catch (final ValidationException e) { actualException = e; } assertNull(actualException); }
@Test public void shouldThrowValidationException_givenCharSequenceNotInString() { final String string = Randoms.randomString(50); final CharSequence charSequence = "------------------------------"; ValidationException actualException = null; try { Check.contains(field, string, charSequence); } catch (final ValidationException e) { actualException = e; } assertNotNull(actualException); assertThat(actualException.getFields()[0], is(field)); }
@Test public void shouldNotThrowValidationException_givenCharSequenceInString() { final String string = Randoms.randomString(50); final int beginIndex = Randoms.randomInt(15); final int endIndex = 50 - Randoms.randomInt(15); final CharSequence charSequence = string.subSequence(beginIndex, endIndex); ValidationException actualException = null; try { Check.contains(field, string, charSequence); } catch (final ValidationException e) { actualException = e; } assertNull(actualException); }