### Question:
DoubleSearch implements Iterable<DoubleDefinition> { public DoubleDefinition findOneDefinition(String beanName, Class<?> beanClass) { final List<DoubleDefinition> matchingDoubles = matchingDoubles(filterByName(beanName).and(filterByClass(beanClass))); ensureSingleMatch(matchingDoubles, "[name = " + beanName + " AND class = " + beanClass + "]"); return matchingDoubles.get(0); } DoubleSearch(Collection<DoubleDefinition> doubles); boolean containsAnyDoubleMatching(String beaName, Class<?> beanClass); boolean containsExactlyOneDouble(String beanName, Class<?> beanClass); boolean containsExactlyOneDouble(String beanName); boolean containsExactlyOneDouble(Class<?> beanClass); DoubleDefinition findOneDefinition(String beanName, Class<?> beanClass); DoubleDefinition findOneDefinition(String beanName); DoubleDefinition findOneDefinition(Class<?> beanClass); @Override Iterator<DoubleDefinition> iterator(); @Override String toString();  }### Answer:
@Test public void should_throw_exception_when_no_definition_found_by_name_and_class() { final DoubleSearch search = new DoubleSearch(emptyList()); exception.expect(IllegalStateException.class); exception.expectMessage(Matchers.allOf( startsWith(MISSING_DOUBLE_EXCEPTION_PREFIX), endsWith(NO_DEFINITION_FOUND_EXCEPTION_MESSAGE))); search.findOneDefinition("non existing name", Service.class); }
@Test public void should_throw_exception_when_multiple_definitions_found_by_name_and_class() { final String mockName = "mock"; final Class<?> mockClass = Service.class; final DoubleSearch search = new DoubleSearch(asList( doubleDefinition(mockClass, mockName), doubleDefinition(mockClass, mockName))); exception.expect(IllegalStateException.class); exception.expectMessage(Matchers.allOf( startsWith(MISSING_DOUBLE_EXCEPTION_PREFIX), containsString(MULTIPLE_DOUBLES_EXCEPTION_MESSAGE))); search.findOneDefinition(mockName, Service.class); }
@Test public void should_throw_exception_when_no_definition_found_by_name() { final DoubleSearch search = new DoubleSearch(emptyList()); exception.expect(IllegalStateException.class); exception.expectMessage(Matchers.allOf( startsWith(MISSING_DOUBLE_EXCEPTION_PREFIX), endsWith(NO_DEFINITION_FOUND_EXCEPTION_MESSAGE))); search.findOneDefinition("non existing name"); }
@Test public void should_throw_exception_when_multiple_definitions_found_by_name() { final String mockName = "mock"; final Class<?> mockClass = Service.class; final DoubleSearch search = new DoubleSearch(asList( doubleDefinition(mockClass, mockName), doubleDefinition(mockClass, mockName))); exception.expect(IllegalStateException.class); exception.expectMessage(Matchers.allOf( startsWith(MISSING_DOUBLE_EXCEPTION_PREFIX), containsString(MULTIPLE_DOUBLES_EXCEPTION_MESSAGE))); search.findOneDefinition(mockName); }
@Test public void should_throw_exception_when_no_definition_found_by_class() { final DoubleSearch search = new DoubleSearch(emptyList()); exception.expect(IllegalStateException.class); exception.expectMessage(Matchers.allOf( startsWith(MISSING_DOUBLE_EXCEPTION_PREFIX), endsWith(NO_DEFINITION_FOUND_EXCEPTION_MESSAGE))); search.findOneDefinition(Service.class); }
@Test public void should_throw_exception_when_multiple_definitions_found_by_class() { final String mockName = "mock"; final Class<?> mockClass = Service.class; final DoubleSearch search = new DoubleSearch(asList( doubleDefinition(mockClass, mockName), doubleDefinition(mockClass, mockName))); exception.expect(IllegalStateException.class); exception.expectMessage(Matchers.allOf( startsWith(MISSING_DOUBLE_EXCEPTION_PREFIX), containsString(MULTIPLE_DOUBLES_EXCEPTION_MESSAGE))); search.findOneDefinition(mockClass); }