@Test public void if_constructor_query_returns_empty_create_returns_no_specimen() { when(this.mockConstructorQuery.getConstructorsForClass(TwoConstructorType.class)).thenReturn(new ArrayList<Constructor<?>>()); Object result = this.relay.create(TwoConstructorType.class, mockSpecimenContext); assertEquals(new NoSpecimen(), result); }
@Override public Object create(final Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } if (!this.specification.isSatisfiedBy(request)) { return new NoSpecimen(); } SpecimenType specimenType = (SpecimenType)request; Class rawTypeClass = specimenType.getRawType(); if (rawTypeClass.isInterface() || Modifier.isAbstract(rawTypeClass.getModifiers())) { return new NoSpecimen(); } List<Constructor<?>> constructors = constructorQuery.getConstructorsForClass(rawTypeClass); if (constructors == null || constructors.isEmpty()) { return new NoSpecimen(); } for (Constructor constructor : constructors) { try { GenericConstructorRequest constructorRequest = new GenericConstructorRequest(constructor, specimenType); Object specimen = context.resolve(constructorRequest); if (!(specimen instanceof NoSpecimen)) { return specimen; } } catch (ObjectCreationException e) { } } return new NoSpecimen(); }
ClassToConstructorRelay implements SpecimenBuilder { @Override public Object create(final Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } if (!this.specification.isSatisfiedBy(request)) { return new NoSpecimen(); } SpecimenType specimenType = (SpecimenType)request; Class rawTypeClass = specimenType.getRawType(); if (rawTypeClass.isInterface() || Modifier.isAbstract(rawTypeClass.getModifiers())) { return new NoSpecimen(); } List<Constructor<?>> constructors = constructorQuery.getConstructorsForClass(rawTypeClass); if (constructors == null || constructors.isEmpty()) { return new NoSpecimen(); } for (Constructor constructor : constructors) { try { GenericConstructorRequest constructorRequest = new GenericConstructorRequest(constructor, specimenType); Object specimen = context.resolve(constructorRequest); if (!(specimen instanceof NoSpecimen)) { return specimen; } } catch (ObjectCreationException e) { } } return new NoSpecimen(); } }
ClassToConstructorRelay implements SpecimenBuilder { @Override public Object create(final Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } if (!this.specification.isSatisfiedBy(request)) { return new NoSpecimen(); } SpecimenType specimenType = (SpecimenType)request; Class rawTypeClass = specimenType.getRawType(); if (rawTypeClass.isInterface() || Modifier.isAbstract(rawTypeClass.getModifiers())) { return new NoSpecimen(); } List<Constructor<?>> constructors = constructorQuery.getConstructorsForClass(rawTypeClass); if (constructors == null || constructors.isEmpty()) { return new NoSpecimen(); } for (Constructor constructor : constructors) { try { GenericConstructorRequest constructorRequest = new GenericConstructorRequest(constructor, specimenType); Object specimen = context.resolve(constructorRequest); if (!(specimen instanceof NoSpecimen)) { return specimen; } } catch (ObjectCreationException e) { } } return new NoSpecimen(); } ClassToConstructorRelay(ConstructorQuery constructorQuery, Specification specification); }
ClassToConstructorRelay implements SpecimenBuilder { @Override public Object create(final Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } if (!this.specification.isSatisfiedBy(request)) { return new NoSpecimen(); } SpecimenType specimenType = (SpecimenType)request; Class rawTypeClass = specimenType.getRawType(); if (rawTypeClass.isInterface() || Modifier.isAbstract(rawTypeClass.getModifiers())) { return new NoSpecimen(); } List<Constructor<?>> constructors = constructorQuery.getConstructorsForClass(rawTypeClass); if (constructors == null || constructors.isEmpty()) { return new NoSpecimen(); } for (Constructor constructor : constructors) { try { GenericConstructorRequest constructorRequest = new GenericConstructorRequest(constructor, specimenType); Object specimen = context.resolve(constructorRequest); if (!(specimen instanceof NoSpecimen)) { return specimen; } } catch (ObjectCreationException e) { } } return new NoSpecimen(); } ClassToConstructorRelay(ConstructorQuery constructorQuery, Specification specification); @Override Object create(final Object request, SpecimenContext context); }
ClassToConstructorRelay implements SpecimenBuilder { @Override public Object create(final Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } if (!this.specification.isSatisfiedBy(request)) { return new NoSpecimen(); } SpecimenType specimenType = (SpecimenType)request; Class rawTypeClass = specimenType.getRawType(); if (rawTypeClass.isInterface() || Modifier.isAbstract(rawTypeClass.getModifiers())) { return new NoSpecimen(); } List<Constructor<?>> constructors = constructorQuery.getConstructorsForClass(rawTypeClass); if (constructors == null || constructors.isEmpty()) { return new NoSpecimen(); } for (Constructor constructor : constructors) { try { GenericConstructorRequest constructorRequest = new GenericConstructorRequest(constructor, specimenType); Object specimen = context.resolve(constructorRequest); if (!(specimen instanceof NoSpecimen)) { return specimen; } } catch (ObjectCreationException e) { } } return new NoSpecimen(); } ClassToConstructorRelay(ConstructorQuery constructorQuery, Specification specification); @Override Object create(final Object request, SpecimenContext context);  }