If the value you're getting from fromXpath
is a String
, but it may be a String
that can be parsed as a long
, just match everything as a String
.
That is, you're not missing many real problems when you change:
assertThat(a, is("abc"));
assertThat(Long.parseLong(b), is(123L));
for:
assertThat(a, is("abc"));
assertThat(b, is("123"));
So use the latter.
(Using the latter will also catch a few errors, like unexpected leading zeroes.)