AdapterCommandProcessor { @MainThread public void execute(@NonNull List<AdapterCommand> commands) { if (commands == null) { throw new NullPointerException("commands == null"); } for (int i = 0; i < commands.size(); i++) { commands.get(i).execute(adapter); } } AdapterCommandProcessor(@NonNull RecyclerView.Adapter<?> adapter); @MainThread void execute(@NonNull List<AdapterCommand> commands);  }
@Test public void executeCommands() { AdapterCommand c1 = Mockito.mock(AdapterCommand.class); AdapterCommand c2 = Mockito.mock(AdapterCommand.class); List<AdapterCommand> commandList = new ArrayList<>(); commandList.add(c1); commandList.add(c2); processor.execute(commandList); Mockito.verify(c1, Mockito.times(1)).execute(adapter); Mockito.verify(c2, Mockito.times(1)).execute(adapter); }
@Test public void executeNullList() { try { processor.execute(null); Assert.fail("Nullpointer expected"); } catch (NullPointerException e) { Assert.assertEquals("commands == null", e.getMessage()); } }