@@ -27,8 +27,7 @@ public class TimeSpecimen<T> implements ISpecimen<T> {
2727 private final Random random ;
2828 private final Context context ;
2929
30- public TimeSpecimen (final SpecimenType <T > type , Context context ) {
31- this .context = context ;
30+ public TimeSpecimen (final SpecimenType <T > type , final Context context ) {
3231 if (type == null ) {
3332 throw new IllegalArgumentException ("type: null" );
3433 }
@@ -43,6 +42,7 @@ public TimeSpecimen(final SpecimenType<T> type, Context context) {
4342
4443 this .type = type ;
4544 this .random = new Random ();
45+ this .context = context ;
4646 }
4747
4848 @ Override
@@ -55,42 +55,41 @@ public T create(final CustomizationContext customizationContext) {
5555 if (Temporal .class .isAssignableFrom (type .asClass ())) {
5656 try {
5757 Method now = type .asClass ().getMethod ("now" , Clock .class );
58- return (T ) now .invoke (null , context .getConfiguration ().getClock ());
58+ return (T ) context . preDefined ( type , now .invoke (null , context .getConfiguration ().getClock () ));
5959 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e ) {
6060 throw new SpecimenException ("Unsupported type: " + type .asClass ());
6161 }
6262 }
6363
6464 if (type .asClass ().equals (java .util .Date .class )) {
65- return (T ) java .sql .Timestamp .valueOf (LocalDateTime .now (context .getConfiguration ().getClock ()));
65+ return (T ) context . preDefined ( type , java .sql .Timestamp .valueOf (LocalDateTime .now (context .getConfiguration ().getClock () )));
6666 }
6767
68-
6968 if (type .asClass ().equals (java .sql .Date .class )) {
70- return (T ) java .sql .Date .valueOf (LocalDateTime .now (context .getConfiguration ().getClock ()).toLocalDate ());
69+ return (T ) context . preDefined ( type , java .sql .Date .valueOf (LocalDateTime .now (context .getConfiguration ().getClock ()).toLocalDate () ));
7170 }
7271
7372 if (type .asClass ().equals (MonthDay .class )) {
74- return (T ) MonthDay .now (context .getConfiguration ().getClock ());
73+ return (T ) context . preDefined ( type , MonthDay .now (context .getConfiguration ().getClock () ));
7574 }
7675
7776 if (type .asClass ().equals (JapaneseEra .class )) {
78- return (T ) JapaneseEra .values ()[random .nextInt (JapaneseEra .values ().length )];
77+ return (T ) context . preDefined ( type , JapaneseEra .values ()[random .nextInt (JapaneseEra .values ().length )]) ;
7978 }
8079
8180 if (type .asClass ().equals (ZoneOffset .class )) {
82- return (T ) ZoneOffset .ofHours (new Random ().nextInt (19 ));
81+ return (T ) context . preDefined ( type , ZoneOffset .ofHours (new Random ().nextInt (19 ) ));
8382 }
8483 if (type .asClass ().equals (Duration .class )) {
85- return (T ) Duration .ofDays (random .nextInt ());
84+ return (T ) context . preDefined ( type , Duration .ofDays (random .nextInt () ));
8685 }
8786
8887 if (type .asClass ().equals (Period .class )) {
89- return (T ) Period .ofDays (random .nextInt ());
88+ return (T ) context . preDefined ( type , Period .ofDays (random .nextInt () ));
9089 }
9190
9291 if (type .asClass ().equals (ZoneId .class )) {
93- return (T ) ZoneId .of (ZoneId .getAvailableZoneIds ().iterator ().next ());
92+ return (T ) context . preDefined ( type , ZoneId .of (ZoneId .getAvailableZoneIds ().iterator ().next () ));
9493 }
9594
9695 throw new SpecimenException ("Unsupported type: " + type .asClass ());
0 commit comments