Assert的使用和简单解释
Assert 的简单使用
Document d = Jsoup.connect("http://www.baidu.com").get();
Assert.notNull(d, "d不为空才放行");
System.out.println(d.title());
Assert.isNull(d.parentNode(), "d.parentNode()为null才放行");
System.out.println(d.parentNode());
Assert.isTrue(d.outputSettings().prettyPrint(), "d.outputSettings().prettyPrint()是真的才放行");
System.out.println(d.outputSettings().prettyPrint());
Assert.notEmpty(d.childNodes(), "d.childNodes()不为空放行,Collection的子类");
System.out.println(d.childNodes().size());
Assert.hasLength(d.title(), "d.title()必须有长度才放行");
System.out.println(d.title().length());
Assert.hasText(d.title(), "d.title()必须有内容才放行");
System.out.println(d.title().length());
Assert.isInstanceOf(Document.class, d, "d必须是Document类型的才放行");
System.out.println(d.getClass());
Assert.isAssignable(Element.class, d.getClass(), "d.getClass()必须是Element的子类或者实现类才放行");
System.out.println(d.getClass());