@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); }
@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 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 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); }
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); }
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);  }