assert.notNull

今天我做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必须不能为空。如果为空就抛出异常。

posted @ 2017-06-05 02:56  Walker竹  阅读(3691)  评论(0编辑  收藏  举报