@Test void whenNoConcreteTypeIsFound_thenShouldThrowAnInstantiationError() { Mockito.when(context.getParameters().isScanClasspathForConcreteTypes()).thenReturn(true); assertThatThrownBy(() -> objenesisObjectFactory.createInstance(AbstractFoo.class, context)).isInstanceOf(InstantiationError.class); }
@Override public <T> T createInstance(Class<T> type, RandomizerContext context) { if (context.getParameters().isScanClasspathForConcreteTypes() && isAbstract(type)) { Class<?> randomConcreteSubType = randomElementOf(getPublicConcreteSubTypesOf((type))); if (randomConcreteSubType == null) { throw new InstantiationError("Unable to find a matching concrete subtype of type: " + type + " in the classpath"); } else { return (T) createNewInstance(randomConcreteSubType); } } else { try { return createNewInstance(type); } catch (Error e) { throw new ObjectCreationException("Unable to create an instance of type: " + type, e); } } }
ObjenesisObjectFactory implements ObjectFactory { @Override public <T> T createInstance(Class<T> type, RandomizerContext context) { if (context.getParameters().isScanClasspathForConcreteTypes() && isAbstract(type)) { Class<?> randomConcreteSubType = randomElementOf(getPublicConcreteSubTypesOf((type))); if (randomConcreteSubType == null) { throw new InstantiationError("Unable to find a matching concrete subtype of type: " + type + " in the classpath"); } else { return (T) createNewInstance(randomConcreteSubType); } } else { try { return createNewInstance(type); } catch (Error e) { throw new ObjectCreationException("Unable to create an instance of type: " + type, e); } } } }
ObjenesisObjectFactory implements ObjectFactory { @Override public <T> T createInstance(Class<T> type, RandomizerContext context) { if (context.getParameters().isScanClasspathForConcreteTypes() && isAbstract(type)) { Class<?> randomConcreteSubType = randomElementOf(getPublicConcreteSubTypesOf((type))); if (randomConcreteSubType == null) { throw new InstantiationError("Unable to find a matching concrete subtype of type: " + type + " in the classpath"); } else { return (T) createNewInstance(randomConcreteSubType); } } else { try { return createNewInstance(type); } catch (Error e) { throw new ObjectCreationException("Unable to create an instance of type: " + type, e); } } }  }
ObjenesisObjectFactory implements ObjectFactory { @Override public <T> T createInstance(Class<T> type, RandomizerContext context) { if (context.getParameters().isScanClasspathForConcreteTypes() && isAbstract(type)) { Class<?> randomConcreteSubType = randomElementOf(getPublicConcreteSubTypesOf((type))); if (randomConcreteSubType == null) { throw new InstantiationError("Unable to find a matching concrete subtype of type: " + type + " in the classpath"); } else { return (T) createNewInstance(randomConcreteSubType); } } else { try { return createNewInstance(type); } catch (Error e) { throw new ObjectCreationException("Unable to create an instance of type: " + type, e); } } }  @Override T createInstance(Class<T> type, RandomizerContext context); }
ObjenesisObjectFactory implements ObjectFactory { @Override public <T> T createInstance(Class<T> type, RandomizerContext context) { if (context.getParameters().isScanClasspathForConcreteTypes() && isAbstract(type)) { Class<?> randomConcreteSubType = randomElementOf(getPublicConcreteSubTypesOf((type))); if (randomConcreteSubType == null) { throw new InstantiationError("Unable to find a matching concrete subtype of type: " + type + " in the classpath"); } else { return (T) createNewInstance(randomConcreteSubType); } } else { try { return createNewInstance(type); } catch (Error e) { throw new ObjectCreationException("Unable to create an instance of type: " + type, e); } } }  @Override T createInstance(Class<T> type, RandomizerContext context);  }