Add more tests for UidReverseComparator
This commit is contained in:
parent
4ec6e88f4f
commit
75121d85fe
1 changed files with 141 additions and 5 deletions
|
@ -34,6 +34,86 @@ public class UidReverseComparatorTest {
|
|||
assertEquals("result must be 0 when both arguments are null", 0, result);
|
||||
}
|
||||
|
||||
@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_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_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_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_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_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_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_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_withLeftNullArgument_shouldReturnPositive() throws Exception {
|
||||
Message messageLeft = null;
|
||||
|
@ -44,6 +124,26 @@ public class UidReverseComparatorTest {
|
|||
assertTrue("result must be > 0 when left argument is null", result > 0);
|
||||
}
|
||||
|
||||
@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_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_withRightNullArgument_shouldReturnNegative() throws Exception {
|
||||
Message messageLeft = createMessageWithUid(1);
|
||||
|
@ -55,19 +155,55 @@ public class UidReverseComparatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void compare_twoMessages_shouldReturnOrderByUid() throws Exception {
|
||||
Message messageLeft = createMessageWithUid(5);
|
||||
Message messageRight = createMessageWithUid(15);
|
||||
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 message has larger UID than left message", result > 0);
|
||||
assertTrue("result must be < 0 when right 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_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);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Message createMessageWithUid(int uid) {
|
||||
return createMessageWithUidString(Integer.toString(uid));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Message createMessageWithNullUid() {
|
||||
return createMessageWithUidString(null);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Message createMessageWithInvalidUid() {
|
||||
return createMessageWithUidString("invalid");
|
||||
}
|
||||
|
||||
private Message createMessageWithUidString(String uid) {
|
||||
Message message = mock(Message.class);
|
||||
when(message.getUid()).thenReturn(Integer.toString(uid));
|
||||
when(message.getUid()).thenReturn(uid);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue