class AndroidMocks {

    public static RecyclerView mockRecyclerView() {
        final RecyclerView recyclerView = mock(RecyclerView.class);

        doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                when(recyclerView.getAdapter()).thenReturn((RecyclerView.Adapter) invocation.getArguments()[0]);
                return null;
            }
        }).when(recyclerView).setAdapter(any(RecyclerView.Adapter.class));

        doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                when(recyclerView.getLayoutManager()).thenReturn((RecyclerView.LayoutManager) invocation.getArguments()[0]);
                return null;
            }
        }).when(recyclerView).setLayoutManager(any(RecyclerView.LayoutManager.class));

        return recyclerView;
    }

}