@Before public void onBefore() { comparator = new UidReverseComparator(); }
@Test public void compare_withTwoNullArguments_shouldReturnZero() throws Exception { Message messageLeft = null; Message messageRight = null; int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are null", 0, result); }
@Override public int compare(Message messageLeft, Message messageRight) { Long uidLeft = getUidForMessage(messageLeft); Long uidRight = getUidForMessage(messageRight); if (uidLeft == null && uidRight == null) { return 0; } else if (uidLeft == null) { return 1; } else if (uidRight == null) { return -1; } // reverse order return uidRight.compareTo(uidLeft); }
@Test public void compare_twoMessages_shouldReturnOrderByUid() throws Exception { Message messageSmall = createMessageWithUid(5); Message messageLarge = createMessageWithUid(15); int resultOne = comparator.compare(messageSmall, messageLarge); int resultTwo = comparator.compare(messageLarge, messageSmall); assertTrue("result must be > 0 when right message has larger UID than left message", resultOne > 0); assertTrue("result must be < 0 when left message has larger UID than right message", resultTwo < 0); }
@Test public void compare_withNullArgumentAndMessageWithInvalidUid_shouldReturnZero() throws Exception { Message messageLeft = null; Message messageRight = createMessageWithInvalidUid(); int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result); }
@Test public void compare_withMessageWithNullUidAndNullArgument_shouldReturnZero() throws Exception { Message messageLeft = createMessageWithNullUid(); Message messageRight = null; int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result); }
@Test public void compare_withLeftNullArgument_shouldReturnPositive() throws Exception { Message messageLeft = null; Message messageRight = createMessageWithUid(1); int result = comparator.compare(messageLeft, messageRight); assertTrue("result must be > 0 when left argument is null", result > 0); }
@Test public void compare_withNullArgumentAndMessageWithNullUid_shouldReturnZero() throws Exception { Message messageLeft = null; Message messageRight = createMessageWithNullUid(); int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result); }
@Test public void compare_withMessageWithInvalidUidAndNullArgument_shouldReturnZero() throws Exception { Message messageLeft = createMessageWithInvalidUid(); Message messageRight = null; int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result); }
@Test public void compare_withRightNullArgument_shouldReturnNegative() throws Exception { Message messageLeft = createMessageWithUid(1); Message messageRight = null; int result = comparator.compare(messageLeft, messageRight); assertTrue("result must be < 0 when right argument is null", result < 0); }
@Test public void compare_withLeftMessageWithInvalidUid_shouldReturnPositive() throws Exception { Message messageLeft = createMessageWithInvalidUid(); Message messageRight = createMessageWithUid(1); int result = comparator.compare(messageLeft, messageRight); assertTrue("result must be > 0 when left argument is message with invalid UID", result > 0); }
@Test public void compare_withTwoMessagesWithInvalidUid_shouldReturnZero() throws Exception { Message messageLeft = createMessageWithInvalidUid(); Message messageRight = createMessageWithInvalidUid(); int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are a message with an invalid UID", 0, result); }
@Test public void compare_withMessageWithInvalidUidAndMessageWithNullUid_shouldReturnZero() throws Exception { Message messageLeft = createMessageWithInvalidUid(); Message messageRight = createMessageWithNullUid(); int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result); }
@Test public void compare_withLeftMessageWithNullUid_shouldReturnPositive() throws Exception { Message messageLeft = createMessageWithNullUid(); Message messageRight = createMessageWithUid(1); int result = comparator.compare(messageLeft, messageRight); assertTrue("result must be > 0 when left argument is message with null UID", result > 0); }
@Test public void compare_withRightMessageWithInvalidUid_shouldReturnNegative() throws Exception { Message messageLeft = createMessageWithUid(1); Message messageRight = createMessageWithInvalidUid(); int result = comparator.compare(messageLeft, messageRight); assertTrue("result must be < 0 when right argument is message with invalid UID", result < 0); }
@Test public void compare_withTwoMessagesWithNullUid_shouldReturnZero() throws Exception { Message messageLeft = createMessageWithNullUid(); Message messageRight = createMessageWithNullUid(); int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are a message with a null UID", 0, result); }
@Test public void compare_withMessageWithNullUidAndMessageWithInvalidUid_shouldReturnZero() throws Exception { Message messageLeft = createMessageWithNullUid(); Message messageRight = createMessageWithInvalidUid(); int result = comparator.compare(messageLeft, messageRight); assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result); }
@Test public void compare_withRightMessageWithNullUid_shouldReturnNegative() throws Exception { Message messageLeft = createMessageWithUid(1); Message messageRight = createMessageWithNullUid(); int result = comparator.compare(messageLeft, messageRight); assertTrue("result must be < 0 when right argument is message with null UID", result < 0); }