AbstractTask implements Runnable, Comparable<AbstractTask> { @Override public int compareTo(AbstractTask o) { return o.getPriority() - this.getPriority(); }  @Override abstract void run(); @Override int compareTo(AbstractTask o); AbstractTask setPriority(int priority); int getPriority();  }
@Test public void compareTo() { TestTask testTask1 = new TestTask(); testTask1.setPriority(123); Assert.assertEquals(123, testTask1.getPriority()); TestTask testTask2 = new TestTask(); testTask2.setPriority(234); Assert.assertTrue(testTask1.compareTo(testTask2) > 0); PriorityQueue<AbstractTask> queue = new PriorityQueue<AbstractTask>(); queue.offer(testTask1); queue.offer(testTask2); Assert.assertEquals(queue.poll(), testTask2); Assert.assertEquals(queue.poll(), testTask1); }