Example #1
0
 /**
  * Assert that the given text does not contain the given substring.
  *
  * <pre class="code">
  * Assert.doesNotContain(name, &quot;rod&quot;, &quot;Name must not contain 'rod'&quot;);
  * </pre>
  *
  * @param textToSearch the text to search
  * @param substring the substring to find within the text
  * @param message the exception message to use if the assertion fails
  */
 public static void doesNotContain(String textToSearch, String substring, String message) {
   if (DataUtil.isNotNullOrEmpty(textToSearch)
       && DataUtil.isNotNullOrEmpty(substring)
       && textToSearch.indexOf(substring) != -1) {
     throw new IllegalArgumentException(message);
   }
 }
Example #2
0
 /**
  * Assert that a Map has entries; that is, it must not be <code>null</code> and must have at least
  * one entry.
  *
  * <pre class="code">
  * Assert.notEmpty(map, &quot;Map must have entries&quot;);
  * </pre>
  *
  * @param map the map to check
  * @param message the exception message to use if the assertion fails
  * @throws IllegalArgumentException if the map is <code>null</code> or has no entries
  */
 public static void notEmpty(Map map, String message) {
   if (DataUtil.isNullOrEmpty(map)) {
     throw new IllegalArgumentException(message);
   }
 }
Example #3
0
 /**
  * Assert that a collection has elements; that is, it must not be <code>null</code> and must have
  * at least one element.
  *
  * <pre class="code">
  * Assert.notEmpty(collection, &quot;Collection must have elements&quot;);
  * </pre>
  *
  * @param collection the collection to check
  * @param message the exception message to use if the assertion fails
  * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements
  */
 public static void notEmpty(Collection collection, String message) {
   if (DataUtil.isNullOrEmpty(collection)) {
     throw new IllegalArgumentException(message);
   }
 }
Example #4
0
 /**
  * Assert that an array has elements; that is, it must not be <code>null</code> and must have at
  * least one element.
  *
  * <pre class="code">
  * Assert.notEmpty(array, &quot;The array must have elements&quot;);
  * </pre>
  *
  * @param array the array to check
  * @param message the exception message to use if the assertion fails
  * @throws IllegalArgumentException if the object array is <code>null</code> or has no elements
  */
 public static void notEmpty(Object[] array, String message) {
   if (DataUtil.isNullOrEmpty(array)) {
     throw new IllegalArgumentException(message);
   }
 }
Example #5
0
 /**
  * Assert that the given String has valid text content; that is, it must not be <code>null</code>
  * and must contain at least one non-whitespace character.
  *
  * <pre class="code">
  * Assert.hasText(name, &quot;'name' must not be empty&quot;);
  * </pre>
  *
  * @param text the String to check
  * @param message the exception message to use if the assertion fails
  */
 public static void hasText(String text, String message) {
   if (!DataUtil.isNotNullOrEmpty(text)) {
     throw new IllegalArgumentException(message);
   }
 }