Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Assert.Assert.equal具有多个预期可能性,其中一个可能性始终为空异常错误_Java_Exception_Logic_Assert - Fatal编程技术网

Java Assert.Assert.equal具有多个预期可能性,其中一个可能性始终为空异常错误

Java Assert.Assert.equal具有多个预期可能性,其中一个可能性始终为空异常错误,java,exception,logic,assert,Java,Exception,Logic,Assert,我遇到了一个让我发疯的Java问题。我试图对两个可能的响应之一断言一个对象 Assert.assertEquals("Card status state does not match", true, statusResource.getActive().equals(response.path("status.active")) || statusResource.getActive().equals(response.path("cards[0].status.

我遇到了一个让我发疯的Java问题。我试图对两个可能的响应之一断言一个对象

    Assert.assertEquals("Card status state does not match", true,
    statusResource.getActive().equals(response.path("status.active"))
        || statusResource.getActive().equals(response.path("cards[0].status.active")));
简单的英语逻辑如下: 1) 如果在statusResource对象中找到的活动状态等于: a) 在response.path(“status.active”)中找到的活动状态,或 b) 在response.path(“卡[0].status.active”)中找到的活动状态

如果statusResource对象与2个选项中的任何一个都不匹配,则返回错误消息“卡状态不匹配”

问题是选项1或2的response.path结果之一将抛出一个错误“
方法抛出'java.lang.IllegalArgumentException'异常。
”,因为相应的值不存在

当我知道其中一个值总是会导致异常错误时,如何执行预期的断言

问题出在BKAC(键盘和椅子之间) 以下是解决方案:

      if (statusResource.getVerificationType().getMicro() != null) {

    assertTrue("Card verification Micro Type does not match",
        response.path("status.verificationType.micro").toString().equals("{}")
        || Integer.valueOf(statusResource.getVerificationType().getMicro().getAmount()
            .toString()).equals(response.path("status.verificationType.micro.amount")));
  }

我宁愿使用简单的if-else循环