### Question:
ClassToFactoryMethodRelay implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if (!this.specification.isSatisfiedBy(request)) { return new NoSpecimen(); } if(!(request instanceof SpecimenType)) { return new NoSpecimen(); } SpecimenType specimenType = (SpecimenType)request; List<Method> factoryMethods = this.factoryMethodQuery.getFactoryMethodsForType(specimenType); if (factoryMethods.isEmpty()) { return new NoSpecimen(); } for (Method method : factoryMethods) { try { Object specimen = context.resolve(new FactoryMethodRequest(method, specimenType)); if (!(specimen instanceof NoSpecimen)) { return specimen; } } catch (ObjectCreationException e) { } } return new NoSpecimen(); } ClassToFactoryMethodRelay(FactoryMethodQuery factoryMethodQuery, Specification specification); @Override Object create(Object request, SpecimenContext context);  }### Answer:
@Test public void if_request_does_not_satisfy_specification_returns_no_specimen() { when(this.mockSpecification.isSatisfiedBy(any(Object.class))).thenReturn(false); Object result = this.relay.create(TypeWithFactoryMethod.class, mockSpecimenContext); assertEquals(new NoSpecimen(), result); }
@Test public void if_factory_method_query_returns_empty_create_returns_no_specimen() { when(this.mockFactoryMethodQuery.getFactoryMethodsForType(SpecimenType.of(TypeWithFactoryMethod.class))).thenReturn(Collections.<Method>emptyList()); Object result = this.relay.create(TwoConstructorType.class, mockSpecimenContext); assertEquals(new NoSpecimen(), result); }
@Test public void returns_result_of_context_resolve() { Object contextResult = new Object(); when(mockSpecimenContext.resolve(any(Object.class))).thenReturn(contextResult); Object result = this.relay.create(SpecimenType.of(TypeWithFactoryMethod.class), mockSpecimenContext); assertSame(contextResult, result); }