@Test public void should_fail_if_actual_starts_with_first_elements_of_sequence_only() { AssertionInfo info = someInfo(); byte[] sequence = {6, 20}; try { arrays.assertStartsWith(info, actual, sequence); } catch (AssertionError e) { verifyFailureThrownWhenSequenceNotFound(info, sequence); return; } throw expectedAssertionErrorNotThrown(); }
@Test public void should_fail_if_sequence_is_bigger_than_actual() { AssertionInfo info = someInfo(); byte[] sequence = {6, 8, 10, 12, 20, 22}; try { arrays.assertStartsWith(info, actual, sequence); } catch (AssertionError e) { verifyFailureThrownWhenSequenceNotFound(info, sequence); return; } throw expectedAssertionErrorNotThrown(); }
@Test public void should_fail_if_actual_does_not_start_with_sequence() { AssertionInfo info = someInfo(); byte[] sequence = {8, 10}; try { arrays.assertStartsWith(info, actual, sequence); } catch (AssertionError e) { verifyFailureThrownWhenSequenceNotFound(info, sequence); return; } throw expectedAssertionErrorNotThrown(); }
@Test public void should_fail_if_actual_contains_given_values() { AssertionInfo info = someInfo(); byte[] expected = {6, 8, 20}; try { arrays.assertDoesNotContain(info, actual, expected); } catch (AssertionError e) { verify(failures).failure(info, shouldNotContain(actual, expected, set((byte) 6, (byte) 8))); return; } throw expectedAssertionErrorNotThrown(); }
@Test public void should_fail_if_actual_is_null() { thrown.expectAssertionError(actualIsNull()); arrays.assertStartsWith(someInfo(), null, array(8)); }
@Test public void should_throw_error_if_sequence_is_empty() { thrown.expectIllegalArgumentException(valuesToLookForIsEmpty()); arrays.assertStartsWith(someInfo(), actual, emptyArray()); }
@Test public void should_throw_error_if_sequence_is_null() { thrown.expectNullPointerException(valuesToLookForIsNull()); arrays.assertStartsWith(someInfo(), actual, null); }
@Before public void setUp() { failures = spy(new Failures()); arrays = new ByteArrays(); arrays.failures = failures; }
@Test public void should_pass_if_actual_and_sequence_are_equal() { arrays.assertStartsWith(someInfo(), actual, array(6, 8, 10, 12)); }
@Test public void should_pass_if_actual_starts_with_sequence() { arrays.assertStartsWith(someInfo(), actual, array(6, 8, 10)); }
@Test public void should_fail_if_actual_is_null() { thrown.expectAssertionError(actualIsNull()); arrays.assertDoesNotContain(someInfo(), null, array(8)); }
@Test public void should_throw_error_if_array_of_values_to_look_for_is_null() { thrown.expectNullPointerException(valuesToLookForIsNull()); arrays.assertDoesNotContain(someInfo(), actual, null); }
@Test public void should_throw_error_if_array_of_values_to_look_for_is_empty() { thrown.expectIllegalArgumentException(valuesToLookForIsEmpty()); arrays.assertDoesNotContain(someInfo(), actual, emptyArray()); }
@Test public void should_pass_if_actual_does_not_contain_given_values_even_if_duplicated() { arrays.assertDoesNotContain(someInfo(), actual, array(12, 12, 20)); }