class MapScreenshotProvider extends BaseScreenshotProvider {

    @NonNull
    @VisibleForTesting
        /* default */ List<MapView> locateMapViewsInHierarchy(@NonNull final View view) {
        final List<MapView> result = new ArrayList<>();

        final Queue<View> viewsToProcess = new LinkedList<>();
        viewsToProcess.add(view);

        while (!viewsToProcess.isEmpty()) {
            final View viewToProcess = viewsToProcess.remove();

            if (viewToProcess instanceof MapView && viewToProcess.getVisibility() == VISIBLE) {
                result.add((MapView) viewToProcess);
            } else if (viewToProcess instanceof ViewGroup) {
                final ViewGroup viewGroup = (ViewGroup) viewToProcess;

                for (int childIndex = 0; childIndex < viewGroup.getChildCount(); childIndex++) {
                    viewsToProcess.add(viewGroup.getChildAt(childIndex));
                }
            }
        }

        return result;
    }

}

class MapScreenshotProviderTest {

    private MapScreenshotProvider mapScreenshotProvider;
    @Mock
    private Context applicationContext;

    @SuppressWarnings("MethodName")
    @Test
    public void testThat_noExceptionThrown_when_searchingViewHierarchyThatContainsMultipleViews() {

        // Arrange
        final ViewGroup mockRootView = mock(ViewGroup.class);
        final int numberOfChildViews = 4;
        assert numberOfChildViews > 1;

        when(mockRootView.getChildCount()).thenReturn(numberOfChildViews);
        when(mockRootView.getChildAt(anyInt())).thenReturn(mock(View.class));

        // Act
        mapScreenshotProvider.locateMapViewsInHierarchy(mockRootView);
    }

}