コード例 #1
0
 @Test
 public void should_fail_if_actual_is_null() {
   long[] sequence = new long[1];
   String message = ShouldNotBeNull.shouldNotBeNull().create(description);
   thrown.expect(AssertionError.class, message);
   arrays.assertStartsWith(description, null, sequence);
 }
コード例 #2
0
 @Test
 public void should_fail_if_sequence_is_empty() {
   long[] actual = new long[2];
   long[] sequence = {};
   thrown.expect(
       IllegalArgumentException.class, "The array of values to look for should not be empty");
   arrays.assertStartsWith(description, actual, sequence);
 }
コード例 #3
0
 @Test
 public void should_fail_if_actual_does_not_start_with_sequence() {
   long[] actual = {1, 2, 3, 4, 5};
   long[] sequence = {1, 1, 2, 3};
   try {
     arrays.assertStartsWith(description, actual, sequence);
   } catch (AssertionError e) {
     verify(failures).failure(description, shouldStartWith(actual, sequence));
     return;
   }
   throw expectedAssertionErrorNotThrown();
 }
コード例 #4
0
 @Test
 public void should_fail_if_the_size_of_sequence_is_greater_than_the_size_of_actual() {
   long[] actual = new long[3];
   long[] sequence = new long[5];
   try {
     arrays.assertStartsWith(description, actual, sequence);
   } catch (AssertionError e) {
     verify(failures).failure(description, shouldStartWith(actual, sequence));
     return;
   }
   throw expectedAssertionErrorNotThrown();
 }
コード例 #5
0
 @Test
 public void should_fail_if_actual_starts_with_given_sequence_with_duplicates() {
   long[] actual = {1, 2, 3, 4, 5};
   long[] sequence = {1, 2, 2};
   try {
     arrays.assertStartsWith(description, actual, sequence);
   } catch (AssertionError e) {
     verify(failures).failure(description, ShouldStartWith.shouldStartWith(actual, sequence));
     return;
   }
   expectedAssertionErrorNotThrown();
 }
コード例 #6
0
 /**
  * Verifies that the actual array contains the given values, in any order.
  *
  * @param values the given values.
  * @return {@code this} assertion object.
  * @throws NullPointerException if the given argument is {@code null}.
  * @throws IllegalArgumentException if the given argument is an empty array.
  * @throws AssertionError if the actual array is {@code null}.
  * @throws AssertionError if the actual array does not contain the given values.
  */
 public LongArrayAssert contains(long... values) {
   arrays.assertContains(info, actual, values);
   return this;
 }
コード例 #7
0
 /** {@inheritDoc} */
 public LongArrayAssert hasSameSizeAs(Iterable<?> other) {
   arrays.assertHasSameSizeAs(info, actual, other);
   return this;
 }
コード例 #8
0
 /** {@inheritDoc} */
 public LongArrayAssert hasSameSizeAs(Object[] other) {
   arrays.assertHasSameSizeAs(info, actual, other);
   return this;
 }
コード例 #9
0
 /** {@inheritDoc} */
 public LongArrayAssert hasSize(int expected) {
   arrays.assertHasSize(info, actual, expected);
   return this;
 }
コード例 #10
0
 /**
  * Verifies that the actual array does not contain duplicates.
  *
  * @return {@code this} assertion object.
  * @throws AssertionError if the actual array is {@code null}.
  * @throws AssertionError if the actual array contains duplicates.
  */
 public LongArrayAssert doesNotHaveDuplicates() {
   arrays.assertDoesNotHaveDuplicates(info, actual);
   return this;
 }
コード例 #11
0
 @Test
 public void should_fail_if_sequence_is_null() {
   long[] actual = new long[2];
   thrown.expect(NullPointerException.class, "The array of values to look for should not be null");
   arrays.assertStartsWith(description, actual, null);
 }
コード例 #12
0
 /** {@inheritDoc} */
 public void isNullOrEmpty() {
   arrays.assertNullOrEmpty(info, actual);
 }
コード例 #13
0
/**
 * Assertion methods for arrays of {@code long}s.
 *
 * <p>To create an instance of this class, invoke <code>{@link Assertions#assertThat(long[])}</code>
 * .
 *
 * @author Yvonne Wang
 * @author Alex Ruiz
 * @author Joel Costigliola
 * @author Mikhail Mazursky
 * @author Nicolas François
 */
