Tasks implements BaseService { public void removeType(@NonNull TaskType taskType) { Exceptions.log("Tasks remove type type " + taskType); synchronized (pending) { final ListIterator<Task> it = pending.listIterator(); while (it.hasNext()) { final Task task = it.next(); if (!task.equals(running) && task.taskType().name().equals(taskType.name())) { it.remove(); } } } }  @Override void start(@NonNull Context context); void add(@NonNull Task task); void tendQueue(); void removeType(@NonNull TaskType taskType); @Override void stop();  }
@Test public void removeType() throws InterruptedException { Tasks tasks = new Tasks(); tasks.start(null); assertEquals(0, tasks.pending.size()); TestTask testTask1 = new TestTask("id1"); TestTask testTask2 = new TestTask("id2"); tasks.add(testTask1); tasks.add(testTask2); assertEquals(2, tasks.pending.size()); tasks.removeType(TestTask.taskType); assertEquals(1, tasks.pending.size()); testTask1.wait = false; Thread.sleep(60); assertEquals(0, tasks.pending.size()); }