Best Assertj code snippet using org.assertj.core.api.AbstractByteArrayAssert.toPrimitiveByteArray
Source:AbstractByteArrayAssert.java
...225 * @since 3.19.0226 */227 public SELF contains(Byte[] values) {228 requireNonNullParameter(values, "values");229 arrays.assertContains(info, actual, toPrimitiveByteArray(values));230 return myself;231 }232 /**233 * Verifies that the actual array contains the given values, in any order.234 * <p>235 * Example:236 * <pre><code class='java'> // assertion will pass237 * assertThat(new byte[] { 1, 2, 3 }).contains(1, 2);238 * assertThat(new byte[] { 1, 2, 3 }).contains(3, 1);239 * assertThat(new byte[] { 1, 2, 3 }).contains(1, 3, 2);240 *241 * // assertion will fail242 * assertThat(new byte[] { 1, 2, 3 }).contains(1, 4);243 * assertThat(new byte[] { 1, 2, 3 }).contains(4, 7);</code></pre>244 *245 * @param values the given values.246 * @return {@code this} assertion object.247 * @throws NullPointerException if the given argument is {@code null}.248 * @throws IllegalArgumentException if the given argument is an empty array.249 * @throws AssertionError if the actual array is {@code null}.250 * @throws AssertionError if the actual array does not contain the given values.251 * @since 2.6.0 / 3.6.0252 */253 public SELF contains(int... values) {254 arrays.assertContains(info, actual, values);255 return myself;256 }257 /**258 * Verifies that the actual array contains only the given values and nothing else, in any order.259 * <p>260 * Example:261 * <pre><code class='java'> // assertions will pass262 * assertThat(new byte[] { 1, 2, 3 }).containsOnly((byte) 1, (byte) 2, (byte) 3);263 * assertThat(new byte[] { 1, 2, 3 }).containsOnly((byte) 2, (byte) 3, (byte) 1);264 * assertThat(new byte[] { 1, 1, 2 }).containsOnly((byte) 1, (byte) 2);265 *266 * // assertions will fail267 * assertThat(new byte[] { 1, 2, 3 }).containsOnly((byte) 1, (byte) 2, (byte) 3, (byte) 4);268 * assertThat(new byte[] { 1, 2, 3 }).containsOnly((byte) 4, (byte) 7);</code></pre>269 *270 * @param values the given values.271 * @return {@code this} assertion object.272 * @throws NullPointerException if the given argument is {@code null}.273 * @throws IllegalArgumentException if the given argument is an empty array.274 * @throws AssertionError if the actual array is {@code null}.275 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array276 * contains some277 * or none of the given values, or the actual array contains more values than the278 * given ones.279 */280 public SELF containsOnly(byte... values) {281 arrays.assertContainsOnly(info, actual, values);282 return myself;283 }284 /**285 * Verifies that the actual array contains only the values of the given array and nothing else, in any order.286 * <p>287 * Example:288 * <pre><code class='java'> // assertions will pass289 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(new Byte[] { 1, 2, 3 });290 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(new Byte[] { 2, 3, 1 });291 * assertThat(new byte[] { 1, 1, 2 }).containsOnly(new Byte[] { 1, 2 });292 *293 * // assertions will fail294 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(new Byte[] { 1, 2, 3, 4 });295 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(new Byte[] { 4, 7 });</code></pre>296 *297 * @param values the given values.298 * @return {@code this} assertion object.299 * @throws NullPointerException if the given argument is {@code null}.300 * @throws IllegalArgumentException if the given argument is an empty array.301 * @throws AssertionError if the actual array is {@code null}.302 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array303 * contains some304 * or none of the given values, or the actual array contains more values than the305 * given ones.306 * @since 3.19.0307 */308 public SELF containsOnly(Byte[] values) {309 requireNonNullParameter(values, "values");310 arrays.assertContainsOnly(info, actual, toPrimitiveByteArray(values));311 return myself;312 }313 /**314 * Verifies that the actual array contains only the given values and nothing else, in any order.315 * <p>316 * Example:317 * <pre><code class='java'> // assertion will pass318 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(1, 2, 3);319 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(2, 3, 1);320 * assertThat(new byte[] { 1, 1, 2 }).containsOnly(1, 2);321 *322 * // assertion will fail323 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(1, 2, 3, 4);324 * assertThat(new byte[] { 1, 2, 3 }).containsOnly(4, 7);</code></pre>325 *326 * @param values the given values.327 * @return {@code this} assertion object.328 * @throws NullPointerException if the given argument is {@code null}.329 * @throws IllegalArgumentException if the given argument is an empty array.330 * @throws AssertionError if the actual array is {@code null}.331 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array332 * contains some333 * or none of the given values, or the actual array contains more values than the334 * given ones.335 * @since 2.6.0 / 3.6.0336 */337 public SELF containsOnly(int... values) {338 arrays.assertContainsOnly(info, actual, values);339 return myself;340 }341 /**342 * Verifies that the actual array contains the given values only once.343 * <p>344 * Examples :345 * <pre><code class='java'> // assertion will pass346 * assertThat(new byte[] { 1, 2, 3 }).containsOnlyOnce((byte) 1, (byte) 2);347 *348 * // assertions will fail349 * assertThat(new byte[] { 1, 2, 1 }).containsOnlyOnce((byte) 1);350 * assertThat(new byte[] { 1, 2, 3 }).containsOnlyOnce((byte) 4);351 * assertThat(new byte[] { 1, 2, 3, 3 }).containsOnlyOnce((byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5);</code></pre>352 *353 * @param values the given values.354 * @return {@code this} assertion object.355 * @throws NullPointerException if the given argument is {@code null}.356 * @throws IllegalArgumentException if the given argument is an empty array.357 * @throws AssertionError if the actual array is {@code null}.358 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group359 * contains some360 * or none of the given values, or the actual group contains more than once these361 * values.362 */363 public SELF containsOnlyOnce(byte... values) {364 arrays.assertContainsOnlyOnce(info, actual, values);365 return myself;366 }367 /**368 * Verifies that the actual array contains the values of the given array only once.369 * <p>370 * Examples :371 * <pre><code class='java'> // assertion will pass372 * assertThat(new byte[] { 1, 2, 3 }).containsOnlyOnce(new Byte[] { 1, 2 });373 *374 * // assertions will fail375 * assertThat(new byte[] { 1, 2, 1 }).containsOnlyOnce(new Byte[] { 1 });376 * assertThat(new byte[] { 1, 2, 3 }).containsOnlyOnce(new Byte[] { 4 });377 * assertThat(new byte[] { 1, 2, 3, 3 }).containsOnlyOnce(new Byte[] { 0, 1, 2, 3, 4, 5 });</code></pre>378 *379 * @param values the given values.380 * @return {@code this} assertion object.381 * @throws NullPointerException if the given argument is {@code null}.382 * @throws IllegalArgumentException if the given argument is an empty array.383 * @throws AssertionError if the actual array is {@code null}.384 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group385 * contains some386 * or none of the given values, or the actual group contains more than once these387 * values.388 * @since 3.19.0389 */390 public SELF containsOnlyOnce(Byte[] values) {391 requireNonNullParameter(values, "values");392 arrays.assertContainsOnlyOnce(info, actual, toPrimitiveByteArray(values));393 return myself;394 }395 /**396 * Verifies that the actual array contains the given values only once.397 * <p>398 * Examples :399 * <pre><code class='java'> // assertion will pass400 * assertThat(new byte[] { 1, 2, 3 }).containsOnlyOnce(1, 2);401 *402 * // assertions will fail403 * assertThat(new byte[] { 1, 2, 1 }).containsOnlyOnce(1);404 * assertThat(new byte[] { 1, 2, 3 }).containsOnlyOnce(4);405 * assertThat(new byte[] { 1, 2, 3, 3 }).containsOnlyOnce(0, 1, 2, 3, 4, 5);</code></pre>406 *407 * @param values the given values.408 * @return {@code this} assertion object.409 * @throws NullPointerException if the given argument is {@code null}.410 * @throws IllegalArgumentException if the given argument is an empty array.411 * @throws AssertionError if the actual array is {@code null}.412 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group413 * contains some414 * or none of the given values, or the actual group contains more than once these415 * values.416 * @since 2.6.0 / 3.6.0417 */418 public SELF containsOnlyOnce(int... values) {419 arrays.assertContainsOnlyOnce(info, actual, values);420 return myself;421 }422 /**423 * Verifies that the actual array contains the given sequence, without any other values between them.424 * <p>425 * Example:426 * <pre><code class='java'> // assertion will pass427 * assertThat(new byte[] { 1, 2, 3 }).containsSequence((byte) 1, (byte) 2);428 * assertThat(new byte[] { 1, 2, 3 }).containsSequence((byte) 1, (byte) 2, (byte) 3);429 * assertThat(new byte[] { 1, 2, 3 }).containsSequence((byte) 2, (byte) 3);430 *431 * // assertion will fail432 * assertThat(new byte[] { 1, 2, 3 }).containsSequence((byte) 1, (byte) 3);433 * assertThat(new byte[] { 1, 2, 3 }).containsSequence((byte) 4, (byte) 7);</code></pre>434 *435 * @param sequence the sequence of values to look for.436 * @return myself assertion object.437 * @throws AssertionError if the actual array is {@code null}.438 * @throws AssertionError if the given array is {@code null}.439 * @throws AssertionError if the actual array does not contain the given sequence.440 */441 public SELF containsSequence(byte... sequence) {442 arrays.assertContainsSequence(info, actual, sequence);443 return myself;444 }445 /**446 * Verifies that the actual array contains the given sequence, without any other values between them.447 * <p>448 * Example:449 * <pre><code class='java'> // assertion will pass450 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(new Byte[] { 1, 2 });451 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(new Byte[] { 1, 2, 3 });452 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(new Byte[] { 2, 3 });453 *454 * // assertion will fail455 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(new Byte[] { 1, 3 });456 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(new Byte[] { 4, 7 });</code></pre>457 *458 * @param sequence the sequence of values to look for.459 * @return myself assertion object.460 * @throws AssertionError if the actual array is {@code null}.461 * @throws AssertionError if the given array is {@code null}.462 * @throws AssertionError if the actual array does not contain the given sequence.463 * @since 3.19.0464 */465 public SELF containsSequence(Byte[] sequence) {466 requireNonNullParameter(sequence, "sequence");467 arrays.assertContainsSequence(info, actual, toPrimitiveByteArray(sequence));468 return myself;469 }470 /**471 * Verifies that the actual array contains the given sequence, without any other values between them.472 * <p>473 * Example:474 * <pre><code class='java'> // assertion will pass475 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(1, 2);476 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(1, 2, 3);477 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(2, 3);478 *479 * // assertion will fail480 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(1, 3);481 * assertThat(new byte[] { 1, 2, 3 }).containsSequence(4, 7);</code></pre>482 *483 * @param sequence the sequence of values to look for.484 * @return myself assertion object.485 * @throws AssertionError if the actual array is {@code null}.486 * @throws AssertionError if the given array is {@code null}.487 * @throws AssertionError if the actual array does not contain the given sequence.488 * @since 2.6.0 / 3.6.0489 */490 public SELF containsSequence(int... sequence) {491 arrays.assertContainsSequence(info, actual, sequence);492 return myself;493 }494 /**495 * Verifies that the actual array contains the given subsequence (possibly with other values between them).496 * <p>497 * Example:498 * <pre><code class='java'> // assertion will pass499 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence((byte) 1, (byte) 2, (byte) 3);500 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence((byte) 1, (byte) 2);501 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence((byte) 1, (byte) 3);502 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence((byte) 2, (byte) 3);503 *504 * // assertion will fail505 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence((byte) 2, (byte) 1);506 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence((byte) 4, (byte) 7);</code></pre>507 *508 * @param subsequence the subsequence of values to look for.509 * @return myself assertion object.510 * @throws AssertionError if the actual array is {@code null}.511 * @throws AssertionError if the given array is {@code null}.512 * @throws AssertionError if the actual array does not contain the given subsequence.513 */514 public SELF containsSubsequence(byte... subsequence) {515 arrays.assertContainsSubsequence(info, actual, subsequence);516 return myself;517 }518 /**519 * Verifies that the actual array contains the given subsequence (possibly with other values between them).520 * <p>521 * Example:522 * <pre><code class='java'> // assertion will pass523 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(new Byte[] { 1, 2, 3 });524 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(new Byte[] { 1, 2 });525 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(new Byte[] { 1, 3 });526 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(new Byte[] { 2, 3 });527 *528 * // assertion will fail529 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(new Byte[] { 2, 1 });530 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(new Byte[] { 4, 7 });</code></pre>531 *532 * @param subsequence the subsequence of values to look for.533 * @return myself assertion object.534 * @throws AssertionError if the actual array is {@code null}.535 * @throws AssertionError if the given array is {@code null}.536 * @throws AssertionError if the actual array does not contain the given subsequence.537 * @since 3.19.0538 */539 public SELF containsSubsequence(Byte[] subsequence) {540 requireNonNullParameter(subsequence, "subsequence");541 arrays.assertContainsSubsequence(info, actual, toPrimitiveByteArray(subsequence));542 return myself;543 }544 /**545 * Verifies that the actual array contains the given subsequence (possibly with other values between them).546 * <p>547 * Example:548 * <pre><code class='java'> // assertion will pass549 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(1, 2, 3);550 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(1, 2);551 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(1, 3);552 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(2, 3);553 *554 * // assertion will fail555 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(2, 1);556 * assertThat(new byte[] { 1, 2, 3 }).containsSubsequence(4, 7);</code></pre>557 *558 * @param subsequence the subsequence of values to look for.559 * @return myself assertion object.560 * @throws AssertionError if the actual array is {@code null}.561 * @throws AssertionError if the given array is {@code null}.562 * @throws AssertionError if the actual array does not contain the given subsequence.563 * @since 2.6.0 / 3.6.0564 */565 public SELF containsSubsequence(int... subsequence) {566 arrays.assertContainsSubsequence(info, actual, subsequence);567 return myself;568 }569 /**570 * Verifies that the actual array contains the given value at the given index.571 * <p>572 * Example:573 * <pre><code class='java'> // assertion will pass574 * assertThat(new byte[] { 1, 2, 3 }).contains((byte) 1, atIndex(O));575 * assertThat(new byte[] { 1, 2, 3 }).contains((byte) 3, atIndex(2));576 *577 * // assertion will fail578 * assertThat(new byte[] { 1, 2, 3 }).contains((byte) 1, atIndex(1));579 * assertThat(new byte[] { 1, 2, 3 }).contains((byte) 4, atIndex(2));</code></pre>580 *581 * @param value the value to look for.582 * @param index the index where the value should be stored in the actual array.583 * @return myself assertion object.584 * @throws AssertionError if the actual array is {@code null} or empty.585 * @throws NullPointerException if the given {@code Index} is {@code null}.586 * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of587 * the actual array.588 * @throws AssertionError if the actual array does not contain the given value at the given index.589 */590 public SELF contains(byte value, Index index) {591 arrays.assertContains(info, actual, value, index);592 return myself;593 }594 /**595 * Verifies that the actual array contains the given value at the given index.596 * <p>597 * Example:598 * <pre><code class='java'> // assertion will pass599 * assertThat(new byte[] { 1, 2, 3 }).contains(1, atIndex(O));600 * assertThat(new byte[] { 1, 2, 3 }).contains(3, atIndex(2));601 *602 * // assertion will fail603 * assertThat(new byte[] { 1, 2, 3 }).contains(1, atIndex(1));604 * assertThat(new byte[] { 1, 2, 3 }).contains(4, atIndex(2));</code></pre>605 *606 * @param value the value to look for.607 * @param index the index where the value should be stored in the actual array.608 * @return myself assertion object.609 * @throws AssertionError if the actual array is {@code null} or empty.610 * @throws NullPointerException if the given {@code Index} is {@code null}.611 * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of612 * the actual array.613 * @throws AssertionError if the actual array does not contain the given value at the given index.614 * @since 2.6.0 / 3.6.0615 */616 public SELF contains(int value, Index index) {617 arrays.assertContains(info, actual, value, index);618 return myself;619 }620 /**621 * Verifies that the actual array does not contain the given values.622 * <p>623 * Example:624 * <pre><code class='java'> // assertion will pass625 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain((byte) 4);626 *627 * // assertion will fail628 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain((byte) 2);</code></pre>629 *630 * @param values the given values.631 * @return {@code this} assertion object.632 * @throws NullPointerException if the given argument is {@code null}.633 * @throws IllegalArgumentException if the given argument is an empty array.634 * @throws AssertionError if the actual array is {@code null}.635 * @throws AssertionError if the actual array contains any of the given values.636 */637 public SELF doesNotContain(byte... values) {638 arrays.assertDoesNotContain(info, actual, values);639 return myself;640 }641 /**642 * Verifies that the actual array does not contain the values of the given array.643 * <p>644 * Example:645 * <pre><code class='java'> // assertion will pass646 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(new Byte[] { 4 });647 *648 * // assertion will fail649 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(new Byte[] { 2 });</code></pre>650 *651 * @param values the given values.652 * @return {@code this} assertion object.653 * @throws NullPointerException if the given argument is {@code null}.654 * @throws IllegalArgumentException if the given argument is an empty array.655 * @throws AssertionError if the actual array is {@code null}.656 * @throws AssertionError if the actual array contains any of the given values.657 * @since 3.19.0658 */659 public SELF doesNotContain(Byte[] values) {660 requireNonNullParameter(values, "values");661 arrays.assertDoesNotContain(info, actual, toPrimitiveByteArray(values));662 return myself;663 }664 /**665 * Verifies that the actual array does not contain the given values.666 * <p>667 * Example:668 * <pre><code class='java'> // assertion will pass669 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(4);670 *671 * // assertion will fail672 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(2);</code></pre>673 *674 * @param values the given values.675 * @return {@code this} assertion object.676 * @throws NullPointerException if the given argument is {@code null}.677 * @throws IllegalArgumentException if the given argument is an empty array.678 * @throws AssertionError if the actual array is {@code null}.679 * @throws AssertionError if the actual array contains any of the given values.680 * @since 2.6.0 / 3.6.0681 */682 public SELF doesNotContain(int... values) {683 arrays.assertDoesNotContain(info, actual, values);684 return myself;685 }686 /**687 * Verifies that the actual array does not contain the given value at the given index.688 * <p>689 * Example:690 * <pre><code class='java'> // assertion will pass691 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain((byte) 1, atIndex(1));692 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain((byte) 2, atIndex(0));693 *694 * // assertion will fail695 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain((byte) 1, atIndex(0));696 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain((byte) 2, atIndex(1));</code></pre>697 *698 * @param value the value to look for.699 * @param index the index where the value should be stored in the actual array.700 * @return myself assertion object.701 * @throws AssertionError if the actual array is {@code null}.702 * @throws NullPointerException if the given {@code Index} is {@code null}.703 * @throws AssertionError if the actual array contains the given value at the given index.704 */705 public SELF doesNotContain(byte value, Index index) {706 arrays.assertDoesNotContain(info, actual, value, index);707 return myself;708 }709 /**710 * Verifies that the actual array does not contain the given value at the given index.711 * <p>712 * Example:713 * <pre><code class='java'> // assertion will pass714 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(1, atIndex(1));715 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(2, atIndex(0));716 *717 * // assertion will fail718 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(1, atIndex(0));719 * assertThat(new byte[] { 1, 2, 3 }).doesNotContain(2, atIndex(1));</code></pre>720 *721 * @param value the value to look for.722 * @param index the index where the value should be stored in the actual array.723 * @return myself assertion object.724 * @throws AssertionError if the actual array is {@code null}.725 * @throws NullPointerException if the given {@code Index} is {@code null}.726 * @throws AssertionError if the actual array contains the given value at the given index.727 * @since 2.6.0 / 3.6.0728 */729 public SELF doesNotContain(int value, Index index) {730 arrays.assertDoesNotContain(info, actual, value, index);731 return myself;732 }733 /**734 * Verifies that the actual array does not contain duplicates.735 * <p>736 * Example:737 * <pre><code class='java'> // assertion will pass738 * assertThat(new byte[] { 1, 2, 3 }).doesNotHaveDuplicates();739 *740 * // assertion will fail741 * assertThat(new byte[] { 1, 1, 2, 3 }).doesNotHaveDuplicates();</code></pre>742 *743 * @return {@code this} assertion object.744 * @throws AssertionError if the actual array is {@code null}.745 * @throws AssertionError if the actual array contains duplicates.746 */747 public SELF doesNotHaveDuplicates() {748 arrays.assertDoesNotHaveDuplicates(info, actual);749 return myself;750 }751 /**752 * Verifies that the actual array starts with the given sequence of values, without any other values between them.753 * Similar to <code>{@link #containsSequence(byte...)}</code>, but it also verifies that the first element in the754 * sequence is also first element of the actual array.755 * <p>756 * Example:757 * <pre><code class='java'> // assertion will pass758 * assertThat(new byte[] { 1, 2, 3 }).startsWith((byte) 1, (byte) 2);759 *760 * // assertion will fail761 * assertThat(new byte[] { 1, 2, 3 }).startsWith((byte) 2, (byte) 3);</code></pre>762 *763 * @param sequence the sequence of values to look for.764 * @return myself assertion object.765 * @throws NullPointerException if the given argument is {@code null}.766 * @throws IllegalArgumentException if the given argument is an empty array.767 * @throws AssertionError if the actual array is {@code null}.768 * @throws AssertionError if the actual array does not start with the given sequence.769 */770 public SELF startsWith(byte... sequence) {771 arrays.assertStartsWith(info, actual, sequence);772 return myself;773 }774 /**775 * Verifies that the actual array starts with the given sequence of values, without any other values between them.776 * Similar to <code>{@link #containsSequence(byte...)}</code>, but it also verifies that the first element in the777 * sequence is also first element of the actual array.778 * <p>779 * Example:780 * <pre><code class='java'> // assertion will pass781 * assertThat(new byte[] { 1, 2, 3 }).startsWith(new Byte[] { 1, 2 });782 *783 * // assertion will fail784 * assertThat(new byte[] { 1, 2, 3 }).startsWith(new Byte[] { 2, 3 });</code></pre>785 *786 * @param sequence the sequence of values to look for.787 * @return myself assertion object.788 * @throws NullPointerException if the given argument is {@code null}.789 * @throws IllegalArgumentException if the given argument is an empty array.790 * @throws AssertionError if the actual array is {@code null}.791 * @throws AssertionError if the actual array does not start with the given sequence.792 * @since 3.19.0793 */794 public SELF startsWith(Byte[] sequence) {795 requireNonNullParameter(sequence, "sequence");796 arrays.assertStartsWith(info, actual, toPrimitiveByteArray(sequence));797 return myself;798 }799 /**800 * Verifies that the actual array starts with the given sequence of values, without any other values between them.801 * Similar to <code>{@link #containsSequence(byte...)}</code>, but it also verifies that the first element in the802 * sequence is also first element of the actual array.803 * <p>804 * Example:805 * <pre><code class='java'> // assertion will pass806 * assertThat(new byte[] { 1, 2, 3 }).startsWith(1, 2);807 *808 * // assertion will fail809 * assertThat(new byte[] { 1, 2, 3 }).startsWith(2, 3);</code></pre>810 *811 * @param sequence the sequence of values to look for.812 * @return myself assertion object.813 * @throws NullPointerException if the given argument is {@code null}.814 * @throws IllegalArgumentException if the given argument is an empty array.815 * @throws AssertionError if the actual array is {@code null}.816 * @throws AssertionError if the actual array does not start with the given sequence.817 * @since 2.6.0 / 3.6.0818 */819 public SELF startsWith(int... sequence) {820 arrays.assertStartsWith(info, actual, sequence);821 return myself;822 }823 /**824 * Verifies that the actual array ends with the given sequence of values, without any other values between them.825 * Similar to <code>{@link #containsSequence(byte...)}</code>, but it also verifies that the last element in the826 * sequence is also last element of the actual array.827 * <p>828 * Example:829 * <pre><code class='java'> // assertion will pass830 * assertThat(new byte[] { 1, 2, 3 }).endsWith((byte) 2, (byte) 3);831 *832 * // assertion will fail833 * assertThat(new byte[] { 1, 2, 3 }).endsWith((byte) 3, (byte) 4);</code></pre>834 *835 * @param sequence the sequence of values to look for.836 * @return myself assertion object.837 * @throws NullPointerException if the given argument is {@code null}.838 * @throws IllegalArgumentException if the given argument is an empty array.839 * @throws AssertionError if the actual array is {@code null}.840 * @throws AssertionError if the actual array does not end with the given sequence.841 */842 public SELF endsWith(byte... sequence) {843 arrays.assertEndsWith(info, actual, sequence);844 return myself;845 }846 /**847 * Verifies that the actual array ends with the given sequence of values, without any other values between them.848 * Similar to <code>{@link #containsSequence(byte...)}</code>, but it also verifies that the last element in the849 * sequence is also last element of the actual array.850 * <p>851 * Example:852 * <pre><code class='java'> // assertion will pass853 * assertThat(new byte[] { 1, 2, 3 }).endsWith(new Byte[] { 2, 3 });854 *855 * // assertion will fail856 * assertThat(new byte[] { 1, 2, 3 }).endsWith(new Byte[] { 3, 4 });</code></pre>857 *858 * @param sequence the sequence of values to look for.859 * @return myself assertion object.860 * @throws NullPointerException if the given argument is {@code null}.861 * @throws IllegalArgumentException if the given argument is an empty array.862 * @throws AssertionError if the actual array is {@code null}.863 * @throws AssertionError if the actual array does not end with the given sequence.864 * @since 3.19.0865 */866 public SELF endsWith(Byte[] sequence) {867 requireNonNullParameter(sequence, "sequence");868 arrays.assertEndsWith(info, actual, toPrimitiveByteArray(sequence));869 return myself;870 }871 /**872 * Verifies that the actual array ends with the given sequence of values, without any other values between them.873 * Similar to <code>{@link #containsSequence(byte...)}</code>, but it also verifies that the last element in the874 * sequence is also last element of the actual array.875 * <p>876 * Example:877 * <pre><code class='java'> // assertion will pass878 * assertThat(new byte[] { 1, 2, 3 }).endsWith(2, 3);879 *880 * // assertion will fail881 * assertThat(new byte[] { 1, 2, 3 }).endsWith(3, 4);</code></pre>882 *883 * @param sequence the sequence of values to look for.884 * @return myself assertion object.885 * @throws NullPointerException if the given argument is {@code null}.886 * @throws IllegalArgumentException if the given argument is an empty array.887 * @throws AssertionError if the actual array is {@code null}.888 * @throws AssertionError if the actual array does not end with the given sequence.889 * @since 2.6.0 / 3.6.0890 */891 public SELF endsWith(int... sequence) {892 arrays.assertEndsWith(info, actual, sequence);893 return myself;894 }895 /** {@inheritDoc} */896 @Override897 public SELF isSorted() {898 arrays.assertIsSorted(info, actual);899 return myself;900 }901 /** {@inheritDoc} */902 @Override903 public SELF isSortedAccordingTo(Comparator<? super Byte> comparator) {904 arrays.assertIsSortedAccordingToComparator(info, actual, comparator);905 return myself;906 }907 /** {@inheritDoc} */908 @Override909 @CheckReturnValue910 public SELF usingElementComparator(Comparator<? super Byte> customComparator) {911 this.arrays = new ByteArrays(new ComparatorBasedComparisonStrategy(customComparator));912 return myself;913 }914 /** {@inheritDoc} */915 @Override916 @CheckReturnValue917 public SELF usingDefaultElementComparator() {918 this.arrays = ByteArrays.instance();919 return myself;920 }921 /**922 * Verifies that the actual group contains only the given values and nothing else, <b>in order</b>.923 * <p>924 * <b>Warning</b>: for performance reason, this assertion compares arrays directly meaning that <b>it does not honor element925 * comparator</b> set with {@link #usingElementComparator(Comparator)}.926 * <p>927 * Example :928 * <pre><code class='java'> // assertion will pass929 * assertThat(new byte[] { 1, 2, 3 }).containsExactly((byte) 1, (byte) 2, (byte) 3);930 *931 * // assertion will fail as actual and expected order differ932 * assertThat(new byte[] { 1, 2, 3 }).containsExactly((byte) 2, (byte) 1, (byte) 3);</code></pre>933 *934 * @param values the given values.935 * @return {@code this} assertion object.936 * @throws NullPointerException if the given argument is {@code null}.937 * @throws AssertionError if the actual group is {@code null}.938 * @throws AssertionError if the actual group does not contain the given values with same order, i.e. the actual939 * group940 * contains some or none of the given values, or the actual group contains more values941 * than the given ones942 * or values are the same but the order is not.943 */944 public SELF containsExactly(byte... values) {945 // In #1801 we changed objects.assertEqual to arrays.assertContainsExactly to get a better error message but it came with946 // significant performance degradation as #1898 showed.947 // We can't get the best of both approaches even if we call assertContainsExactly only when assertEqual, assertContainsExactly948 // would take a long time to compute the diff between both arrays.949 // We can at least solve the representation of byte[] arrays so that they show the bytes950 objects.assertEqual(info, actual, values);951 return myself;952 }953 /**954 * Verifies that the actual group contains only the values of the given array and nothing else, <b>in order</b>.955 * <p>956 * <b>Warning</b>: for performance reason, this assertion compares arrays directly meaning that <b>it does not honor element957 * comparator</b> set with {@link #usingElementComparator(Comparator)}.958 * <p>959 * Example :960 * <pre><code class='java'> // assertion will pass961 * assertThat(new byte[] { 1, 2, 3 }).containsExactly(new Byte[] { 1, 2, 3 });962 *963 * // assertion will fail as actual and expected order differ964 * assertThat(new byte[] { 1, 2, 3 }).containsExactly(new Byte[] { 2, 1, 3 });</code></pre>965 *966 * @param values the given values.967 * @return {@code this} assertion object.968 * @throws NullPointerException if the given argument is {@code null}.969 * @throws AssertionError if the actual group is {@code null}.970 * @throws AssertionError if the actual group does not contain the given values with same order, i.e. the actual971 * group972 * contains some or none of the given values, or the actual group contains more values973 * than the given ones974 * or values are the same but the order is not.975 * @since 3.19.0976 */977 public SELF containsExactly(Byte[] values) {978 // In #1801 we changed objects.assertEqual to arrays.assertContainsExactly to get a better error message but it came with979 // significant performance degradation as #1898 showed.980 // We can't get the best of both approaches even if we call assertContainsExactly only when assertEqual, assertContainsExactly981 // would take a long time to compute the diff between both arrays.982 // We can at least solve the representation of byte[] arrays so that they show the bytes983 requireNonNullParameter(values, "values");984 objects.assertEqual(info, actual, toPrimitiveByteArray(values));985 return myself;986 }987 /**988 * Verifies that the actual group contains only the given values and nothing else, <b>in order</b>.989 * <p>990 * Example :991 * <pre><code class='java'> // assertion will pass992 * assertThat(new byte[] { 1, 2, 3 }).containsExactly(1, 2, 3);993 *994 * // assertion will fail as actual and expected order differ995 * assertThat(new byte[] { 1, 2, 3 }).containsExactly(2, 1, 3);</code></pre>996 *997 * @param values the given values.998 * @return {@code this} assertion object.999 * @throws NullPointerException if the given argument is {@code null}.1000 * @throws AssertionError if the actual group is {@code null}.1001 * @throws AssertionError if the actual group does not contain the given values with same order, i.e. the actual1002 * group1003 * contains some or none of the given values, or the actual group contains more values1004 * than the given ones1005 * or values are the same but the order is not.1006 * @since 2.6.0 / 3.6.01007 */1008 public SELF containsExactly(int... values) {1009 arrays.assertContainsExactly(info, actual, arrays.toByteArray(values));1010 return myself;1011 }1012 /**1013 * Verifies that the actual group contains exactly the given values and nothing else, <b>in any order</b>.<br>1014 * <p>1015 * Example :1016 * <pre><code class='java'> // assertions will pass1017 * assertThat(new byte[] { 1, 2 }).containsExactlyInAnyOrder((byte) 1, (byte) 2);1018 * assertThat(new byte[] { 1, 2, 1 }).containsExactlyInAnyOrder((byte) 1, (byte) 1, (byte) 2);1019 *1020 * // assertions will fail1021 * assertThat(new byte[] { 1, 2 }).containsExactlyInAnyOrder((byte) 1);1022 * assertThat(new byte[] { 1 }).containsExactlyInAnyOrder((byte) 1, (byte) 2);1023 * assertThat(new byte[] { 1, 2, 1 }).containsExactlyInAnyOrder((byte) 1, (byte) 2);</code></pre>1024 *1025 * @param values the given values.1026 * @return {@code this} assertion object.1027 * @throws NullPointerException if the given argument is {@code null}.1028 * @throws AssertionError if the actual group is {@code null}.1029 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group1030 * contains some or none of the given values, or the actual group contains more values than the given ones.1031 * @since 2.6.0 / 3.6.01032 */1033 public SELF containsExactlyInAnyOrder(byte... values) {1034 arrays.assertContainsExactlyInAnyOrder(info, actual, values);1035 return myself;1036 }1037 /**1038 * Verifies that the actual group contains exactly the values of the given array and nothing else, <b>in any order</b>.<br>1039 * <p>1040 * Example :1041 * <pre><code class='java'> // assertions will pass1042 * assertThat(new byte[] { 1, 2 }).containsExactlyInAnyOrder(new Byte[] { 1, 2 });1043 * assertThat(new byte[] { 1, 2, 1 }).containsExactlyInAnyOrder(new Byte[] { 1, 1, 2 });1044 *1045 * // assertions will fail1046 * assertThat(new byte[] { 1, 2 }).containsExactlyInAnyOrder(new Byte[] { 1 });1047 * assertThat(new byte[] { 1 }).containsExactlyInAnyOrder(new Byte[] { 1, 2 });1048 * assertThat(new byte[] { 1, 2, 1 }).containsExactlyInAnyOrder(new Byte[] { 1, 2 });</code></pre>1049 *1050 * @param values the given values.1051 * @return {@code this} assertion object.1052 * @throws NullPointerException if the given argument is {@code null}.1053 * @throws AssertionError if the actual group is {@code null}.1054 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group1055 * contains some or none of the given values, or the actual group contains more values than the given ones.1056 * @since 3.19.01057 */1058 public SELF containsExactlyInAnyOrder(Byte[] values) {1059 requireNonNullParameter(values, "values");1060 arrays.assertContainsExactlyInAnyOrder(info, actual, toPrimitiveByteArray(values));1061 return myself;1062 }1063 /**1064 * Verifies that the actual group contains exactly the given values and nothing else, <b>in any order</b>.<br>1065 * <p>1066 * Example :1067 * <pre><code class='java'> // assertions will pass1068 * assertThat(new byte[] { 1, 2 }).containsExactlyInAnyOrder(1, 2);1069 * assertThat(new byte[] { 1, 2, 1 }).containsExactlyInAnyOrder(1, 1, 2);1070 *1071 * // assertions will fail1072 * assertThat(new byte[] { 1, 2 }).containsExactlyInAnyOrder(1);1073 * assertThat(new byte[] { 1 }).containsExactlyInAnyOrder(1, 2);1074 * assertThat(new byte[] { 1, 2, 1 }).containsExactlyInAnyOrder(1, 2);</code></pre>1075 *1076 * @param values the given values.1077 * @return {@code this} assertion object.1078 * @throws NullPointerException if the given argument is {@code null}.1079 * @throws AssertionError if the actual group is {@code null}.1080 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group1081 * contains some or none of the given values, or the actual group contains more values than the given ones.1082 * @since 2.6.0 / 3.6.01083 */1084 public SELF containsExactlyInAnyOrder(int... values) {1085 arrays.assertContainsExactlyInAnyOrder(info, actual, arrays.toByteArray(values));1086 return myself;1087 }1088 /**1089 * Verifies that the actual array contains at least one of the given values.1090 * <p>1091 * Example :1092 * <pre><code class='java'> byte[] oneTwoThree = { 1, 2, 3 };1093 *1094 * // assertions will pass1095 * assertThat(oneTwoThree).containsAnyOf((byte)2)1096 * .containsAnyOf((byte)2, (byte)3)1097 * .containsAnyOf((byte)1, (byte)2, (byte)3)1098 * .containsAnyOf((byte)1, (byte)2, (byte)3, (byte)4)1099 * .containsAnyOf((byte)5, (byte)6, (byte)7, (byte)2);1100 *1101 * // assertions will fail1102 * assertThat(oneTwoThree).containsAnyOf((byte)4);1103 * assertThat(oneTwoThree).containsAnyOf((byte)4, (byte)5, (byte)6, (byte)7);</code></pre>1104 *1105 * @param values the values whose at least one which is expected to be in the array under test.1106 * @return {@code this} assertion object.1107 * @throws NullPointerException if the array of values is {@code null}.1108 * @throws IllegalArgumentException if the array of values is empty and the array under test is not empty.1109 * @throws AssertionError if the array under test is {@code null}.1110 * @throws AssertionError if the array under test does not contain any of the given {@code values}.1111 * @since 2.9.0 / 3.9.01112 */1113 public SELF containsAnyOf(byte... values) {1114 arrays.assertContainsAnyOf(info, actual, values);1115 return myself;1116 }1117 /**1118 * Verifies that the actual array contains at least one of the values of the given array.1119 * <p>1120 * Example :1121 * <pre><code class='java'> byte[] oneTwoThree = { 1, 2, 3 };1122 *1123 * // assertions will pass1124 * assertThat(oneTwoThree).containsAnyOf(new Byte[] { 2 })1125 * .containsAnyOf(new Byte[] { 2, 3 })1126 * .containsAnyOf(new Byte[] { 1, 2, 3 })1127 * .containsAnyOf(new Byte[] { 1, 2, 3, 4 })1128 * .containsAnyOf(new Byte[] { 5, 6, 7, 2 });1129 *1130 * // assertions will fail1131 * assertThat(oneTwoThree).containsAnyOf(new Byte[] { 4 });1132 * assertThat(oneTwoThree).containsAnyOf(new Byte[] { 4, 5, 6, 7 });</code></pre>1133 *1134 * @param values the values whose at least one which is expected to be in the array under test.1135 * @return {@code this} assertion object.1136 * @throws NullPointerException if the array of values is {@code null}.1137 * @throws IllegalArgumentException if the array of values is empty and the array under test is not empty.1138 * @throws AssertionError if the array under test is {@code null}.1139 * @throws AssertionError if the array under test does not contain any of the given {@code values}.1140 * @since 3.19.01141 */1142 public SELF containsAnyOf(Byte[] values) {1143 requireNonNullParameter(values, "values");1144 arrays.assertContainsAnyOf(info, actual, toPrimitiveByteArray(values));1145 return myself;1146 }1147 /**1148 * Verifies that the actual array contains at least one of the given values.1149 * <p>1150 * Example :1151 * <pre><code class='java'> byte[] oneTwoThree = { 1, 2, 3 };1152 *1153 * // assertions will pass1154 * assertThat(oneTwoThree).containsAnyOf(2)1155 * .containsAnyOf(2, 3)1156 * .containsAnyOf(1, 2, 3)1157 * .containsAnyOf(1, 2, 3, 4)1158 * .containsAnyOf(5, 6, 7, 2);1159 *1160 * // assertions will fail1161 * assertThat(oneTwoThree).containsAnyOf(4);1162 * assertThat(oneTwoThree).containsAnyOf(4, 5, 6, 7);</code></pre>1163 *1164 * @param values the values whose at least one which is expected to be in the array under test.1165 * @return {@code this} assertion object.1166 * @throws NullPointerException if the array of values is {@code null}.1167 * @throws IllegalArgumentException if the array of values is empty and the array under test is not empty.1168 * @throws AssertionError if the array under test is {@code null}.1169 * @throws AssertionError if the array under test does not contain any of the given {@code values}.1170 * @since 2.9.0 / 3.9.01171 */1172 public SELF containsAnyOf(int... values) {1173 arrays.assertContainsAnyOf(info, actual, arrays.toByteArray(values));1174 return myself;1175 }1176 /**1177 * Converts the actual byte array under test to an hexadecimal String and returns assertions for the computed String1178 * allowing String specific assertions from this call.1179 * <p>1180 * The Hex String representation is in upper case.1181 * <p>1182 * Example :1183 * <pre><code class='java'> byte[] bytes = new byte[] { -1, 0, 1 };1184 *1185 * // assertions will pass1186 * assertThat(bytes).asHexString()1187 * .startsWith("FF")1188 * .isEqualTo("FF0001");1189 *1190 * // assertion will fail1191 * assertThat(bytes).asHexString()1192 * .isEqualTo("FF0000");</code></pre>1193 *1194 * @return a String assertion object1195 *1196 * @since 3.16.01197 */1198 @CheckReturnValue1199 public AbstractStringAssert<?> asHexString() {1200 objects.assertNotNull(info, actual);1201 return assertThat(toHexString(actual));1202 }1203 /**1204 * Converts the actual byte[] under test to a String and returns assertions for the computed String1205 * allowing String specific assertions from this call.1206 * <p>1207 * The byte[] conversion to a String by decoding the specified bytes using the platform's default charset.1208 * <p>1209 * Example :1210 * <pre><code class='java'> byte[] bytes = new byte[] { -1, 0, 1 };1211 *1212 * // assertions will pass1213 * assertThat(bytes).asString()1214 * .startsWith("FF")1215 * .isEqualTo("FF0001");1216 *1217 * // assertion will fail1218 * assertThat(bytes).asString()1219 * .isEqualTo("FF0000");</code></pre>1220 *1221 * @return a String assertion object1222 *1223 * @since 3.17.01224 */1225 @Override1226 @CheckReturnValue1227 public AbstractStringAssert<?> asString() {1228 objects.assertNotNull(info, actual);1229 String actualAsString = new String(actual);1230 return assertThat(actualAsString);1231 }1232 /**1233 * Converts the actual byte[] under test to a String by decoding the specified bytes using the given charset1234 * and returns assertions for the computed String1235 * allowing String specific assertions from this call.1236 * <p>1237 * The byte[] conversion to a String by decoding the specified bytes using the platform's default charset.1238 * <p>1239 * Example :1240 * <pre><code class='java'> byte[] bytes = new byte[] { -1, 0, 1 };1241 *1242 * // assertions will pass1243 * assertThat(bytes).asString()1244 * .startsWith("FF")1245 * .isEqualTo("FF0001");1246 *1247 * // assertion will fail1248 * assertThat(bytes).asString()1249 * .isEqualTo("FF0000");</code></pre>1250 *1251 * @param charset the {@link Charset} to interpret the bytes to a String1252 * @return a String assertion object1253 *1254 * @since 3.17.01255 */1256 @CheckReturnValue1257 public AbstractStringAssert<?> asString(Charset charset) {1258 objects.assertNotNull(info, actual);1259 String actualAsString = new String(actual, charset);1260 return assertThat(actualAsString);1261 }1262 /**1263 * Encodes the actual array into a Base64 string, the encoded string becoming the new object under test.1264 * <p>1265 * Examples:1266 * <pre><code class='java'> // assertion succeeds1267 * assertThat("AssertJ".getBytes()).asBase64Encoded().isEqualTo("QXNzZXJ0Sg==");</code></pre>1268 *1269 * @return a new {@link StringAssert} instance whose string under test is the result of the encoding.1270 * @throws AssertionError if the actual value is {@code null}.1271 *1272 * @since 3.22.01273 */1274 @CheckReturnValue1275 public AbstractStringAssert<?> asBase64Encoded() {1276 objects.assertNotNull(info, actual);1277 return new StringAssert(Base64.getEncoder().encodeToString(actual)).withAssertionState(myself);1278 }1279 /**1280 * @deprecated use {@link #asBase64Encoded()} instead.1281 * <p>1282 * Encodes the actual array into a Base64 string, the encoded string becoming the new object under test.1283 * <p>1284 * Examples:1285 * <pre><code class='java'> // assertion succeeds1286 * assertThat("AssertJ".getBytes()).encodedAsBase64().isEqualTo("QXNzZXJ0Sg==");</code></pre>1287 *1288 * @return a new {@link StringAssert} instance whose string under test is the result of the encoding.1289 * @throws AssertionError if the actual value is {@code null}.1290 *1291 * @since 3.16.01292 */1293 @Deprecated1294 @CheckReturnValue1295 public AbstractStringAssert<?> encodedAsBase64() {1296 return asBase64Encoded();1297 }1298 private static byte[] toPrimitiveByteArray(Byte[] values) {1299 byte[] bytes = new byte[values.length];1300 range(0, values.length).forEach(i -> bytes[i] = values[i]);1301 return bytes;1302 }1303}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!