@Override public Object create(Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } SpecimenType<?> type = (SpecimenType) request; if (!BasePeriod.class.isAssignableFrom(type.getRawType())) { return new NoSpecimen(); } Duration duration = (Duration) context.resolve(Duration.class); Period period = duration.toPeriod(); try { return type.getRawType().getDeclaredConstructor(Object.class).newInstance(period); } catch (Exception e) { e.printStackTrace(); return new NoSpecimen(); } }