Closed daltonfury42 closed 3 years ago
We have different tests on queue and token entity objects done all over the place.
This should be extracted into other methods and use function composition. It is very hard to follow.
Predicate<Queue> isNotPaused() { return queue -> { if (queue.getStatus() == QueueStatus.PAUSED) { throw SQInvalidRequestException.queuePausedException(); } return true; }; } Predicate<Queue> isNotDeleted() { return queue -> { if (queue.getStatus() == QueueStatus.DELETED) { throw SQInvalidRequestException.queueDeletedException(); } return true; }; } Predicate<Queue> isNotFull() { return queue -> { if (queue.isFull()) { throw SQInvalidRequestException.queueDeletedException(); } return true; }; } void validateQueue(Queue queue) { isNotPaused() .and(isNotDeleted()) .and(isNotFull()) .test(queue); }
and then just call validateQueue(queue)
validateQueue(queue)
_Originally posted by @chalx in https://github.com/SimplQ/simplQ-backend/pull/130#discussion_r619428589_
Also explore this: https://github.com/SimplQ/simplQ-backend/pull/130/files#r619404455
We have different tests on queue and token entity objects done all over the place.
This should be extracted into other methods and use function composition. It is very hard to follow.
and then just call
validateQueue(queue)
_Originally posted by @chalx in https://github.com/SimplQ/simplQ-backend/pull/130#discussion_r619428589_