今天我做JUnit關於MySQL測試時發現,類似於assertNull(tu)之類的代碼不知道什麼意思,因此稍微總結如下。 org.springframework.util.AssertAssert翻譯為中文為"斷言".大概來說,就是斷定某一個實際的值就為自己預期想得到的,如果不一樣就拋出異常. s ...
今天我做JUnit關於MySQL測試時發現,類似於assertNull(tu)之類的代碼不知道什麼意思,因此稍微總結如下。
org.springframework.util.Assert
Assert翻譯為中文為"斷言".
大概來說,就是斷定某一個實際的值就為自己預期想得到的,如果不一樣就拋出異常.
spring源碼如下:
/**
* Assert that an object is not <code>null</code> .
* <pre class="code">Assert.notNull(clazz, "The class must not be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is <code>null</code>
*/
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
該函數的意思是傳入的object必須不能為空。如果為空就拋出異常。