SumLists { public int sum(ListNode<Integer> n1, ListNode<Integer> n2) { validateInput(n1, n2); int n1Value = calculateNumber(n1); int n2Value = calculateNumber(n2); return n1Value + n2Value; }  int sumReverse(ListNode<Integer> n1, ListNode<Integer> n2); int sum(ListNode<Integer> n1, ListNode<Integer> n2);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullListAsFirstParameter() { sumLists.sum(null, new ListNode<Integer>(0)); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullListAsSecondParameter() { sumLists.sum(new ListNode<Integer>(0), null); }
@Test public void shouldSumNumbersWithJustOneDigit() { ListNode<Integer> n1 = createList(new int[] { 3 }); ListNode<Integer> n2 = createList(new int[] { 8 }); int result = sumLists.sum(n1, n2); assertEquals(11, result); }
@Test public void shouldSumNumbersWithMoreThanOneDigit() { ListNode<Integer> n1 = createList(new int[] { 1, 5, 5 }); ListNode<Integer> n2 = createList(new int[] { 3, 1, 4 }); int result = sumLists.sum(n1, n2); assertEquals(469, result); }
@Test public void shouldSumNumbersWithDifferentSizes() { ListNode<Integer> n1 = createList(new int[] { 1, 5, 5 }); ListNode<Integer> n2 = createList(new int[] { 5 }); int result = sumLists.sum(n1, n2); assertEquals(160, result); }