Dev/weird test#16
Conversation
| static jobOffer(args = [:]) { | ||
| new JobOffer( | ||
| 'id' in args.keySet() ? args.id as String : 'test-id', | ||
| 'title' in args.keySet() ? args.title as String : 'test-title', | ||
| 'companyName' in args.keySet() ? args.companyName as String : 'test-company', | ||
| 'experience' in args.keySet() ? args.experience as String : 'test-experience', | ||
| 'skills' in args.keySet() ? args.skills as List<Skill> : [], | ||
| 'employmentType' in args.keySet() ? args.employmentType as List<EmploymentType> : [], | ||
| 'remote' in args.keySet() ? args.remote as boolean : true | ||
| ) | ||
| } |
There was a problem hiding this comment.
What do you think about simplifying this code?
| static jobOffer(args = [:]) { | |
| new JobOffer( | |
| 'id' in args.keySet() ? args.id as String : 'test-id', | |
| 'title' in args.keySet() ? args.title as String : 'test-title', | |
| 'companyName' in args.keySet() ? args.companyName as String : 'test-company', | |
| 'experience' in args.keySet() ? args.experience as String : 'test-experience', | |
| 'skills' in args.keySet() ? args.skills as List<Skill> : [], | |
| 'employmentType' in args.keySet() ? args.employmentType as List<EmploymentType> : [], | |
| 'remote' in args.keySet() ? args.remote as boolean : true | |
| ) | |
| } | |
| static jobOffer(args = [:]) { | |
| new JobOffer( | |
| args.id as String ?: 'test-id', | |
| args.title as String ?: 'test-title', | |
| args.companyName as String ?: 'test-company', | |
| args.experience as String ?: 'test-experience', | |
| args.skills as List<Skill> ?: [], | |
| args.employmentType as List<EmploymentType> ?: [], | |
| args.remote as boolean ?: true | |
| ) | |
| } |
| 'skills' in args.keySet() ? args.skills as List<Skill> : [], | ||
| 'employmentType' in args.keySet() ? args.employmentType as List<EmploymentType> : [], |
There was a problem hiding this comment.
I suggest filling these fields with additional data instead of empty lists.
| ) | ||
| } | ||
|
|
||
| static List<JobOffer> createListJobOffers(int count) { |
There was a problem hiding this comment.
The name of the function "createListJobOffers" may not reflect the intent well, as it may be associated with creating a list and storing it in a database, which is not the case here. I propose the same naming convention as above ie: jobOffersList
| static List<JobOffer> createListJobOffers(int count) { | ||
| return (1..count).collect { _ -> | ||
| jobOffer() | ||
| } | ||
| } |
There was a problem hiding this comment.
You can simplify things a bit
| static List<JobOffer> createListJobOffers(int count) { | |
| return (1..count).collect { _ -> | |
| jobOffer() | |
| } | |
| } | |
| static jobOfferList(int count) { | |
| (1..count).collect { jobOffer() } | |
| } |
|
|
||
| def "publish should chunk job offers and publish them to the queue"() { | ||
| given: | ||
| List<JobOffer> jobOffers = JobFixture.createListJobOffers(10) |
There was a problem hiding this comment.
Please use static import
import static it.move2.agent.application.JobFixture.createListJobOffers| List<JobOffer> jobOffers = JobFixture.createListJobOffers(10) | |
| def jobOffers = createListJobOffers(10) |
| jobBoard1 = Mock() | ||
| jobBoard2 = Mock() | ||
| queue = Mock() | ||
| objectMapper = new ObjectMapper() |
There was a problem hiding this comment.
How about using the same ObjectMapper that is used in the code from the Bootstrap class? Currently, this ObjectMapper is configured a bit different in tests than in the production version, which may not reveal all the bugs.
| def jobs1 = [JobFixture.jobOffer(), JobFixture.jobOffer()] | ||
|
|
||
| jobBoard1.getJobs() >> jobs1 | ||
| jobBoard2.getJobs() >> { throw new RuntimeException("Test error message") } |
There was a problem hiding this comment.
How is error handling carried out in the application? I haven't seen anything throwing an exception.
| jobBoard2.getJobs() >> { throw new RuntimeException("Test error message") } | ||
|
|
||
| when: | ||
| updater.execute() |
There was a problem hiding this comment.
| updater.execute() | |
| updater.execute() |
|
|
||
| then: | ||
| thrown(RuntimeException) | ||
| 0 * queue.pub(_) >> {} |
There was a problem hiding this comment.
| 0 * queue.pub(_) >> {} | |
| 0 * queue.pub(_) |
Implement tests for application package