Replies: 2 comments 2 replies
-
There were a couple of similar discussions recently, but your use case is somewhat more complicated :) I'm not sure what you described can be easily achieved. It'll require some experimenting and might end up being too complicated to be worth it. I think your best bet is to construct the objects manually. Just in case, below are the other posts. I'll follow up if I can think of a good approach. |
Beta Was this translation helpful? Give feedback.
-
As for my particular case, I think I'm leaving the discussion open for now, and I will continue to search for a solution less convoluted. |
Beta Was this translation helpful? Give feedback.
-
The POJO I'm instancio-ating is a resource that can be created, modified and removed subsequently. In doing so, it stores the instants of when that was done and by whom. There are a few of simple rules, however:
(createdAt != null) && (createdBy != null)
modifiedAt >= createdAt
(removedAt != null) -> (modifiedAt == removedAt)
Resource definition for a better understanding
Bearing this in mind, I want every second instance to be modified, and every sixth of those to be removed. The problem arises where I want the creation instant be set necessarily, and the modification time to depend on both
createdAt
andmodifiedBy
.Before introduction of
createdAt
, my approach was to generatemodifiedBy
, choosing one ofnull
, or"admin"
. Then based on the value ofmodifiedBy
—should it be non-null—I assigned a custom stateful generator. On the first call it returns a random instant formodifiedAt
, stores the returned value, and on the subsequent call returns that stored value with a probability of 1/6.Now I also want to restrict
JavaTimeTemporalGenerator#min
to only get instants aftercreatedAt
, so as not to set amodifiedAt
beforecreatedAt
, but I can't access the actualcreatedAt
.I was thinking along the lines of writing my own
InstantGenerator
, which would store the last returnedcreatedAt
in something likeAtomicReference
, and refer to that in the generator ofmodifiedAt
/removedAt
. However, with this approach I would probably have to test my tests. 😅Beta Was this translation helpful? Give feedback.
All reactions