Frage

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>/...)"

War es hilfreich?

Lösung

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);
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top