I am building a REST service for a Q/A website. When users ask question, they can tag them with keywords(like java for my question here). So if the tagged keyword is already under the Topic table, then the question will be tagged to that topic otherwise the tag will be created under topic table and then the question will be tagged with that. I hope the requirement is understood.Dave Tolls wrote:Optional aside, I'm a bit confused about this test.
It looks to me like the test does not have a guaranteed starting setup (that is the Topic may or may not already exist in the test environment).
That strikes me as a a bit odd.
Campbell Ritchie wrote: Also, how are you changing the findByName() method to change from returning Topic to Optional<Topic>? What is wrong with a predicate method to test whether that Topic already exists?
Will try it. BTW, is it a good practice to handle such requirements?Stephan wrote:Why not just save the entity and if there's already an entity with that name, you get an exception. That will save you a round-trip to the database.
The Ids for Topic are surrogate integer keys generated by MYSQL. It will be easy to index the surrogated keys w.r.t string values (just my thoughts). Would love to here your thoughts.Stephan wrote:By the way, why does the entity have an ID if it already has a unique name? The ID is superfluous and just plain cumbersome.
Puspender Tanwar wrote:I am building a REST service for a Q/A website. When users ask question, they can tag them with keywords(like java for my question here). So if the tagged keyword is already under the Topic table, then the question will be tagged to that topic otherwise the tag will be created under topic table and then the question will be tagged with that. I hope the requirement is understood.
But my test is for this condition only. Situation for 'topic' not exists.Dave Tolls wrote: one for where it doesn't
Puspender Tanwar wrote:But my test is for this condition only. Situation for 'topic' not exists.
Stephan van Hulst wrote:By the way, why does the entity have an ID if it already has a unique name? The ID is superfluous and just plain cumbersome.
There are worse crimes than burning books. One of them is not reading them. Ray Bradbury
Climb the rope! CLIMB THE ROPE! You too tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|