@Test public void first_builder_returns_no_specimen_returns_result_of_next_builder_with_valid_result() { Object builderBResult = new Object(); when(mockBuilderA.create(request, mockContext)).thenReturn(new NoSpecimen()); when(mockBuilderB.create(request, mockContext)).thenReturn(builderBResult); Object result = compositeBuilder.create(request, mockContext); assertSame(builderBResult, result); }
@Override public Object create(Object request, SpecimenContext context) { for (SpecimenBuilder builder : this) { Object result = builder.create(request, context); if (isSpecimen(result)) { return result; } } return new NoSpecimen(); }
CompositeBuilder extends ArrayList<SpecimenBuilder> implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { for (SpecimenBuilder builder : this) { Object result = builder.create(request, context); if (isSpecimen(result)) { return result; } } return new NoSpecimen(); } }
CompositeBuilder extends ArrayList<SpecimenBuilder> implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { for (SpecimenBuilder builder : this) { Object result = builder.create(request, context); if (isSpecimen(result)) { return result; } } return new NoSpecimen(); } CompositeBuilder(SpecimenBuilder... builders);  CompositeBuilder(Iterable<SpecimenBuilder> builders); }
CompositeBuilder extends ArrayList<SpecimenBuilder> implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { for (SpecimenBuilder builder : this) { Object result = builder.create(request, context); if (isSpecimen(result)) { return result; } } return new NoSpecimen(); } CompositeBuilder(SpecimenBuilder... builders);  CompositeBuilder(Iterable<SpecimenBuilder> builders); @Override Object create(Object request, SpecimenContext context); }
CompositeBuilder extends ArrayList<SpecimenBuilder> implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { for (SpecimenBuilder builder : this) { Object result = builder.create(request, context); if (isSpecimen(result)) { return result; } } return new NoSpecimen(); } CompositeBuilder(SpecimenBuilder... builders);  CompositeBuilder(Iterable<SpecimenBuilder> builders); @Override Object create(Object request, SpecimenContext context);  }