Skip to content

3-1-3-author-book excercise: added correct exception handling for testing of duplicate book ISBN #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

JoshukLite
Copy link
Contributor

In task 3-1-3-author-book it's not clearly mentioned that the Book entity should have @GeneratedValue annotation with default (AUTO) strategy. Also, there are no tests (AuthorBookMappingTest.java) where this strategy is checked.

The third test (saveBookWithDuplicateIsbn()) will work just fine if Book ID generation strategy is default (AUTO), but it won't pass the test if Book ID generation strategy value is IDENTITY. Furthermore, it's really unobvious why the test is failing, but ConstraintViolationException will be always there:

  1. In case when Book ID generation strategy is the default (AUTO), hibernate will throw RollbackException, but its cause will be ConstraintViolationException.
  2. In case the Book ID generation strategy is IDENTITY, hibernate will throw ConstraintViolationException.

From my point of view third test saveBookWithDuplicateIsbn() should check if any exception mentioned above is the exception thrown by entityManager.persist(...) method.

* when book ID generation strategy is IDENTITY it throws ConstraintViolationException instead of RollbackException
@JoshukLite JoshukLite closed this Jan 22, 2024
@JoshukLite JoshukLite deleted the completed-3-1-3-test-improvement branch January 22, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant