### Question:
GapWorker implements Runnable { public void add(RecyclerView recyclerView) { if (RecyclerView.DEBUG && mRecyclerViews.contains(recyclerView)) { throw new IllegalStateException("RecyclerView already present in worker list!"); } mRecyclerViews.add(recyclerView); }  void add(RecyclerView recyclerView); void remove(RecyclerView recyclerView); @Override void run();  }### Answer:
@Test public void taskOrderViewPresence() { ArrayList<GapWorker.Task> list = new ArrayList<>(); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.get(0).view = null; list.get(1).view = new RecyclerView(getContext()); list.get(2).view = null; Collections.sort(list, GapWorker.sTaskComparator); assertNotNull(list.get(0).view); assertNull(list.get(1).view); assertNull(list.get(2).view); }
@Test public void taskOrderImmediate() { ArrayList<GapWorker.Task> list = new ArrayList<>(); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.get(0).immediate = true; list.get(1).immediate = false; list.get(2).immediate = true; Collections.sort(list, GapWorker.sTaskComparator); assertTrue(list.get(0).immediate); assertTrue(list.get(1).immediate); assertFalse(list.get(2).immediate); }
@Test public void taskOrderImmediateVelocity() { ArrayList<GapWorker.Task> list = new ArrayList<>(); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.get(0).immediate = true; list.get(0).viewVelocity = 10; list.get(1).immediate = false; list.get(1).viewVelocity = 99; list.get(2).immediate = true; list.get(2).viewVelocity = 20; Collections.sort(list, GapWorker.sTaskComparator); assertEquals(20, list.get(0).viewVelocity); assertEquals(10, list.get(1).viewVelocity); assertEquals(99, list.get(2).viewVelocity); }
@Test public void taskOrderImmediateVelocityDistance() { ArrayList<GapWorker.Task> list = new ArrayList<>(); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.add(new GapWorker.Task()); list.get(0).immediate = true; list.get(0).viewVelocity = 400; list.get(0).distanceToItem = 300; list.get(1).immediate = false; list.get(1).viewVelocity = 800; list.get(1).distanceToItem = 900; list.get(2).immediate = true; list.get(2).viewVelocity = 300; list.get(2).distanceToItem = 200; list.get(3).immediate = true; list.get(3).viewVelocity = 300; list.get(3).distanceToItem = 100; Collections.sort(list, GapWorker.sTaskComparator); assertEquals(300, list.get(0).distanceToItem); assertEquals(100, list.get(1).distanceToItem); assertEquals(200, list.get(2).distanceToItem); assertEquals(900, list.get(3).distanceToItem); }