@Test public void non_factory_method_request_returns_no_specimen() { Object specimen = this.relay.create(String.class, mockSpecimenContext); assertEquals(new NoSpecimen(), specimen); }
@Override public Object create(Object request, SpecimenContext context) { if(!(request instanceof FactoryMethodRequest)) { return new NoSpecimen(); } FactoryMethodRequest factoryMethodRequest = (FactoryMethodRequest)request; Method method = factoryMethodRequest.getMethod(); List<Object> parameters = ParameterUtils.getMethodParameters(method, factoryMethodRequest.getContainingType(), context); if(parameters == null) { return new NoSpecimen(); } try { Object[] paramsArray = parameters.toArray(new Object[parameters.size()]); return method.invoke(null, paramsArray); } catch (Exception e) { throw new ObjectCreationException(String.format("Unable to invoke factory method %s", method), e); } }
FactoryMethodRelay implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if(!(request instanceof FactoryMethodRequest)) { return new NoSpecimen(); } FactoryMethodRequest factoryMethodRequest = (FactoryMethodRequest)request; Method method = factoryMethodRequest.getMethod(); List<Object> parameters = ParameterUtils.getMethodParameters(method, factoryMethodRequest.getContainingType(), context); if(parameters == null) { return new NoSpecimen(); } try { Object[] paramsArray = parameters.toArray(new Object[parameters.size()]); return method.invoke(null, paramsArray); } catch (Exception e) { throw new ObjectCreationException(String.format("Unable to invoke factory method %s", method), e); } } }
FactoryMethodRelay implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if(!(request instanceof FactoryMethodRequest)) { return new NoSpecimen(); } FactoryMethodRequest factoryMethodRequest = (FactoryMethodRequest)request; Method method = factoryMethodRequest.getMethod(); List<Object> parameters = ParameterUtils.getMethodParameters(method, factoryMethodRequest.getContainingType(), context); if(parameters == null) { return new NoSpecimen(); } try { Object[] paramsArray = parameters.toArray(new Object[parameters.size()]); return method.invoke(null, paramsArray); } catch (Exception e) { throw new ObjectCreationException(String.format("Unable to invoke factory method %s", method), e); } }  }
FactoryMethodRelay implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if(!(request instanceof FactoryMethodRequest)) { return new NoSpecimen(); } FactoryMethodRequest factoryMethodRequest = (FactoryMethodRequest)request; Method method = factoryMethodRequest.getMethod(); List<Object> parameters = ParameterUtils.getMethodParameters(method, factoryMethodRequest.getContainingType(), context); if(parameters == null) { return new NoSpecimen(); } try { Object[] paramsArray = parameters.toArray(new Object[parameters.size()]); return method.invoke(null, paramsArray); } catch (Exception e) { throw new ObjectCreationException(String.format("Unable to invoke factory method %s", method), e); } }  @Override Object create(Object request, SpecimenContext context); }
FactoryMethodRelay implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if(!(request instanceof FactoryMethodRequest)) { return new NoSpecimen(); } FactoryMethodRequest factoryMethodRequest = (FactoryMethodRequest)request; Method method = factoryMethodRequest.getMethod(); List<Object> parameters = ParameterUtils.getMethodParameters(method, factoryMethodRequest.getContainingType(), context); if(parameters == null) { return new NoSpecimen(); } try { Object[] paramsArray = parameters.toArray(new Object[parameters.size()]); return method.invoke(null, paramsArray); } catch (Exception e) { throw new ObjectCreationException(String.format("Unable to invoke factory method %s", method), e); } }  @Override Object create(Object request, SpecimenContext context);  }