public class LongArrayAssert extends AbstractAssert<LongArrayAssert, long[]>
    implements EnumerableAssert<LongArrayAssert, Long>, ArraySortedAssert<LongArrayAssert, Long> {

  @VisibleForTesting LongArrays arrays = LongArrays.instance();

  protected LongArrayAssert(long[] actual) {
    super(actual, LongArrayAssert.class);
  }

  /** {@inheritDoc} */
  public void isNullOrEmpty() {
    arrays.assertNullOrEmpty(info, actual);
  }

  /** {@inheritDoc} */
  public void isEmpty() {
    arrays.assertEmpty(info, actual);
  }

  /** {@inheritDoc} */
  public LongArrayAssert isNotEmpty() {
    arrays.assertNotEmpty(info, actual);
    return this;
  }

  /** {@inheritDoc} */
  public LongArrayAssert hasSize(int expected) {
    arrays.assertHasSize(info, actual, expected);
    return this;
  }

  /** {@inheritDoc} */
  public LongArrayAssert hasSameSizeAs(Object[] other) {
    arrays.assertHasSameSizeAs(info, actual, other);
    return this;
  }

  /** {@inheritDoc} */
  public LongArrayAssert hasSameSizeAs(Iterable<?> other) {
    arrays.assertHasSameSizeAs(info, actual, other);
    return this;
  }

  /**
   * Verifies that the actual array contains the given values, in any order.
   *
   * @param values the given values.
   * @return {@code this} assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the actual array does not contain the given values.
   */
  public LongArrayAssert contains(long... values) {
    arrays.assertContains(info, actual, values);
    return this;
  }

  /**
   * Verifies that the actual array contains only the given values and nothing else, in any order.
   *
   * @param values the given values.
   * @return {@code this} assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the actual array does not contain the given values, i.e. the actual
   *     array contains some or none of the given values, or the actual array contains more values
   *     than the given ones.
   */
  public LongArrayAssert containsOnly(long... values) {
    arrays.assertContainsOnly(info, actual, values);
    return this;
  }

  /**
   * Verifies that the actual array contains the given sequence, without any other values between
   * them.
   *
   * @param sequence the sequence of values to look for.
   * @return this assertion object.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the given array is {@code null}.
   * @throws AssertionError if the actual array does not contain the given sequence.
   */
  public LongArrayAssert containsSequence(long... sequence) {
    arrays.assertContainsSequence(info, actual, sequence);
    return this;
  }

  /**
   * Verifies that the actual array contains the given value at the given index.
   *
   * @param value the value to look for.
   * @param index the index where the value should be stored in the actual array.
   * @return this assertion object.
   * @throws AssertionError if the actual array is {@code null} or empty.
   * @throws NullPointerException if the given {@code Index} is {@code null}.
   * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or
   *     greater than the size of the actual array.
   * @throws AssertionError if the actual array does not contain the given value at the given index.
   */
  public LongArrayAssert contains(long value, Index index) {
    arrays.assertContains(info, actual, value, index);
    return this;
  }

  /**
   * Verifies that the actual array does not contain the given values.
   *
   * @param values the given values.
   * @return {@code this} assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the actual array contains any of the given values.
   */
  public LongArrayAssert doesNotContain(long... values) {
    arrays.assertDoesNotContain(info, actual, values);
    return this;
  }

  /**
   * Verifies that the actual array does not contain the given value at the given index.
   *
   * @param value the value to look for.
   * @param index the index where the value should be stored in the actual array.
   * @return this assertion object.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws NullPointerException if the given {@code Index} is {@code null}.
   * @throws AssertionError if the actual array contains the given value at the given index.
   */
  public LongArrayAssert doesNotContain(long value, Index index) {
    arrays.assertDoesNotContain(info, actual, value, index);
    return this;
  }

  /**
   * Verifies that the actual array does not contain duplicates.
   *
   * @return {@code this} assertion object.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the actual array contains duplicates.
   */
  public LongArrayAssert doesNotHaveDuplicates() {
    arrays.assertDoesNotHaveDuplicates(info, actual);
    return this;
  }

  /**
   * Verifies that the actual array starts with the given sequence of values, without any other
   * values between them. Similar to <code>{@link #containsSequence(long...)}</code>, but it also
   * verifies that the first element in the sequence is also first element of the actual array.
   *
   * @param sequence the sequence of values to look for.
   * @return this assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the actual array does not start with the given sequence.
   */
  public LongArrayAssert startsWith(long... sequence) {
    arrays.assertStartsWith(info, actual, sequence);
    return this;
  }

  /**
   * Verifies that the actual array ends with the given sequence of values, without any other values
   * between them. Similar to <code>{@link #containsSequence(long...)}</code>, but it also verifies
   * that the last element in the sequence is also last element of the actual array.
   *
   * @param sequence the sequence of values to look for.
   * @return this assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws AssertionError if the actual array is {@code null}.
   * @throws AssertionError if the actual array does not end with the given sequence.
   */
  public LongArrayAssert endsWith(long... sequence) {
    arrays.assertEndsWith(info, actual, sequence);
    return this;
  }

  /** {@inheritDoc} */
  public LongArrayAssert isSorted() {
    arrays.assertIsSorted(info, actual);
    return this;
  }

  /** {@inheritDoc} */
  public LongArrayAssert isSortedAccordingTo(Comparator<? super Long> comparator) {
    arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
    return this;
  }

  /** {@inheritDoc} */
  public LongArrayAssert usingElementComparator(Comparator<? super Long> customComparator) {
    this.arrays = new LongArrays(new ComparatorBasedComparisonStrategy(customComparator));
    return myself;
  }

  /** {@inheritDoc} */
  public LongArrayAssert usingDefaultElementComparator() {
    this.arrays = LongArrays.instance();
    return myself;
  }
}
コード例 #14
0
 /** {@inheritDoc} */
 public LongArrayAssert usingDefaultElementComparator() {
   this.arrays = LongArrays.instance();
   return myself;
 }
