# apiAssert
**Repository Path**: chaibao/api-assert
## Basic Information
- **Project Name**: apiAssert
- **Description**: 校验、断言小框架
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2022-10-18
- **Last Updated**: 2022-10-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Api-Assert 介绍
- [github地址](https://github.com/min1854/apiAssert)
- [gitee地址](https://gitee.com/min1854/api-assert)
api-assert 是一个经量级的小小框架,或者说是一个工具类,用于提供在日常开发中,经常需要一些条件判断,如果条件成立需要抛出异常编写的重复,api-assert 提供了链式校验的方式,目前提供了几种检查器:
- com.old.apiAssert.check.FirstApiAssert 第一检查器,检查器可以提供链式编程,并且当第一个条件成立之后就不会再替换异常信息,并由调用者最终决定是否抛出异常
- com.old.apiAssert.check.FunctionApiAssert 由调用者提供异常对象,当条件成立时会立刻抛出异常
- com.old.apiAssert.check.OperateApiAssert 与 Optional 类的思想类似,用于提供对一个对象的校验与对象内部属性的校验,支持 Lambda,并支持 FunctionApiAssert 检查器的功能。
- com.old.apiAssert.check.ReflectionApiAssert 调用者传入异常类型,检查器当条件成立之后会立刻抛出异常
# 用例
添加 maven 依赖
```xml
io.github.min1854
apiAssert
2.0.0
```
# 注意
2.0.0 版本与之前的版本不太兼容,使用需要注意。2.0 版本将框架进行了重写,使用了继承方式,抛弃了原有的复合方式。并重新抽取了父类与规范。
# 版本
## 2.0.0
因 2.0 版本将框架进行了重构,所以版本号使用新的大版本号。2.0.0 相比之前的版本,扩展性更高,重复代码更少。并且提供了 Enum 作为消息内容的校验器。
- 重构代码
- 新增枚举校验器 EnumOperationApiAssert、EnumFunctionApiAssert
- OperationApiAssert 增加 校验对象、标准校验器的 then 方法
# 使用
```java
public class Demo {
public OperateApiAssert createAssert() {
TestEntity entity = new TestEntity();
entity.setId(1);
entity.setDeleteFlag(false);
return OperateApiAssert.create(entity, NoArgConstructorException::new);
}
@Test(expected = ApiAssertException.class)
public void testThen() {
OperateApiAssert