AssertJ可以验证值是特定数据类型吗?

问题描述

我已经浏览了网络,但是努力寻找一种方法来使AssertJ验证数据类型,例如,我想验证JSON响应中的值是长数据类型还是不是double:

类似这样的东西:

JsonPath jp = response.jsonPath();
long money= jp.get("amount.money");
Assertions.assertthat(money).isNotDouble; //isNotDouble is not a valid method,but I want to achieve something similar to this. isLong also does not exist.

是否可以为money创建像正则表达式或样式的样式并将其用作验证点?

解决方法

这种方法存在。

Assertions.assertThat(table).isInstanceOf(Long.class);
Assertions.assertThat(table).isInstanceOfAny(Long.class,Number.class);
Assertions.assertThat(table).isExactlyInstanceOf(Long.class);
Assertions.assertThat(table).isInstanceOfSatisfying(Long.class,num -> {
        
});

并且有notNot变体。