### Question:
MultisourceBeanLocator implements ConfiguredBeanLocator { @Override public <T> T getBeanOfType(String name, Class<T> type) { return locators.stream() .map(locator -> locator.getBeanOfType(name, type)) .filter(Objects::nonNull) .findFirst() .orElse(null); } MultisourceBeanLocator(ConfiguredBeanLocator... locators); @Override List<String> getBeanNamesOfType(Class<?> type); @Override T getBeanOfType(String name, Class<T> type); @Override Collection<? extends T> getBeansOfType(Class<T> type); @Override boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T> listener); @Override boolean hasConfiguredPropertyValue(String beanName, String propertyName, String value); @Override boolean hasBeanOfName(String name);  }### Answer:
@Test public void testGetBeanOfType_nullFirstSource() { when(source1.getBeanOfType(anyString(), eq(Long.class))).thenReturn(null); when(source2.getBeanOfType(anyString(), eq(Long.class))).thenReturn(3L); Long bean = multisourceBeanLocator.getBeanOfType("test", Long.class); Assert.assertEquals(3L, bean.longValue()); }
@Test public void testGetBeanOfType_nullBothSources() { when(source1.getBeanOfType(anyString(), eq(Long.class))).thenReturn(null); when(source2.getBeanOfType(anyString(), eq(Long.class))).thenReturn(null); Long bean = multisourceBeanLocator.getBeanOfType("test", Long.class); Assert.assertNull(bean); }
@Test public void testGetBeanOfType_notNullBothSources() { when(source1.getBeanOfType(anyString(), eq(Long.class))).thenReturn(2L); when(source2.getBeanOfType(anyString(), eq(Long.class))).thenReturn(3L); Long bean = multisourceBeanLocator.getBeanOfType("test", Long.class); verifyNoMoreInteractions(source2); Assert.assertEquals(2L, bean.longValue()); }