### Question:
CompositeDriverFinder implements DriverFinder { @Override public Driver findTestClassDriver(Class<?> testClass) { for (DriverFinder finder : finders) { Driver driver = finder.findTestClassDriver(testClass); if (driver != DRIVER_NOT_FOUND) { return driver; } } throw new IllegalArgumentException(testClass + " was not recognized as a compatible test class; tried " + Arrays.toString(finders)); } CompositeDriverFinder(List<DriverFinder> finders);  CompositeDriverFinder(DriverFinder... finders); @Override Driver findTestClassDriver(Class<?> testClass);  }### Answer:
@Test public void returns_the_driver_from_the_backing_driver_finder() { DriverFinder finder1 = mock(DriverFinder.class, "finder1"); stub(finder1.findTestClassDriver(testClass)).toReturn(expectedDriver); Driver driver = new CompositeDriverFinder(finder1).findTestClassDriver(testClass); assertThat(driver, is(expectedDriver)); }
@Test public void returns_the_driver_from_the_first_compatible_backing_driver_finder() { DriverFinder finder1 = mock(DriverFinder.class, "finder1"); DriverFinder finder2 = mock(DriverFinder.class, "finder2"); DriverFinder finder3 = mock(DriverFinder.class, "finder3"); stub(finder1.findTestClassDriver(testClass)).toReturn(null); stub(finder2.findTestClassDriver(testClass)).toReturn(expectedDriver); stub(finder3.findTestClassDriver(testClass)).toReturn(null); Driver driver = new CompositeDriverFinder(finder1, finder2, finder3).findTestClassDriver(testClass); assertThat(driver, is(expectedDriver)); verify(finder1).findTestClassDriver(testClass); verify(finder2).findTestClassDriver(testClass); verifyZeroInteractions(finder3); }
@Test public void fails_if_none_of_the_backing_driver_finders_was_compatible() { DriverFinder finder1 = mock(DriverFinder.class, "finder1"); stub(finder1.findTestClassDriver(testClass)).toReturn(null); thrown.expect(IllegalArgumentException.class); thrown.expectMessage(testClass + " was not recognized as a compatible test class"); thrown.expectMessage(finder1.toString()); new CompositeDriverFinder(finder1).findTestClassDriver(testClass); }