PalindromeList { public boolean checkReversing(ListNode list) { validateInput(list); ListNode<Integer> reversedList = reverseLinkedList.reverseIterative(list); boolean isPalindrome = true; while (list != null) { isPalindrome = list.equals(reversedList); if (!isPalindrome) { break; } reversedList = reversedList.getNext(); list = list.getNext(); } return isPalindrome; } PalindromeList(); boolean checkReversing(ListNode list); boolean checkIterative(ListNode list);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullListAsInputReversing() { palindromeList.checkReversing(null); }
@Test public void shouldReturnTrueIfListContainsJustOneNodeReversing() { ListNode<Integer> list = new ListNode<Integer>(1); boolean result = palindromeList.checkReversing(list); assertTrue(result); }
@Test public void shouldRturnTrueIfListContainsTwoElementsWithTheSameValueReversing() { ListNode<Integer> list = createList(new int[] { 1, 1 }); boolean result = palindromeList.checkReversing(list); assertTrue(result); }
@Test public void shouldReturnTrueIfListIsPalindromeReversing() { ListNode<Integer> list = createList(new int[] { 1, 2, 1 }); boolean result = palindromeList.checkReversing(list); assertTrue(result); }
@Test public void shouldReturnFalseIfListIsNotPalindromeReversing() { ListNode<Integer> list = createList(new int[] { 1, 1, 3 }); boolean result = palindromeList.checkReversing(list); assertFalse(result); }