예제 #1
0
 /** {@inheritDoc} */
 public ByteArrayAssert hasSameSizeAs(Object[] other) {
   arrays.assertHasSameSizeAs(info, actual, other);
   return this;
 }
예제 #2
0
 /** {@inheritDoc} */
 public ByteArrayAssert isNotEmpty() {
   arrays.assertNotEmpty(info, actual);
   return this;
 }
예제 #3
0
 /** {@inheritDoc} */
 public ByteArrayAssert hasSize(int expected) {
   arrays.assertHasSize(info, actual, expected);
   return this;
 }
예제 #4
0
 /** {@inheritDoc} */
 public void isNullOrEmpty() {
   arrays.assertNullOrEmpty(info, actual);
 }
예제 #5
0
 /** {@inheritDoc} */
 public void isEmpty() {
   arrays.assertEmpty(info, actual);
 }
예제 #6
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 ByteArrayAssert containsSequence(byte... sequence) {
   arrays.assertContainsSequence(info, actual, sequence);
   return this;
 }
예제 #7
0
/**
 * Assertion methods for arrays of {@code byte}s.
 *
 * <p>To create an instance of this class, invoke <code>{@link Assertions#assertThat(byte[])}</code>
 * .
 *
 * @author Yvonne Wang
 * @author Alex Ruiz
 * @author Joel Costigliola
 * @author Mikhail Mazursky
 * @author Nicolas François
 */
public class ByteArrayAssert extends AbstractAssert<ByteArrayAssert, byte[]>
    implements EnumerableAssert<ByteArrayAssert, Byte>, ArraySortedAssert<ByteArrayAssert, Byte> {

  @VisibleForTesting ByteArrays arrays = ByteArrays.instance();

  protected ByteArrayAssert(byte[] actual) {
    super(actual, ByteArrayAssert.class);
  }

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

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

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

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

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

  /** {@inheritDoc} */
  public ByteArrayAssert 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 ByteArrayAssert contains(byte... 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 ByteArrayAssert containsOnly(byte... 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 ByteArrayAssert containsSequence(byte... 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 ByteArrayAssert contains(byte 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 ByteArrayAssert doesNotContain(byte... 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 ByteArrayAssert doesNotContain(byte 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 ByteArrayAssert 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(byte...)}</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 ByteArrayAssert startsWith(byte... 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(byte...)}</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 ByteArrayAssert endsWith(byte... sequence) {
    arrays.assertEndsWith(info, actual, sequence);
    return this;
  }

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

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

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

  /** {@inheritDoc} */
  public ByteArrayAssert usingDefaultElementComparator() {
    this.arrays = ByteArrays.instance();
    return myself;
  }
}
예제 #8
0
 /** {@inheritDoc} */
 public ByteArrayAssert isSorted() {
   arrays.assertIsSorted(info, actual);
   return this;
 }
예제 #9
0
 /** {@inheritDoc} */
 public ByteArrayAssert isSortedAccordingTo(Comparator<? super Byte> comparator) {
   arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
   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 ByteArrayAssert doesNotHaveDuplicates() {
   arrays.assertDoesNotHaveDuplicates(info, actual);
   return this;
 }
예제 #11
0
 /**
  * Verifies that the actual array ends with the given sequence of values, without any other values
  * between them. Similar to <code>{@link #containsSequence(byte...)}</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 ByteArrayAssert endsWith(byte... sequence) {
   arrays.assertEndsWith(info, actual, sequence);
   return this;
 }
예제 #12
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 ByteArrayAssert doesNotContain(byte value, Index index) {
   arrays.assertDoesNotContain(info, actual, value, index);
   return this;
 }
예제 #13
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 ByteArrayAssert doesNotContain(byte... values) {
   arrays.assertDoesNotContain(info, actual, values);
   return this;
 }
예제 #14
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 ByteArrayAssert contains(byte value, Index index) {
   arrays.assertContains(info, actual, value, index);
   return this;
 }
예제 #15
0
 /** {@inheritDoc} */
 public ByteArrayAssert hasSameSizeAs(Iterable<?> other) {
   arrays.assertHasSameSizeAs(info, actual, other);
   return this;
 }
예제 #16
0
 /** {@inheritDoc} */
 public ByteArrayAssert usingDefaultElementComparator() {
   this.arrays = ByteArrays.instance();
   return myself;
 }
예제 #17
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 ByteArrayAssert contains(byte... values) {
   arrays.assertContains(info, actual, values);
   return this;
 }
예제 #18
0
 @Override
 public ByteArrayAssert usingDefaultComparator() {
   super.usingDefaultComparator();
   this.arrays = ByteArrays.instance();
   return myself;
 }