}
public void testCompareTo() throws InterruptedException
{
String uuid = UUID.getUUID();
EventGroup g1 = new EventGroup(uuid);
EventGroup g2 = new EventGroup(uuid);
EventGroup g3 = new EventGroup(UUID.getUUID());
// test comparison against null
try
{
g1.compareTo(null);
fail("expected NullPointerException");
}
catch (NullPointerException npe)
{
// expected
}
assertEquals(0, g1.compareTo(g2));
/*
* guids are randomly generated, we cannot compare them with '<' '>'
* we used to generate them this way: generator.generateTimeBasedUUID().toString()
* but now we generate them as java.util.UUID.randomUUID().toString()
*/
assertTrue(g1.compareTo(g3) != 0);
assertTrue(g3.compareTo(g1) != 0);
assertTrue(g3.compareTo(g2) != 0);
// when the groupId is not Comparable, the creation time is used as fallback
g1 = new EventGroup(new Object());
// sleep a mini bit to ensure that both event groups do not accidentially have the same
// creation timestamp
Thread.sleep(10);
g2 = new EventGroup(new Object());
// g1 is older (smaller) than g2
assertTrue(g1.compareTo(g2) < 0);
assertTrue(g2.compareTo(g1) > 0);
}