FindTheMissingNumber { public int find(int[] numbers) { validateInput(numbers); int length = numbers.length; int idealSum = length * (length + 1) / 2; int sum = calculateSum(numbers); int missingNumber = idealSum - sum; return missingNumber; }  int find(int[] numbers);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullInstances() { findMissingNumber.find(null); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptyArrays() { findMissingNumber.find(new int[0]); }
@Test public void shouldFindMissingNumber() { int[] numbers = { 0, 1, 2, 4 }; int missingNumber = findMissingNumber.find(numbers); assertEquals(3, missingNumber); }