I have this Junit test with is using hateoas 1.0:
@Test
public void processUserExceptionThrown() {
when(userService.processAccount(request, account))
.thenThrow(new RuntimeException());
try {
userService.processAccount(request);
fail("Exception was expected to be thrown, but was not");
} catch (InternalException ex) {
assertEquals(Link.REL_SELF, ex.getSelfLink().getRel());
}
}
I tried to migrate the code to latest Spring and hateoas:
@Test
public void processUserExceptionThrown() {
when(userService.processAccount(request, account))
.thenThrow(new RuntimeException());
try {
userService.processAccount(request);
fail("Exception was expected to be thrown, but was not");
} catch (InternalException ex) {
assertEquals(Link.of("url", IanaLinkRelations.SELF), ex.getSelfLink().getRel());
}
}
The new assertion
assertEquals(Link.of("url", IanaLinkRelations.SELF), ex.getSelfLink().getRel());
fails with
.opentest4j.AssertionFailedError: expected: <<url>;rel="self"> but was: <self>
How can I migrate the code properly without changing the end result?
I have this Junit test with is using hateoas 1.0:
@Test
public void processUserExceptionThrown() {
when(userService.processAccount(request, account))
.thenThrow(new RuntimeException());
try {
userService.processAccount(request);
fail("Exception was expected to be thrown, but was not");
} catch (InternalException ex) {
assertEquals(Link.REL_SELF, ex.getSelfLink().getRel());
}
}
I tried to migrate the code to latest Spring and hateoas:
@Test
public void processUserExceptionThrown() {
when(userService.processAccount(request, account))
.thenThrow(new RuntimeException());
try {
userService.processAccount(request);
fail("Exception was expected to be thrown, but was not");
} catch (InternalException ex) {
assertEquals(Link.of("url", IanaLinkRelations.SELF), ex.getSelfLink().getRel());
}
}
The new assertion
assertEquals(Link.of("url", IanaLinkRelations.SELF), ex.getSelfLink().getRel());
fails with
.opentest4j.AssertionFailedError: expected: <<url>;rel="self"> but was: <self>
How can I migrate the code properly without changing the end result?
Share Improve this question edited Mar 11 at 21:03 Geba 2,22311 silver badges16 bronze badges asked Mar 11 at 11:29 Peter PenzovPeter Penzov 1,628156 gold badges501 silver badges908 bronze badges1 Answer
Reset to default 1In your old code, you have asserted that a relation (Link.REL_SELF
) is equal to a relation (ex.getSelfLink().getRel()
)
In your new code, you assert that a link (Link.of("url", IanaLinkRelations.SELF)
) is equal to a relation (ex.getSelfLink().getRel()
).
Change your new code so expected and actual values are of the same type - both are relations (LinkRelation
).
assertEquals(IanaLinkRelations.SELF, ex.getSelfLink().getRel());