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或空格!");
    }

}
复制代码

 

posted @   星瑞  阅读(60)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示