コード例 #15
0
 /** {@inheritDoc} */
 public LongArrayAssert isSortedAccordingTo(Comparator<? super Long> comparator) {
   arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
   return this;
 }
コード例 #16
0
 /** {@inheritDoc} */
 public LongArrayAssert isSorted() {
   arrays.assertIsSorted(info, actual);
   return this;
 }
コード例 #17
0
 /**
  * Verifies that the actual array ends with the given sequence of values, without any other values
  * between them. Similar to <code>{@link #containsSequence(long...)}</code>, but it also verifies
  * that the last element in the sequence is also last element of the actual array.
  *
  * @param sequence the sequence of values to look for.
  * @return this assertion object.
  * @throws NullPointerException if the given argument is {@code null}.
  * @throws IllegalArgumentException if the given argument is an empty array.
  * @throws AssertionError if the actual array is {@code null}.
  * @throws AssertionError if the actual array does not end with the given sequence.
  */
 public LongArrayAssert endsWith(long... sequence) {
   arrays.assertEndsWith(info, actual, sequence);
   return this;
 }
コード例 #18
0
 @Test
 public void should_pass_if_actual_starts_with_given_sequence() {
   long[] actual = {1, 2, 3, 4, 5};
   long[] sequence = {1, 2};
   arrays.assertStartsWith(description, actual, sequence);
 }
コード例 #19
0
 /**
  * Verifies that the actual array does not contain the given values.
  *
  * @param values the given values.
  * @return {@code this} assertion object.
  * @throws NullPointerException if the given argument is {@code null}.
  * @throws IllegalArgumentException if the given argument is an empty array.
  * @throws AssertionError if the actual array is {@code null}.
  * @throws AssertionError if the actual array contains any of the given values.
  */
 public LongArrayAssert doesNotContain(long... values) {
   arrays.assertDoesNotContain(info, actual, values);
   return this;
 }
コード例 #20
0
 /**
  * Verifies that the actual array contains the given value at the given index.
  *
  * @param value the value to look for.
  * @param index the index where the value should be stored in the actual array.
  * @return this assertion object.
  * @throws AssertionError if the actual array is {@code null} or empty.
  * @throws NullPointerException if the given {@code Index} is {@code null}.
  * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or
  *     greater than the size of the actual array.
  * @throws AssertionError if the actual array does not contain the given value at the given index.
  */
 public LongArrayAssert contains(long value, Index index) {
   arrays.assertContains(info, actual, value, index);
   return this;
 }
コード例 #21
0
 /** {@inheritDoc} */
 public void isEmpty() {
   arrays.assertEmpty(info, actual);
 }
コード例 #22
0
 /**
  * Verifies that the actual array does not contain the given value at the given index.
  *
  * @param value the value to look for.
  * @param index the index where the value should be stored in the actual array.
  * @return this assertion object.
  * @throws AssertionError if the actual array is {@code null}.
  * @throws NullPointerException if the given {@code Index} is {@code null}.
  * @throws AssertionError if the actual array contains the given value at the given index.
  */
 public LongArrayAssert doesNotContain(long value, Index index) {
   arrays.assertDoesNotContain(info, actual, value, index);
   return this;
 }
コード例 #23
0
 /** {@inheritDoc} */
 public LongArrayAssert isNotEmpty() {
   arrays.assertNotEmpty(info, actual);
   return this;
 }
コード例 #24
0
 /**
  * Verifies that the actual array contains the given sequence, without any other values between
  * them.
  *
  * @param sequence the sequence of values to look for.
  * @return this assertion object.
  * @throws AssertionError if the actual array is {@code null}.
  * @throws AssertionError if the given array is {@code null}.
  * @throws AssertionError if the actual array does not contain the given sequence.
  */
 public LongArrayAssert containsSequence(long... sequence) {
   arrays.assertContainsSequence(info, actual, sequence);
   return this;
 }