3-1-3-author-book excercise: added correct exception handling for testing of duplicate book ISBN #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ifBook
ID generation strategy is default (AUTO
), but it won't pass the test ifBook
ID generation strategy value isIDENTITY
. Furthermore, it's really unobvious why the test is failing, butConstraintViolationException
will be always there:Book
ID generation strategy is the default (AUTO
), hibernate will throwRollbackException
, but its cause will beConstraintViolationException
.Book
ID generation strategy isIDENTITY
, hibernate will throwConstraintViolationException
.From my point of view third test
saveBookWithDuplicateIsbn()
should check if any exception mentioned above is the exception thrown byentityManager.persist(...)
method.