I am failing to understand why my test case is failing even when the message is correct. Has anyone run into this issue before? Could it be regex matching? If so, then how to fix it?

The exception was thrown with the wrong message: expected "'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)" but got "'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)"

有帮助吗?

解决方案

Yes it expects a regex. You need to escape the brackets (and the dots but it makes little difference in this case). The test below passes:

@Test(expectedExceptions = RuntimeException.class,
      expectedExceptionsMessageRegExp = "'authority' Uri should have at least one segment in the path \\(i.e. https://<host>/<path>/...\\)")
public void test() {
    String input = "'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)";
    throw new RuntimeException(input);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top