@Test public void shouldReturnNegativeIntForNullArray() { String errorMsg = "response not a negative int"; int position = positionFinder.getPosition(null, 3); assertTrue(errorMsg, position < 0); }
@Test public void shouldReturnNegativePositionIfValueDoesNotExistInArray() { String errorMsg = "position is not less than 0"; int[] valueArray = {1, 2, 3, 4, 5}; int position = positionFinder.getPosition(valueArray, 9); assertTrue(errorMsg, position < 0); }
@Test public void shouldReturnPositivePositionIfValueExistInArray() { String errorMsg = "position is not greater than 0"; int[] valueArray = {1, 2, 3, 4, 5}; int position = positionFinder.getPosition(valueArray, 3); assertTrue(errorMsg, position > 0); }
private void assertPositionIsAsExpected(int[] valueArray, int value, int expectedPosition) { String errorMsg = "position not as expected"; int actualPosition = positionFinder.getPosition(valueArray, value); assertEquals(errorMsg, expectedPosition, actualPosition); }