|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -80,8 +80,8 @@ public abstract class Assert {
@@ -80,8 +80,8 @@ public abstract class Assert {
|
|
|
|
|
* <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException} |
|
|
|
|
* on an assertion failure. |
|
|
|
|
* <pre class="code"> |
|
|
|
|
* Assert.state(id == null, |
|
|
|
|
* () -> "ID for " + entity.getName() + " must not already be initialized"); |
|
|
|
|
* Assert.state(entity.getId() == null, |
|
|
|
|
* () -> "ID for entity " + entity.getName() + " must not already be initialized"); |
|
|
|
|
* </pre> |
|
|
|
|
* @param expression a boolean expression |
|
|
|
|
* @param messageSupplier a supplier for the exception message to use if the |
|
|
|
|
@ -96,6 +96,8 @@ public abstract class Assert {
@@ -96,6 +96,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert a boolean expression, throwing an {@code IllegalStateException} |
|
|
|
|
* if the expression evaluates to {@code false}. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -136,6 +138,8 @@ public abstract class Assert {
@@ -136,6 +138,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert a boolean expression, throwing an {@code IllegalArgumentException} |
|
|
|
|
* if the expression evaluates to {@code false}. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -174,6 +178,7 @@ public abstract class Assert {
@@ -174,6 +178,7 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that an object is {@code null}. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -197,7 +202,8 @@ public abstract class Assert {
@@ -197,7 +202,8 @@ public abstract class Assert {
|
|
|
|
|
/** |
|
|
|
|
* Assert that an object is not {@code null}. |
|
|
|
|
* <pre class="code"> |
|
|
|
|
* Assert.notNull(clazz, () -> "The class '" + clazz.getName() + "' must not be null"); |
|
|
|
|
* Assert.notNull(entity.getId(), |
|
|
|
|
* () -> "ID for entity " + entity.getName() + " must not be null"); |
|
|
|
|
* </pre> |
|
|
|
|
* @param object the object to check |
|
|
|
|
* @param messageSupplier a supplier for the exception message to use if the |
|
|
|
|
@ -212,6 +218,7 @@ public abstract class Assert {
@@ -212,6 +218,7 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that an object is not {@code null}. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -225,8 +232,8 @@ public abstract class Assert {
@@ -225,8 +232,8 @@ public abstract class Assert {
|
|
|
|
|
* <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre> |
|
|
|
|
* @param text the String to check |
|
|
|
|
* @param message the exception message to use if the assertion fails |
|
|
|
|
* @see StringUtils#hasLength |
|
|
|
|
* @throws IllegalArgumentException if the text is empty |
|
|
|
|
* @see StringUtils#hasLength |
|
|
|
|
*/ |
|
|
|
|
public static void hasLength(@Nullable String text, String message) { |
|
|
|
|
if (!StringUtils.hasLength(text)) { |
|
|
|
|
@ -238,14 +245,15 @@ public abstract class Assert {
@@ -238,14 +245,15 @@ public abstract class Assert {
|
|
|
|
|
* Assert that the given String is not empty; that is, |
|
|
|
|
* it must not be {@code null} and not the empty String. |
|
|
|
|
* <pre class="code"> |
|
|
|
|
* Assert.hasLength(name, () -> "Name for account '" + account.getId() + "' must not be empty"); |
|
|
|
|
* Assert.hasLength(account.getName(), |
|
|
|
|
* () -> "Name for account '" + account.getId() + "' must not be empty"); |
|
|
|
|
* </pre> |
|
|
|
|
* @param text the String to check |
|
|
|
|
* @param messageSupplier a supplier for the exception message to use if the |
|
|
|
|
* assertion fails |
|
|
|
|
* @see StringUtils#hasLength |
|
|
|
|
* @throws IllegalArgumentException if the text is empty |
|
|
|
|
* @since 5.0 |
|
|
|
|
* @see StringUtils#hasLength |
|
|
|
|
*/ |
|
|
|
|
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier) { |
|
|
|
|
if (!StringUtils.hasLength(text)) { |
|
|
|
|
@ -254,6 +262,8 @@ public abstract class Assert {
@@ -254,6 +262,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that the given String is not empty; that is, |
|
|
|
|
* it must not be {@code null} and not the empty String. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -268,8 +278,8 @@ public abstract class Assert {
@@ -268,8 +278,8 @@ public abstract class Assert {
|
|
|
|
|
* <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre> |
|
|
|
|
* @param text the String to check |
|
|
|
|
* @param message the exception message to use if the assertion fails |
|
|
|
|
* @see StringUtils#hasText |
|
|
|
|
* @throws IllegalArgumentException if the text does not contain valid text content |
|
|
|
|
* @see StringUtils#hasText |
|
|
|
|
*/ |
|
|
|
|
public static void hasText(@Nullable String text, String message) { |
|
|
|
|
if (!StringUtils.hasText(text)) { |
|
|
|
|
@ -281,14 +291,15 @@ public abstract class Assert {
@@ -281,14 +291,15 @@ public abstract class Assert {
|
|
|
|
|
* Assert that the given String contains valid text content; that is, it must not |
|
|
|
|
* be {@code null} and must contain at least one non-whitespace character. |
|
|
|
|
* <pre class="code"> |
|
|
|
|
* Assert.hasText(name, () -> "Name for account '" + account.getId() + "' must not be empty"); |
|
|
|
|
* Assert.hasText(account.getName(), |
|
|
|
|
* () -> "Name for account '" + account.getId() + "' must not be empty"); |
|
|
|
|
* </pre> |
|
|
|
|
* @param text the String to check |
|
|
|
|
* @param messageSupplier a supplier for the exception message to use if the |
|
|
|
|
* assertion fails |
|
|
|
|
* @see StringUtils#hasText |
|
|
|
|
* @throws IllegalArgumentException if the text does not contain valid text content |
|
|
|
|
* @since 5.0 |
|
|
|
|
* @see StringUtils#hasText |
|
|
|
|
*/ |
|
|
|
|
public static void hasText(@Nullable String text, Supplier<String> messageSupplier) { |
|
|
|
|
if (!StringUtils.hasText(text)) { |
|
|
|
|
@ -297,6 +308,8 @@ public abstract class Assert {
@@ -297,6 +308,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that the given String contains valid text content; that is, it must not |
|
|
|
|
* be {@code null} and must contain at least one non-whitespace character. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -340,6 +353,7 @@ public abstract class Assert {
@@ -340,6 +353,7 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that the given text does not contain the given substring. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -381,6 +395,8 @@ public abstract class Assert {
@@ -381,6 +395,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that an array contains elements; that is, it must not be |
|
|
|
|
* {@code null} and must contain at least one element. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -429,6 +445,7 @@ public abstract class Assert {
@@ -429,6 +445,7 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that an array contains no {@code null} elements. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -471,6 +488,8 @@ public abstract class Assert {
@@ -471,6 +488,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that a collection contains elements; that is, it must not be |
|
|
|
|
* {@code null} and must contain at least one element. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@ -512,6 +531,8 @@ public abstract class Assert {
@@ -512,6 +531,8 @@ public abstract class Assert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Assert that a Map contains entries; that is, it must not be {@code null} |
|
|
|
|
* and must contain at least one entry. |
|
|
|
|
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
|