Best Assertj code snippet using org.assertj.core.util.Arrays.sizeOf
Source:Arrays.java
...117 if (!isArrayEmpty(array)) throw failures.failure(info, shouldBeEmpty(array));118 }119 void assertHasSize(AssertionInfo info, Failures failures, Object array, int expectedSize) {120 assertNotNull(info, array);121 int sizeOfActual = sizeOf(array);122 if (sizeOfActual != expectedSize) throw failures.failure(info, shouldHaveSize(array, sizeOfActual, expectedSize));123 }124 void assertHasSameSizeAs(AssertionInfo info, Object array, Iterable<?> other) {125 assertNotNull(info, array);126 hasSameSizeAsCheck(info, array, other, sizeOf(array));127 }128 public void assertHasSameSizeAs(AssertionInfo info, Object array, Object other) {129 assertNotNull(info, array);130 assertIsArray(info, array);131 assertIsArray(info, other);132 hasSameSizeAsCheck(info, array, other, sizeOf(array));133 }134 void assertContains(AssertionInfo info, Failures failures, Object actual, Object values) {135 if (commonChecks(info, actual, values)) return;136 Set<Object> notFound = new LinkedHashSet<>();137 int valueCount = sizeOf(values);138 for (int i = 0; i < valueCount; i++) {139 Object value = Array.get(values, i);140 if (!arrayContains(actual, value)) notFound.add(value);141 }142 if (!notFound.isEmpty())143 throw failures.failure(info, shouldContain(actual, values, notFound, comparisonStrategy));144 }145 void assertcontainsAll(AssertionInfo info, Failures failures, Object array, Iterable<?> iterable) {146 if (iterable == null) throw iterableToLookForIsNull();147 assertNotNull(info, array);148 Object[] values = newArrayList(iterable).toArray();149 Set<Object> notFound = new LinkedHashSet<>();150 for (Object value : values) {151 if (!arrayContains(array, value)) notFound.add(value);152 }153 if (!notFound.isEmpty())154 throw failures.failure(info, shouldContain(array, values, notFound, comparisonStrategy));155 }156 void assertContains(AssertionInfo info, Failures failures, Object array, Object value, Index index) {157 assertNotNull(info, array);158 assertNotEmpty(info, failures, array);159 checkIndexValueIsValid(index, sizeOf(array) - 1);160 Object actualElement = Array.get(array, index.value);161 if (!areEqual(actualElement, value))162 throw failures.failure(info, shouldContainAtIndex(array, value, index, Array.get(array, index.value),163 comparisonStrategy));164 }165 void assertNotEmpty(AssertionInfo info, Failures failures, Object array) {166 assertNotNull(info, array);167 if (isArrayEmpty(array)) throw failures.failure(info, shouldNotBeEmpty());168 }169 void assertDoesNotContain(AssertionInfo info, Failures failures, Object array, Object value, Index index) {170 assertNotNull(info, array);171 checkIndexValueIsValid(index, Integer.MAX_VALUE);172 if (index.value >= sizeOf(array)) return;173 if (areEqual(Array.get(array, index.value), value))174 throw failures.failure(info, shouldNotContainAtIndex(array, value, index, comparisonStrategy));175 }176 void assertContainsOnly(AssertionInfo info, Failures failures, Object actual, Object values) {177 if (commonChecks(info, actual, values)) return;178 List<Object> notExpected = asListWithoutDuplicatesAccordingToComparisonStrategy(actual);179 List<Object> notFound = containsOnly(notExpected, values);180 if (notExpected.isEmpty() && notFound.isEmpty()) return;181 throw failures.failure(info, shouldContainOnly(actual, values, notFound, notExpected, comparisonStrategy));182 }183 void assertContainsExactly(AssertionInfo info, Failures failures, Object actual, Object values) {184 if (commonChecks(info, actual, values)) return;185 assertNotNull(info, actual);186 assertIsArray(info, actual);187 assertIsArray(info, values);188 int actualSize = sizeOf(actual);189 int expectedSize = sizeOf(values);190 if (actualSize != expectedSize)191 throw failures.failure(info, shouldHaveSameSize(actual, values, actualSize, expectedSize, comparisonStrategy));192 List<Object> actualWithoutDuplicates = asListWithoutDuplicatesAccordingToComparisonStrategy(actual);193 List<Object> notFound = containsOnly(actualWithoutDuplicates, values);194 if (actualWithoutDuplicates.isEmpty() && notFound.isEmpty()) {195 // actual and values have the same elements but are they in the same order ?196 int arrayLength = sizeOf(actual);197 for (int i = 0; i < arrayLength; i++) {198 Object actualElement = Array.get(actual, i);199 Object expectedElement = Array.get(values, i);200 if (!areEqual(actualElement, expectedElement)) {201 throw failures.failure(info, elementsDifferAtIndex(actualElement, expectedElement, i, comparisonStrategy));202 }203 }204 return;205 }206 throw failures.failure(info,207 shouldContainExactly(actual, values, notFound, actualWithoutDuplicates, comparisonStrategy));208 }209 void assertContainsOnlyOnce(AssertionInfo info, Failures failures, Object actual, Object values) {210 if (commonChecks(info, actual, values))211 return;212 Iterable<?> actualDuplicates = comparisonStrategy.duplicatesFrom(asList(actual));213 Set<Object> notFound = new LinkedHashSet<>();214 Set<Object> notOnlyOnce = new LinkedHashSet<>();215 for (Object expectedElement : asList(values)) {216 if (!arrayContains(actual, expectedElement)) {217 notFound.add(expectedElement);218 } else if (iterableContains(actualDuplicates, expectedElement)) {219 notOnlyOnce.add(expectedElement);220 }221 }222 if (!notFound.isEmpty() || !notOnlyOnce.isEmpty())223 throw failures.failure(info, shouldContainsOnlyOnce(actual, values, notFound, notOnlyOnce, comparisonStrategy));224 // assertion succeeded225 }226 private List<Object> containsOnly(Collection<Object> actual, Object values) {227 List<Object> notFound = new ArrayList<>();228 for (Object o : asListWithoutDuplicatesAccordingToComparisonStrategy(values)) {229 if (iterableContains(actual, o)) {230 collectionRemoves(actual, o);231 } else {232 notFound.add(o);233 }234 }235 return notFound;236 }237 /**238 * build a Set with that avoid duplicates <b>according to given comparison strategy</b>239 * 240 * @param array to feed the Set we want to build241 * @return a Set without duplicates <b>according to given comparison strategy</b>242 */243 private List<Object> asListWithoutDuplicatesAccordingToComparisonStrategy(Object array) {244 List<Object> list = new ArrayList<>();245 int size = sizeOf(array);246 for (int i = 0; i < size; i++) {247 Object element = Array.get(array, i);248 if (!iterableContains(list, element)) list.add(element);249 }250 return list;251 }252 /**253 * Delegates to {@link ComparisonStrategy#iterableContains(Iterable, Object)}254 */255 private boolean iterableContains(Iterable<?> actual, Object value) {256 return comparisonStrategy.iterableContains(actual, value);257 }258 /**259 * Delegates to {@link ComparisonStrategy#iterableRemoves(Iterable, Object)}260 */261 private void collectionRemoves(Collection<?> actual, Object value) {262 comparisonStrategy.iterableRemoves(actual, value);263 }264 void assertContainsSequence(AssertionInfo info, Failures failures, Object actual, Object sequence) {265 if (commonChecks(info, actual, sequence)) return;266 // look for given sequence, stop check when there is not enough elements remaining in actual to contain sequence267 int lastIndexWhereSequeceCanBeFound = sizeOf(actual) - sizeOf(sequence);268 for (int actualIndex = 0; actualIndex <= lastIndexWhereSequeceCanBeFound; actualIndex++) {269 if (containsSequenceAtGivenIndex(actualIndex, actual, sequence)) return;270 }271 throw failures.failure(info, shouldContainSequence(actual, sequence, comparisonStrategy));272 }273 /**274 * Return true if actualArray contains exactly the given sequence at given starting index, false otherwise.275 * 276 * 277 * @param actualStartIndex the index to start looking for sequence in actualArray278 * @param actualArray the actual array to search sequence in279 * @param sequence the sequence to look for280 * @return true if actualArray contains exactly the given sequence at given starting index, false otherwise.281 */282 private boolean containsSequenceAtGivenIndex(int actualStartIndex, Object actualArray, Object sequence) {283 int sequenceSize = sizeOf(sequence);284 for (int i = 0; i < sequenceSize; i++) {285 if (areEqual(Array.get(sequence, i), Array.get(actualArray, i + actualStartIndex)))286 continue;287 return false;288 }289 return true;290 }291 void assertContainsSubsequence(AssertionInfo info, Failures failures, Object actual, Object subsequence) {292 if (commonChecks(info, actual, subsequence)) return;293 int sizeOfActual = sizeOf(actual);294 int sizeOfSubsequence = sizeOf(subsequence);295 // look for given subsequence, stop check when there is not enough elements remaining in actual to contain296 // subsequence297 int lastIndexWhereEndOfSubsequeceCanBeFound = sizeOfActual - sizeOfSubsequence;298 int actualIndex = 0;299 int subsequenceIndex = 0;300 while (actualIndex <= lastIndexWhereEndOfSubsequeceCanBeFound && subsequenceIndex < sizeOfSubsequence) {301 if (areEqual(Array.get(actual, actualIndex), Array.get(subsequence, subsequenceIndex))) {302 subsequenceIndex++;303 lastIndexWhereEndOfSubsequeceCanBeFound++;304 }305 actualIndex++;306 }307 if (subsequenceIndex < sizeOfSubsequence)308 throw failures.failure(info, shouldContainSubsequence(actual, subsequence, comparisonStrategy));309 }310 /**311 * Delegates to {@link ComparisonStrategy#areEqual(Object, Object)}312 */313 private boolean areEqual(Object actual, Object other) {314 return comparisonStrategy.areEqual(actual, other);315 }316 void assertDoesNotContain(AssertionInfo info, Failures failures, Object array, Object values) {317 checkIsNotNullAndNotEmpty(values);318 assertNotNull(info, array);319 Set<Object> found = new LinkedHashSet<>();320 int valuesSize = sizeOf(values);321 for (int i = 0; i < valuesSize; i++) {322 Object value = Array.get(values, i);323 if (arrayContains(array, value)) found.add(value);324 }325 if (!found.isEmpty()) throw failures.failure(info, shouldNotContain(array, values, found, comparisonStrategy));326 }327 /**328 * Delegates to {@link ComparisonStrategy#arrayContains(Object, Object)}329 */330 private boolean arrayContains(Object array, Object value) {331 return comparisonStrategy.arrayContains(array, value);332 }333 void assertDoesNotHaveDuplicates(AssertionInfo info, Failures failures, Object array) {334 assertNotNull(info, array);335 ArrayWrapperList wrapped = wrap(array);336 Iterable<?> duplicates = comparisonStrategy.duplicatesFrom(wrapped);337 if (!isNullOrEmpty(duplicates))338 throw failures.failure(info, shouldNotHaveDuplicates(array, duplicates, comparisonStrategy));339 }340 void assertStartsWith(AssertionInfo info, Failures failures, Object actual, Object sequence) {341 if (commonChecks(info, actual, sequence))342 return;343 int sequenceSize = sizeOf(sequence);344 int arraySize = sizeOf(actual);345 if (arraySize < sequenceSize) throw arrayDoesNotStartWithSequence(info, failures, actual, sequence);346 for (int i = 0; i < sequenceSize; i++) {347 if (!areEqual(Array.get(sequence, i), Array.get(actual, i)))348 throw arrayDoesNotStartWithSequence(info, failures, actual, sequence);349 }350 }351 private static boolean commonChecks(AssertionInfo info, Object actual, Object sequence) {352 checkIsNotNull(sequence);353 assertNotNull(info, actual);354 // if both actual and values are empty arrays, then assertion passes.355 if (isArrayEmpty(actual) && isArrayEmpty(sequence)) return true;356 failIfEmptySinceActualIsNotEmpty(sequence);357 return false;358 }359 private AssertionError arrayDoesNotStartWithSequence(AssertionInfo info, Failures failures, Object array,360 Object sequence) {361 return failures.failure(info, shouldStartWith(array, sequence, comparisonStrategy));362 }363 void assertEndsWith(AssertionInfo info, Failures failures, Object actual, Object sequence) {364 if (commonChecks(info, actual, sequence)) return;365 int sequenceSize = sizeOf(sequence);366 int arraySize = sizeOf(actual);367 if (arraySize < sequenceSize) throw arrayDoesNotEndWithSequence(info, failures, actual, sequence);368 for (int i = 0; i < sequenceSize; i++) {369 int sequenceIndex = sequenceSize - (i + 1);370 int arrayIndex = arraySize - (i + 1);371 if (!areEqual(Array.get(sequence, sequenceIndex), Array.get(actual, arrayIndex)))372 throw arrayDoesNotEndWithSequence(info, failures, actual, sequence);373 }374 }375 public void assertIsSubsetOf(AssertionInfo info, Failures failures, Object actual, Iterable<?> values) {376 assertNotNull(info, actual);377 checkIterableIsNotNull(info, values);378 List<Object> extra = newArrayList();379 int sizeOfActual = sizeOf(actual);380 for (int i = 0; i < sizeOfActual; i++) {381 Object actualElement = Array.get(actual, i);382 if (!iterableContains(values, actualElement)) {383 extra.add(actualElement);384 }385 }386 if (extra.size() > 0) {387 throw failures.failure(info, shouldBeSubsetOf(actual, values, extra, comparisonStrategy));388 }389 }390 void assertContainsNull(AssertionInfo info, Failures failures, Object array) {391 assertNotNull(info, array);392 if (!arrayContains(array, null)) throw failures.failure(info, shouldContainNull(array));393 }394 void assertDoesNotContainNull(AssertionInfo info, Failures failures, Object array) {395 assertNotNull(info, array);396 if (arrayContains(array, null)) throw failures.failure(info, shouldNotContainNull(array));397 }398 public <E> void assertAre(AssertionInfo info, Failures failures, Conditions conditions, Object array,399 Condition<E> condition) {400 List<E> notMatchingCondition = getElementsNotMatchingCondition(info, failures, conditions, array, condition);401 if (!notMatchingCondition.isEmpty())402 throw failures.failure(info, elementsShouldBe(array, notMatchingCondition, condition));403 }404 public <E> void assertAreNot(AssertionInfo info, Failures failures, Conditions conditions, Object array,405 Condition<E> condition) {406 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);407 if (!matchingElements.isEmpty())408 throw failures.failure(info, elementsShouldNotBe(array, matchingElements, condition));409 }410 public <E> void assertHave(AssertionInfo info, Failures failures, Conditions conditions, Object array,411 Condition<E> condition) {412 List<E> notMatchingCondition = getElementsNotMatchingCondition(info, failures, conditions, array, condition);413 if (!notMatchingCondition.isEmpty())414 throw failures.failure(info, elementsShouldHave(array, notMatchingCondition, condition));415 }416 public <E> void assertHaveNot(AssertionInfo info, Failures failures, Conditions conditions, Object array,417 Condition<E> condition) {418 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);419 if (!matchingElements.isEmpty())420 throw failures.failure(info, elementsShouldNotHave(array, matchingElements, condition));421 }422 public <E> void assertAreAtLeast(AssertionInfo info, Failures failures, Conditions conditions, Object array,423 int times, Condition<E> condition) {424 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);425 if (matchingElements.size() < times)426 throw failures.failure(info, elementsShouldBeAtLeast(array, times, condition));427 }428 public <E> void assertAreAtMost(AssertionInfo info, Failures failures, Conditions conditions, Object array,429 int times, Condition<E> condition) {430 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);431 if (matchingElements.size() > times) throw failures.failure(info, elementsShouldBeAtMost(array, times, condition));432 }433 public <E> void assertAreExactly(AssertionInfo info, Failures failures, Conditions conditions, Object array,434 int times, Condition<E> condition) {435 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);436 if (matchingElements.size() != times)437 throw failures.failure(info, elementsShouldBeExactly(array, times, condition));438 }439 public <E> void assertHaveAtLeast(AssertionInfo info, Failures failures, Conditions conditions, Object array,440 int times, Condition<E> condition) {441 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);442 if (matchingElements.size() < times)443 throw failures.failure(info, elementsShouldHaveAtLeast(array, times, condition));444 }445 public <E> void assertHaveAtMost(AssertionInfo info, Failures failures, Conditions conditions, Object array,446 int times, Condition<E> condition) {447 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);448 if (matchingElements.size() > times)449 throw failures.failure(info, elementsShouldHaveAtMost(array, times, condition));450 }451 public <E> void assertHaveExactly(AssertionInfo info, Failures failures, Conditions conditions, Object array,452 int times, Condition<E> condition) {453 List<E> matchingElements = getElementsMatchingCondition(info, failures, conditions, array, condition);454 if (matchingElements.size() != times)455 throw failures.failure(info, elementsShouldHaveExactly(array, times, condition));456 }457 private <E> List<E> getElementsMatchingCondition(AssertionInfo info, Failures failures, Conditions conditions,458 Object array, Condition<E> condition) {459 return filterElements(info, failures, conditions, array, condition, false);460 }461 private <E> List<E> getElementsNotMatchingCondition(AssertionInfo info, Failures failures, Conditions conditions,462 Object array, Condition<E> condition) {463 return filterElements(info, failures, conditions, array, condition, true);464 }465 @SuppressWarnings("unchecked")466 private <E> List<E> filterElements(AssertionInfo info, Failures failures, Conditions conditions, Object array,467 Condition<E> condition, boolean negateCondition) throws AssertionError {468 assertNotNull(info, array);469 conditions.assertIsNotNull(condition);470 try {471 List<E> filteredElements = new LinkedList<>();472 int arraySize = sizeOf(array);473 for (int i = 0; i < arraySize; i++) {474 E element = (E) Array.get(array, i);475 if (negateCondition ? !condition.matches(element) : condition.matches(element)) filteredElements.add(element);476 }477 return filteredElements;478 } catch (ClassCastException e) {479 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(array, condition));480 }481 }482 void assertIsSorted(AssertionInfo info, Failures failures, Object array) {483 assertNotNull(info, array);484 if (comparisonStrategy instanceof ComparatorBasedComparisonStrategy) {485 // instead of comparing array elements with their natural comparator, use the one set by client.486 Comparator<?> comparator = ((ComparatorBasedComparisonStrategy) comparisonStrategy).getComparator();487 assertIsSortedAccordingToComparator(info, failures, array, comparator);488 return;489 }490 // empty arrays are considered sorted even if component type is not sortable.491 if (sizeOf(array) == 0) return;492 assertThatArrayComponentTypeIsSortable(info, failures, array);493 try {494 // sorted assertion is only relevant if array elements are Comparable495 // => we should be able to build a Comparable array496 Comparable<Object>[] comparableArray = arrayOfComparableItems(array);497 // array with 0 or 1 element are considered sorted.498 if (comparableArray.length <= 1) return;499 for (int i = 0; i < comparableArray.length - 1; i++) {500 // array is sorted in ascending order iif element i is less or equal than element i+1501 if (comparableArray[i].compareTo(comparableArray[i + 1]) > 0)502 throw failures.failure(info, shouldBeSorted(i, array));503 }504 } catch (ClassCastException e) {505 // elements are either not Comparable or not mutually Comparable (e.g. array with String and Integer)506 throw failures.failure(info, shouldHaveMutuallyComparableElements(array));507 }508 }509 // is static to avoid "generify" Arrays510 static <T> void assertIsSortedAccordingToComparator(AssertionInfo info, Failures failures, Object array,511 Comparator<T> comparator) {512 assertNotNull(info, array);513 checkNotNull(comparator, "The given comparator should not be null");514 try {515 List<T> arrayAsList = asList(array);516 // empty arrays are considered sorted even if comparator can't be applied to <T>.517 if (arrayAsList.size() == 0) return;518 if (arrayAsList.size() == 1) {519 // call compare to see if unique element is compatible with comparator.520 comparator.compare(arrayAsList.get(0), arrayAsList.get(0));521 return;522 }523 for (int i = 0; i < arrayAsList.size() - 1; i++) {524 // array is sorted in comparator defined order iif element i is less or equal than element i+1525 if (comparator.compare(arrayAsList.get(i), arrayAsList.get(i + 1)) > 0)526 throw failures.failure(info, shouldBeSortedAccordingToGivenComparator(i, array, comparator));527 }528 } catch (ClassCastException e) {529 throw failures.failure(info, shouldHaveComparableElementsAccordingToGivenComparator(array, comparator));530 }531 }532 @SuppressWarnings("unchecked")533 private static <T> List<T> asList(Object array) {534 if (array == null) return null;535 if (!isArray(array)) throw new IllegalArgumentException("The object should be an array");536 int length = getLength(array);537 List<T> list = new ArrayList<>(length);538 for (int i = 0; i < length; i++) {539 list.add((T) Array.get(array, i));540 }541 return list;542 }543 @SuppressWarnings("unchecked")544 private static Comparable<Object>[] arrayOfComparableItems(Object array) {545 ArrayWrapperList arrayWrapperList = wrap(array);546 Comparable<Object>[] arrayOfComparableItems = new Comparable[arrayWrapperList.size()];547 for (int i = 0; i < arrayWrapperList.size(); i++) {548 arrayOfComparableItems[i] = (Comparable<Object>) arrayWrapperList.get(i);549 }550 return arrayOfComparableItems;551 }552 private static void assertThatArrayComponentTypeIsSortable(AssertionInfo info, Failures failures, Object array) {553 ArrayWrapperList arrayAsList = wrap(array);554 Class<?> arrayComponentType = arrayAsList.getComponentType();555 if (arrayComponentType.isPrimitive()) return;556 if (!Comparable.class.isAssignableFrom(arrayComponentType))557 throw failures.failure(info, shouldHaveMutuallyComparableElements(array));558 }559 // TODO manage empty values + empty actual560 private static void checkIsNotNullAndNotEmpty(Object values) {561 checkIsNotNull(values);562 if (isArrayEmpty(values)) throw arrayOfValuesToLookForIsEmpty();563 }564 private static void checkIsNotNull(Object values) {565 if (values == null) throw arrayOfValuesToLookForIsNull();566 }567 private static boolean isArrayEmpty(Object array) {568 return sizeOf(array) == 0;569 }570 private AssertionError arrayDoesNotEndWithSequence(AssertionInfo info, Failures failures, Object array,571 Object sequence) {572 return failures.failure(info, shouldEndWith(array, sequence, comparisonStrategy));573 }574 private static void assertNotNull(AssertionInfo info, Object array) {575 Objects.instance().assertNotNull(info, array);576 }577 private static int sizeOf(Object array) {578 if (array instanceof Object[]) return ((Object[]) array).length;579 return Array.getLength(array);580 }581 private static void failIfEmptySinceActualIsNotEmpty(Object values) {582 if (isArrayEmpty(values)) throw new AssertionError("actual is not empty while group of values to look for is.");583 }584}...
Source:ShouldContainSubsequence.java
...11 * Copyright 2012-2022 the original author or authors.12 */13package org.assertj.core.error;14import static org.assertj.core.util.Arrays.isArray;15import static org.assertj.core.util.Arrays.sizeOf;16import java.lang.reflect.Array;17import org.assertj.core.internal.ComparisonStrategy;18import org.assertj.core.internal.StandardComparisonStrategy;19import org.assertj.core.util.Arrays;20import org.assertj.core.util.IterableUtil;21/**22 * Creates an error message indicating that an assertion that verifies that a group of elements contains a subsequence23 * of values failed. A group of elements can be a collection, an array or a {@code String}.24 * 25 * @author Marcin Mikosik26 */27public class ShouldContainSubsequence extends BasicErrorMessageFactory {28 public static ShouldContainSubsequence actualDoesNotHaveEnoughElementsToContainSubsequence(Object actual, Object subsequence) {29 return new ShouldContainSubsequence(actual, subsequence);30 }31 private ShouldContainSubsequence(Object actual, Object subsequence) {32 super("%nExpecting actual to contain the specified subsequence but actual does not have enough elements to contain it, actual size is %s when subsequence size is %s%nactual:%n %s%nsubsequence:%n %s",33 sizeOfArrayOrIterable(actual), sizeOf(subsequence), actual, subsequence);34 }35 public static ShouldContainSubsequence actualDoesNotHaveEnoughElementsLeftToContainSubsequence(Object actual,36 Object subsequence,37 int actualIndex,38 int subsequenceIndex) {39 return new ShouldContainSubsequence(actual, subsequence, actualIndex, subsequenceIndex);40 }41 private ShouldContainSubsequence(Object actual, Object subsequence, int actualIndex, int subsequenceIndex) {42 super("%nExpecting actual to contain the specified subsequence but actual does not have enough elements left to compare after reaching element %s out of %s with %s subsequence element(s) still to find."43 + "%nactual:%n %s%nsubsequence:%n %s",44 actualIndex + 1, sizeOfArrayOrIterable(actual), sizeOf(subsequence) - subsequenceIndex, actual, subsequence);45 }46 private static Object sizeOfArrayOrIterable(Object actual) {47 return isArray(actual) ? Arrays.sizeOf(actual) : IterableUtil.sizeOf((Iterable<?>) actual);48 }49 /**50 * Creates a new <code>{@link ShouldContainSubsequence}</code>.51 * 52 * @param actual the actual value in the failed assertion.53 * @param subsequence the subsequence of values expected to be in {@code actual}.54 * @param subsequenceIndex the index of the first token in {@code subsequence} that was not found in {@code actual}.55 * @param comparisonStrategy the {@link ComparisonStrategy} used to evaluate assertion.56 * @return the created {@code ErrorMessageFactory}.57 */58 public static ShouldContainSubsequence shouldContainSubsequence(Object actual, Object subsequence, int subsequenceIndex,59 ComparisonStrategy comparisonStrategy) {60 return new ShouldContainSubsequence(actual, subsequence, subsequenceIndex, comparisonStrategy);61 }...
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class 1 {3 public static void main(String[] args) {4 int[] array = { 1, 2, 3, 4, 5 };5 int size = Arrays.sizeOf(array);6 System.out.println("Size of array is: " + size);7 }8}9Recommended Posts: Java | Arrays.copyOf() method10Java | Arrays.equals() method11Java | Arrays.sort() method12Java | Arrays.fill() method13Java | Arrays.toString() method14Java | Arrays.binarySearch() method15Java | Arrays.copyOfRange() method16Java | Arrays.deepEquals() method17Java | Arrays.deepToString() method18Java | Arrays.deepHashCode() method19Java | Arrays.asList() method20Java | Arrays.hashCode() method21Java | Arrays.parallelPrefix() method22Java | Arrays.parallelSetAll() method23Java | Arrays.parallelSort() method24Java | Arrays.spliterator() method25Java | Arrays.stream() method26Java | Arrays.setAll() method27Java | Arrays.parallelCopyOf() method28Java | Arrays.copyOf() method29Java | Arrays.equals() method30Java | Arrays.sort() method31Java | Arrays.fill() method32Java | Arrays.toString() method33Java | Arrays.binarySearch() method34Java | Arrays.copyOfRange() method35Java | Arrays.deepEquals() method36Java | Arrays.deepToString() method37Java | Arrays.deepHashCode() method38Java | Arrays.asList() method39Java | Arrays.hashCode() method40Java | Arrays.parallelPrefix() method41Java | Arrays.parallelSetAll() method42Java | Arrays.parallelSort() method43Java | Arrays.spliterator() method44Java | Arrays.stream() method45Java | Arrays.setAll() method46Java | Arrays.parallelCopyOf() method47Java | Arrays.copyOf() method48Java | Arrays.equals() method49Java | Arrays.sort() method50Java | Arrays.fill() method51Java | Arrays.toString() method52Java | Arrays.binarySearch() method53Java | Arrays.copyOfRange() method54Java | Arrays.deepEquals() method55Java | Arrays.deepToString() method56Java | Arrays.deepHashCode() method57Java | Arrays.asList() method58Java | Arrays.hashCode() method59Java | Arrays.parallelPrefix() method60Java | Arrays.parallelSetAll() method61Java | Arrays.parallelSort() method
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class Main {3 public static void main(String[] args) {4 int[] arr = {1, 2, 3, 4, 5};5 int size = Arrays.sizeOf(arr);6 System.out.println(size);7 }8}
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class 1 {3 public static void main(String[] args) {4 String[] array = new String[] { "one", "two", "three" };5 int size = Arrays.sizeOf(array);6 System.out.println("Size of array: " + size);7 }8}
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class MainClass {3 public static void main(String[] args) {4 String[] array = { "a", "b", "c" };5 System.out.println(Arrays.sizeOf(array));6 }7}
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class 1 {3public static void main(String[] args) {4int[] arr = new int[10];5System.out.println("Size of array is: " + Arrays.sizeOf(arr));6}7}
sizeOf
Using AI Code Generation
1package com.example;2import org.assertj.core.util.Arrays;3public class Example {4 public static void main(String[] args) {5 int arr[] = {1, 2, 3, 4, 5};6 System.out.println(Arrays.sizeOf(arr));7 }8}9Recommended Posts: Java | Arrays.sort(Object[] a) method10Java | Arrays.sort(Object[] a, Comparator c) method11Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method12Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method13Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method14Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method15Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method16Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method17Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method18Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method19Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method20Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method21Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method22Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method23Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method24Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method25Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method26Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method27Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method28Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method29Java | Arrays.sort(Object[] a, int fromIndex, int toIndex) method30Java | Arrays.sort(Object[] a, int fromIndex, int toIndex, Comparator c) method31Java | Arrays.sort(Object[] a, int fromIndex, int
sizeOf
Using AI Code Generation
1import static org.assertj.core.api.Assertions.assertThat;2import org.assertj.core.util.Arrays;3public class SizeOfMethod {4 public static void main(String[] args) {5 int[] arr = { 1, 2, 3, 4 };6 int size = Arrays.sizeOf(arr);7 System.out.println("Size of the array: " + size);8 }9}10Recommended Posts: Java | Arrays.stream() method11Java | Arrays.equals() method12Java | Arrays.compare() method13Java | Arrays.compareUnsigned() method14Java | Arrays.compareLong() method15Java | Arrays.compareLongUnsigned() method16Java | Arrays.compareShort() method17Java | Arrays.compareShortUnsigned() method18Java | Arrays.compareChar() method19Java | Arrays.compareInt() method20Java | Arrays.compareIntUnsigned() method21Java | Arrays.compare() method22Java | Arrays.compareUnsigned() method23Java | Arrays.compareUnsigned() method24Java | Arrays.compare() method
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class ArraysDemo {3public static void main(String[] args) {4int[] arr = new int[]{1, 2, 3, 4};5System.out.println(Arrays.sizeOf(arr));6}7}
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class 1 {3 public static void main(String[] args) {4 int[] array = {1, 2, 3, 4};5 int size = Arrays.sizeOf(array);6 System.out.println("Size of given array: " + size);7 }8}
sizeOf
Using AI Code Generation
1import org.assertj.core.util.Arrays;2public class ArraysSizeOf {3 public static void main(String[] args) {4 String[] str = new String[] {"a", "b", "c", "d", "e", "f", "g"};5 System.out.println("Size of array is: " + Arrays.sizeOf(str));6 }7}8Recommended Posts: Java | Arrays.equals() method9Java | Arrays.copyOf() method10Java | Arrays.copyOfRange() method11Java | Arrays.fill() method12Java | Arrays.binarySearch() method13Java | Arrays.toString() method14Java | Arrays.deepToString() method15Java | Arrays.asList() method16Java | Arrays.deepEquals() method17Java | Arrays.sort() method18Java | Arrays.deepHashCode() method
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!!