springframework的Assert功能举例
作者:互联网
import com.google.common.collect.Lists; import com.shein.dms.common.BasicCase; import lombok.extern.slf4j.Slf4j; import org.springframework.util.Assert; import org.testng.annotations.Test; /** * @author :gongxr * @description:测试springframework的Assert功能 */ @Slf4j public class TestAssert extends BasicCase { String object = null; String a = "abc"; String b = "b"; @Test public void notNull() throws Exception { Assert.notNull(object, "不能为null"); } @Test public void isTrue() throws Exception { Assert.isTrue(false, "不为真!"); } @Test public void notEmpty() throws Exception { Assert.notEmpty(Lists.newArrayList(), "列表不能为空!"); } @Test public void doesNotContain() throws Exception { boolean flag = a.contains(b); log.info("a.contains(b):{}", flag); Assert.doesNotContain(a, b, "a中不能含有b"); } @Test public void hasText() throws Exception { Assert.hasText(" ", "不能为null或空格!"); } }
标签:Exception,springframework,throws,Assert,举例,Test,import,public 来源: https://www.cnblogs.com/gongxr/p/16360947.html