Best Assertj code snippet using org.assertj.core.api.AbstractObjectArrayAssert.newListAssertInstance
Source:AbstractObjectArrayAssert.java
...1790 public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> extracting(String fieldOrProperty) {1791 Object[] values = FieldsOrPropertiesExtractor.extract(actual, byName(fieldOrProperty));1792 String extractedDescription = extractedDescriptionOf(fieldOrProperty);1793 String description = mostRelevantDescription(info.description(), extractedDescription);1794 return newListAssertInstance(newArrayList(values)).as(description);1795 }1796 /**1797 * Extract the values of given field or property from the array's elements under test into a new list, this new list of the provided type1798 * becoming the object under test.1799 * <p>1800 * It allows you to test a field/property of the array's elements instead of testing the elements themselves, which can1801 * be much less work !1802 * <p>1803 * Let's take an example to make things clearer :1804 * <pre><code class='java'> // Build an array of TolkienCharacter, a TolkienCharacter has a name (String) and a Race (a class)1805 * // they can be public field or properties, both works when extracting their values.1806 * TolkienCharacter[] fellowshipOfTheRing = new TolkienCharacter[] {1807 * new TolkienCharacter("Frodo", 33, HOBBIT),1808 * new TolkienCharacter("Sam", 38, HOBBIT),1809 * new TolkienCharacter("Gandalf", 2020, MAIA),1810 * new TolkienCharacter("Legolas", 1000, ELF),1811 * new TolkienCharacter("Pippin", 28, HOBBIT),1812 * new TolkienCharacter("Gimli", 139, DWARF),1813 * new TolkienCharacter("Aragorn", 87, MAN,1814 * new TolkienCharacter("Boromir", 37, MAN)1815 * };1816 *1817 * // let's verify the names of TolkienCharacter in fellowshipOfTheRing :1818 *1819 * assertThat(fellowshipOfTheRing).extracting("name", String.class)1820 * .contains("Boromir", "Gandalf", "Frodo")1821 * .doesNotContain("Sauron", "Elrond");1822 *1823 * // you can also extract nested field/property like the name of Race :1824 *1825 * assertThat(fellowshipOfTheRing).extracting("race.name", String.class)1826 * .contains("Hobbit", "Elf")1827 * .doesNotContain("Orc");</code></pre>1828 *1829 * A property with the given name is looked for first, if it does not exist then a field with the given name1830 * is looked for.1831 * <p>1832 * Note that the order of extracted field/property values is consistent with the order of the array under test.1833 *1834 * @param <P> the type of elements to extract.1835 * @param fieldOrProperty the field/property to extract from the array under test1836 * @param extractingType type to return1837 * @return a new assertion object whose object under test is the list of extracted field/property values.1838 * @throws IntrospectionError if no field or property exists with the given name1839 */1840 @CheckReturnValue1841 public <P> AbstractListAssert<?, List<? extends P>, P, ObjectAssert<P>> extracting(String fieldOrProperty,1842 Class<P> extractingType) {1843 @SuppressWarnings("unchecked")1844 List<P> values = (List<P>) FieldsOrPropertiesExtractor.extract(Arrays.asList(actual), byName(fieldOrProperty));1845 String extractedDescription = extractedDescriptionOf(fieldOrProperty);1846 String description = mostRelevantDescription(info.description(), extractedDescription);1847 return newListAssertInstance(values).as(description);1848 }1849 /**1850 * Extract the values of given fields/properties from the array's elements under test into a list composed of1851 * Tuple (a simple data structure), this new list becoming the object under test.1852 * <p>1853 * It allows you to test fields/properties of the the array's elements instead of testing the elements themselves, it1854 * can be sometimes much less work !1855 * <p>1856 * The Tuple data corresponds to the extracted values of the given fields/properties, for instance if you ask to1857 * extract "id", "name" and "email" then each Tuple data will be composed of id, name and email extracted from the1858 * element of the initial array (the Tuple's data order is the same as the given fields/properties order).1859 * <p>1860 * Let's take an example to make things clearer :1861 * <pre><code class='java'> // Build an array of TolkienCharacter, a TolkienCharacter has a name (String) and a Race (a class)1862 * // they can be public field or properties, both works when extracting their values.1863 * TolkienCharacter[] fellowshipOfTheRing = new TolkienCharacter[] {1864 * new TolkienCharacter("Frodo", 33, HOBBIT),1865 * new TolkienCharacter("Sam", 38, HOBBIT),1866 * new TolkienCharacter("Gandalf", 2020, MAIA),1867 * new TolkienCharacter("Legolas", 1000, ELF),1868 * new TolkienCharacter("Pippin", 28, HOBBIT),1869 * new TolkienCharacter("Gimli", 139, DWARF),1870 * new TolkienCharacter("Aragorn", 87, MAN,1871 * new TolkienCharacter("Boromir", 37, MAN)1872 * };1873 *1874 * // let's verify 'name' and 'age' of some TolkienCharacter in fellowshipOfTheRing :1875 *1876 * assertThat(fellowshipOfTheRing).extracting("name", "age")1877 * .contains(tuple("Boromir", 37),1878 * tuple("Sam", 38),1879 * tuple("Legolas", 1000));1880 *1881 *1882 * // extract 'name', 'age' and Race name values.1883 *1884 * assertThat(fellowshipOfTheRing).extracting("name", "age", "race.name")1885 * .contains(tuple("Boromir", 37, "Man"),1886 * tuple("Sam", 38, "Hobbit"),1887 * tuple("Legolas", 1000, "Elf"));</code></pre>1888 *1889 * A property with the given name is looked for first, if it does not exist the a field with the given name is1890 * looked for.1891 * <p>1892 * Note that the order of extracted property/field values is consistent with the iteration order of the array under1893 * test.1894 *1895 * @param propertiesOrFields the properties/fields to extract from the initial array under test1896 * @return a new assertion object whose object under test is the list of Tuple with extracted properties/fields values as data.1897 * @throws IntrospectionError if one of the given name does not match a field or property in one of the initial Iterable's element.1898 */1899 @CheckReturnValue1900 public AbstractListAssert<?, List<? extends Tuple>, Tuple, ObjectAssert<Tuple>> extracting(String... propertiesOrFields) {1901 List<Tuple> values = FieldsOrPropertiesExtractor.extract(Arrays.asList(actual), byName(propertiesOrFields));1902 String extractedDescription = extractedDescriptionOf(propertiesOrFields);1903 String description = mostRelevantDescription(info.description(), extractedDescription);1904 return newListAssertInstance(values).as(description);1905 }1906 /**1907 * Extract the values from the array's elements by applying an extracting function on them, the resulting list becomes 1908 * the new object under test.1909 * <p>1910 * This method is similar to {@link #extracting(String)} but more refactoring friendly as it does not use introspection.1911 * <p>1912 * Let's take a look an example:1913 * <pre><code class='java'> // Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class)1914 * // they can be public field or properties, both can be extracted.1915 * TolkienCharacter[] fellowshipOfTheRing = new TolkienCharacter[] {1916 * new TolkienCharacter("Frodo", 33, HOBBIT),1917 * new TolkienCharacter("Sam", 38, HOBBIT),1918 * new TolkienCharacter("Gandalf", 2020, MAIA),1919 * new TolkienCharacter("Legolas", 1000, ELF),1920 * new TolkienCharacter("Pippin", 28, HOBBIT),1921 * new TolkienCharacter("Gimli", 139, DWARF),1922 * new TolkienCharacter("Aragorn", 87, MAN,1923 * new TolkienCharacter("Boromir", 37, MAN)1924 * };1925 *1926 * // fellowship has hobbitses, right, my presioussss?1927 * assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getRace).contains(HOBBIT);</code></pre>1928 *1929 * Note that the order of extracted property/field values is consistent with the iteration order of the Iterable under1930 * test, for example if it's a {@link HashSet}, you won't be able to make any assumptions on the extracted values1931 * order.1932 *1933 * @param <U> the type of elements to extract.1934 * @param extractor the object transforming input object to desired one1935 * @return a new assertion object whose object under test is the list of extracted values. 1936 */1937 @CheckReturnValue1938 public <U> AbstractListAssert<?, List<? extends U>, U, ObjectAssert<U>> extracting(Extractor<? super ELEMENT, U> extractor) {1939 List<U> values = FieldsOrPropertiesExtractor.extract(Arrays.asList(actual), extractor);1940 return newListAssertInstance(values);1941 }1942 /**1943 * Extract the values from the array's elements by applying an extracting function (which might throw an exception)1944 * on them, the resulting list of extracted values becomes a new object under test.1945 * <p>1946 * Any checked exception raised in the extractor is rethrown wrapped in a {@link RuntimeException}.1947 * <p>1948 * It allows to test values from the elements in safer way than by using {@link #extracting(String)}, as it1949 * doesn't use introspection.1950 * <p>1951 * Let's take a look an example:1952 * <pre><code class='java'> // Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class)1953 * // they can be public field or properties, both can be extracted.1954 * TolkienCharacter[] fellowshipOfTheRing = new TolkienCharacter[] {1955 * new TolkienCharacter("Frodo", 33, HOBBIT),1956 * new TolkienCharacter("Sam", 38, HOBBIT),1957 * new TolkienCharacter("Gandalf", 2020, MAIA),1958 * new TolkienCharacter("Legolas", 1000, ELF),1959 * new TolkienCharacter("Pippin", 28, HOBBIT),1960 * new TolkienCharacter("Gimli", 139, DWARF),1961 * new TolkienCharacter("Aragorn", 87, MAN,1962 * new TolkienCharacter("Boromir", 37, MAN)1963 * };1964 *1965 * assertThat(fellowshipOfTheRing).extracting(input -> {1966 * if (input.getAge() < 20) {1967 * throw new Exception("age < 20");1968 * }1969 * return input.getName();1970 * }).contains("Frodo");</code></pre>1971 * <p>1972 * Note that the order of extracted property/field values is consistent with the iteration order of the array under test.1973 *1974 * @param <V> the type of elements to extract.1975 * @param <EXCEPTION> the exception type of {@link ThrowingExtractor}1976 * @param extractor the object transforming input object to desired one1977 * @return a new assertion object whose object under test is the list of extracted values 1978 * @since 3.7.01979 */1980 @CheckReturnValue1981 public <V, EXCEPTION extends Exception> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> extracting(ThrowingExtractor<? super ELEMENT, V, EXCEPTION> extractor) {1982 List<V> values = FieldsOrPropertiesExtractor.extract(newArrayList(actual), extractor);1983 return newListAssertInstance(values);1984 }1985 /**1986 * Use the given {@link Function}s to extract the values from the array's elements into a new list1987 * composed of {@link Tuple}s (a simple data structure containing the extracted values), this new list becoming the1988 * object under test.1989 * <p>1990 * It allows you to test values from the array's elements instead of testing the elements themselves, which sometimes can be1991 * much less work!1992 * <p>1993 * The {@link Tuple} data corresponds to the extracted values from the arrays's elements, for instance if you pass functions1994 * extracting "id", "name" and "email" values then each {@link Tuple}'s data will be composed of an id, a name and an email1995 * extracted from the element of the initial array (the Tuple's data order is the same as the given functions order).1996 * <p>1997 * Let's take a look at an example to make things clearer :1998 * <pre><code class='java'> // Build an array of TolkienCharacter, a TolkienCharacter has a name (String) and a Race (a class)1999 * // they can be public field or properties, both works when extracting their values.2000 * TolkienCharacter[] fellowshipOfTheRing = new TolkienCharacter[] {2001 * new TolkienCharacter("Frodo", 33, HOBBIT),2002 * new TolkienCharacter("Sam", 38, HOBBIT),2003 * new TolkienCharacter("Gandalf", 2020, MAIA),2004 * new TolkienCharacter("Legolas", 1000, ELF),2005 * new TolkienCharacter("Pippin", 28, HOBBIT),2006 * new TolkienCharacter("Gimli", 139, DWARF),2007 * new TolkienCharacter("Aragorn", 87, MAN,2008 * new TolkienCharacter("Boromir", 37, MAN)2009 * };2010 *2011 * // let's verify 'name', 'age' and Race of some TolkienCharacter in fellowshipOfTheRing :2012 * assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName,2013 * character -> character.getAge(),2014 * TolkienCharacter::getRace)2015 * .containsOnly(tuple("Frodo", 33, HOBBIT),2016 * tuple("Sam", 38, HOBBIT),2017 * tuple("Gandalf", 2020, MAIA),2018 * tuple("Legolas", 1000, ELF),2019 * tuple("Pippin", 28, HOBBIT),2020 * tuple("Gimli", 139, DWARF),2021 * tuple("Aragorn", 87, MAN),2022 * tuple("Boromir", 37, MAN));</code></pre>2023 * You can use lambda expression or a method reference to extract the expected values.2024 * <p>2025 * Use {@link Tuple#tuple(Object...)} to initialize the expected values.2026 * <p>2027 * Note that the order of the extracted tuples list is consistent with the iteration order of the array under test,2028 * for example if it's a {@link HashSet}, you won't be able to make any assumptions on the extracted tuples order.2029 *2030 * @param extractors the extractor functions to extract a value from an element of the array under test.2031 * @return a new assertion object whose object under test is the list of Tuples containing the extracted values.2032 */2033 @CheckReturnValue2034 public AbstractListAssert<?, List<? extends Tuple>, Tuple, ObjectAssert<Tuple>> extracting(@SuppressWarnings("unchecked") Function<ELEMENT, ?>... extractors) {2035 Function<ELEMENT, Tuple> tupleExtractor = objectToExtractValueFrom -> new Tuple(Stream.of(extractors)2036 .map(extractor -> extractor.apply(objectToExtractValueFrom))2037 .toArray());2038 List<Tuple> tuples = stream(actual).map(tupleExtractor).collect(toList());2039 return newListAssertInstance(tuples).as(info.description());2040 }2041 /**2042 * Extract the Iterable values from arrays elements under test by applying an Iterable extracting function on them2043 * and concatenating the result lists into an array which becomes the new object under test.2044 * <p>2045 * It allows testing the results of extracting values that are represented by Iterables.2046 * <p>2047 * For example:2048 * <pre><code class='java'> CartoonCharacter bart = new CartoonCharacter("Bart Simpson");2049 * CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson");2050 * CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson");2051 * CartoonCharacter homer = new CartoonCharacter("Homer Simpson");2052 * homer.addChildren(bart, lisa, maggie);2053 *2054 * CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone");2055 * CartoonCharacter fred = new CartoonCharacter("Fred Flintstone");2056 * fred.getChildren().add(pebbles);2057 *2058 * CartoonCharacter[] parents = new CartoonCharacter[] { homer, fred };2059 * // check children2060 * assertThat(parents).flatExtracting(CartoonCharacter::getChildren)2061 * .containsOnly(bart, lisa, maggie, pebbles);</code></pre>2062 *2063 * The order of extracted values is consisted with both the order of the collection itself, as well as the extracted2064 * collections.2065 *2066 * @param <V> the type of elements to extract.2067 * @param <C> the type of collection to flat/extract.2068 * @param extractor the object transforming input object to an Iterable of desired ones2069 * @return a new assertion object whose object under test is the list of values extracted2070 */2071 @CheckReturnValue2072 public <V, C extends Collection<V>> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> flatExtracting(Extractor<? super ELEMENT, C> extractor) {2073 return doFlatExtracting(extractor);2074 }2075 /**2076 * Extract the Iterable values from arrays elements under test by applying an Iterable extracting function (which2077 * might throw an exception) on them and concatenating the result lists into an array which becomes the new object2078 * under test.2079 * <p>2080 * It allows testing the results of extracting values that are represented by Iterables.2081 * <p>2082 * For example:2083 * <pre><code class='java'> CartoonCharacter bart = new CartoonCharacter("Bart Simpson");2084 * CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson");2085 * CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson");2086 * CartoonCharacter homer = new CartoonCharacter("Homer Simpson");2087 * homer.addChildren(bart, lisa, maggie);2088 *2089 * CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone");2090 * CartoonCharacter fred = new CartoonCharacter("Fred Flintstone");2091 * fred.getChildren().add(pebbles);2092 *2093 * CartoonCharacter[] parents = new CartoonCharacter[] { homer, fred };2094 * // check children2095 * assertThat(parents).flatExtracting(input -> {2096 * if (input.getChildren().size() == 0) {2097 * throw new Exception("no children");2098 * }2099 * return input.getChildren();2100 * }).containsOnly(bart, lisa, maggie, pebbles);</code></pre>2101 *2102 * The order of extracted values is consisted with both the order of the collection itself, as well as the extracted2103 * collections.2104 *2105 * @param <V> the type of elements to extract.2106 * @param <C> the type of collection to flat/extract.2107 * @param <EXCEPTION> the exception type of {@link ThrowingExtractor}2108 * @param extractor the object transforming input object to an Iterable of desired ones2109 * @return a new assertion object whose object under test is the list of values extracted2110 * @since 3.7.02111 */2112 @CheckReturnValue2113 public <V, C extends Collection<V>, EXCEPTION extends Exception> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> flatExtracting(ThrowingExtractor<? super ELEMENT, C, EXCEPTION> extractor) {2114 return doFlatExtracting(extractor);2115 }2116 private <V, C extends Collection<V>> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> doFlatExtracting(Extractor<? super ELEMENT, C> extractor) {2117 final List<C> extractedValues = FieldsOrPropertiesExtractor.extract(Arrays.asList(actual), extractor);2118 final List<V> result = newArrayList();2119 for (C e : extractedValues) {2120 result.addAll(e);2121 }2122 return newListAssertInstance(result);2123 }2124 /**2125 * Extract from array's elements the Iterable/Array values corresponding to the given property/field name and2126 * concatenate them into a single array becoming the new object under test.2127 * <p>2128 * It allows testing the elements of extracting values that are represented by iterables or arrays.2129 * <p>2130 * For example:2131 * <pre><code class='java'> CartoonCharacter bart = new CartoonCharacter("Bart Simpson");2132 * CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson");2133 * CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson");2134 * CartoonCharacter homer = new CartoonCharacter("Homer Simpson");2135 * homer.addChildren(bart, lisa, maggie);2136 *2137 * CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone");2138 * CartoonCharacter fred = new CartoonCharacter("Fred Flintstone");2139 * fred.getChildren().add(pebbles);2140 *2141 * CartoonCharacter[] parents = new CartoonCharacter[] { homer, fred };2142 * // check children2143 * assertThat(parents).flatExtracting("children")2144 * .containsOnly(bart, lisa, maggie, pebbles);</code></pre>2145 *2146 * The order of extracted values is consisted with both the order of the collection itself, as well as the extracted2147 * collections.2148 *2149 * @param propertyName the object transforming input object to an Iterable of desired ones2150 * @return a new assertion object whose object under test is the list of values extracted2151 * @throws IllegalArgumentException if one of the extracted property value was not an array or an iterable.2152 */2153 @CheckReturnValue2154 public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> flatExtracting(String propertyName) {2155 List<Object> extractedValues = newArrayList();2156 List<?> extractedGroups = FieldsOrPropertiesExtractor.extract(Arrays.asList(actual), byName(propertyName));2157 for (Object group : extractedGroups) {2158 // expecting group to be an iterable or an array2159 if (isArray(group)) {2160 int size = Array.getLength(group);2161 for (int i = 0; i < size; i++) {2162 extractedValues.add(Array.get(group, i));2163 }2164 } else if (group instanceof Iterable) {2165 Iterable<?> iterable = (Iterable<?>) group;2166 for (Object value : iterable) {2167 extractedValues.add(value);2168 }2169 } else {2170 CommonErrors.wrongElementTypeForFlatExtracting(group);2171 }2172 }2173 return newListAssertInstance(extractedValues);2174 }2175 /**2176 * Extract the result of given method invocation from the array's elements under test into a list, this list becoming 2177 * the object under test.2178 * <p>2179 * It allows you to test a method results of the array's elements instead of testing the elements themselves, which can be2180 * much less work!2181 * <p>2182 * It is especially useful for classes that does not conform to the Java Bean's getter specification (i.e. public String2183 * toString() or public String status() instead of public String getStatus()).2184 * <p>2185 * Let's take an example to make things clearer :2186 * <pre><code class='java'> // Build a array of WesterosHouse, a WesterosHouse has a method: public String sayTheWords()2187 * WesterosHouse[] greatHousesOfWesteros = new WesterosHouse[] { new WesterosHouse("Stark", "Winter is Coming"),2188 * new WesterosHouse("Lannister", "Hear Me Roar!"), new WesterosHouse("Greyjoy", "We Do Not Sow"),2189 * new WesterosHouse("Baratheon", "Our is the Fury"), new WesterosHouse("Martell", "Unbowed, Unbent, Unbroken"),2190 * new WesterosHouse("Tyrell", "Growing Strong") };2191 *2192 * // let's verify the words of the great houses of Westeros:2193 * assertThat(greatHousesOfWesteros).extractingResultOf("sayTheWords")2194 * .contains("Winter is Coming", "We Do Not Sow", "Hear Me Roar")2195 * .doesNotContain("Lannisters always pay their debts");</code></pre>2196 *2197 * <p>2198 * Following requirements have to be met to extract method results:2199 * <ul>2200 * <li>method has to be public,</li>2201 * <li>method cannot accept any arguments,</li>2202 * <li>method cannot return void.</li>2203 * </ul>2204 * <p>2205 * Note that the order of extracted values is consistent with the order of the array under test.2206 *2207 * @param method the name of the method which result is to be extracted from the array under test2208 * @return a new assertion object whose object under test is the list of extracted values.2209 * @throws IllegalArgumentException if no method exists with the given name, or method is not public, or method does2210 * return void, or method accepts arguments.2211 */2212 @CheckReturnValue2213 public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> extractingResultOf(String method) {2214 Object[] values = FieldsOrPropertiesExtractor.extract(actual, resultOf(method));2215 String extractedDescription = extractedDescriptionOfMethod(method);2216 String description = mostRelevantDescription(info.description(), extractedDescription);2217 return newListAssertInstance(newArrayList(values)).as(description);2218 }2219 /**2220 * Extract the result of given method invocation from the array's elements under test into a list, this list becoming 2221 * the object under test.2222 * <p>2223 * It allows you to test a method results of the array's elements instead of testing the elements themselves, which can be2224 * much less work!2225 * <p>2226 * It is especially useful for classes that do not conform to the Java Bean's getter specification (i.e. public String2227 * toString() or public String status() instead of public String getStatus()).2228 * <p>2229 * Let's take an example to make things clearer :2230 * <pre><code class='java'> // Build a array of WesterosHouse, a WesterosHouse has a method: public String sayTheWords()2231 * WesterosHouse[] greatHousesOfWesteros = new WesterosHouse[] { new WesterosHouse("Stark", "Winter is Coming"),2232 * new WesterosHouse("Lannister", "Hear Me Roar!"), new WesterosHouse("Greyjoy", "We Do Not Sow"),2233 * new WesterosHouse("Baratheon", "Our is the Fury"), new WesterosHouse("Martell", "Unbowed, Unbent, Unbroken"),2234 * new WesterosHouse("Tyrell", "Growing Strong") };2235 *2236 * // let's verify the words of the great houses of Westeros:2237 * assertThat(greatHousesOfWesteros).extractingResultOf("sayTheWords", String.class)2238 * .contains("Winter is Coming", "We Do Not Sow", "Hear Me Roar")2239 * .doesNotContain("Lannisters always pay their debts");</code></pre>2240 *2241 * <p>2242 * Following requirements have to be met to extract method results:2243 * <ul>2244 * <li>method has to be public,</li>2245 * <li>method can not accept any arguments,</li>2246 * <li>method can not return void.</li>2247 * </ul>2248 * <p>2249 * Note that the order of extracted values is consistent with the order of the array under test.2250 *2251 * @param <P> the type of elements extracted.2252 * @param method the name of the method which result is to be extracted from the array under test2253 * @param extractingType type to return2254 * @return a new assertion object whose object under test is the list of extracted values.2255 * @throws IllegalArgumentException if no method exists with the given name, or method is not public, or method does2256 * return void, or method accepts arguments.2257 */2258 @CheckReturnValue2259 public <P> AbstractListAssert<?, List<? extends P>, P, ObjectAssert<P>> extractingResultOf(String method,2260 Class<P> extractingType) {2261 @SuppressWarnings("unchecked")2262 P[] values = (P[]) FieldsOrPropertiesExtractor.extract(actual, resultOf(method));2263 String extractedDescription = extractedDescriptionOfMethod(method);2264 String description = mostRelevantDescription(info.description(), extractedDescription);2265 return newListAssertInstance(newArrayList(values)).as(description);2266 }2267 /**2268 * Enable hexadecimal object representation of Iterable elements instead of standard java representation in error2269 * messages.2270 * <p>2271 * It can be useful to better understand what the error was with a more meaningful error message.2272 * <p>2273 * Example2274 * <pre><code class='java'> assertThat(new Byte[] { 0x10, 0x20 }).inHexadecimal().contains(new Byte[] { 0x30 });</code></pre>2275 *2276 * With standard error message:2277 * <pre><code class='java'> Expecting:2278 * <[16, 32]>2279 * to contain:2280 * <[48]>2281 * but could not find:2282 * <[48]></code></pre>2283 *2284 * With Hexadecimal error message:2285 * <pre><code class='java'> Expecting:2286 * <[0x10, 0x20]>2287 * to contain:2288 * <[0x30]>2289 * but could not find:2290 * <[0x30]></code></pre>2291 *2292 * @return {@code this} assertion object.2293 */2294 @Override2295 @CheckReturnValue2296 public SELF inHexadecimal() {2297 return super.inHexadecimal();2298 }2299 @Override2300 @CheckReturnValue2301 public SELF inBinary() {2302 return super.inBinary();2303 }2304 /**2305 * Filter the array under test into a list composed of the elements elements having a property or field equal to 2306 * {@code expectedValue}, the property/field is specified by {@code propertyOrFieldName} parameter.2307 * <p>2308 * The filter first tries to get the value from a property (named {@code propertyOrFieldName}), if no such property2309 * exists it tries to read the value from a field. Reading private fields is supported by default, this can be2310 * globally disabled by calling {@link Assertions#setAllowExtractingPrivateFields(boolean)2311 * Assertions.setAllowExtractingPrivateFields(false)}.2312 * <p>2313 * When reading <b>nested</b> property/field, if an intermediate value is null the whole nested property/field is2314 * considered to be null, thus reading "address.street.name" value will return null if "street" value is null.2315 * <p>2316 *2317 * As an example, let's check all employees 800 years old (yes, special employees):2318 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2319 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2320 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2321 * Employee noname = new Employee(4L, null, 50);2322 *2323 * Employee[] employees = new Employee[] { yoda, luke, obiwan, noname };2324 *2325 * assertThat(employees).filteredOn("age", 800)2326 * .containsOnly(yoda, obiwan);</code></pre>2327 *2328 * Nested properties/fields are supported:2329 * <pre><code class='java'> // Name is bean class with 'first' and 'last' String properties2330 *2331 * // name is null for noname => it does not match the filter on "name.first"2332 * assertThat(employees).filteredOn("name.first", "Luke")2333 * .containsOnly(luke);2334 *2335 * assertThat(employees).filteredOn("name.last", "Vader")2336 * .isEmpty();</code></pre>2337 * <p>2338 * If you want to filter on null value, use {@link #filteredOnNull(String)} as Java will resolve the call to2339 * {@link #filteredOn(String, FilterOperator)} instead of this method.2340 * <p>2341 * An {@link IntrospectionError} is thrown if the given propertyOrFieldName can't be found in one of the array2342 * elements.2343 * <p>2344 * You can chain filters:2345 * <pre><code class='java'> // fellowshipOfTheRing is an array of TolkienCharacter having race and name fields2346 * // 'not' filter is statically imported from Assertions.not2347 *2348 * assertThat(fellowshipOfTheRing).filteredOn("race.name", "Man")2349 * .filteredOn("name", not("Boromir"))2350 * .containsOnly(aragorn);</code></pre>2351 * <p>2352 * If you need more complex filter, use {@link #filteredOn(Condition)} or {@link #filteredOn(Predicate)} and 2353 * provide a {@link Condition} or {@link Predicate} to specify the filter to apply.2354 *2355 * @param propertyOrFieldName the name of the property or field to read2356 * @param expectedValue the value to compare element's property or field with2357 * @return a new assertion object with the filtered list under test2358 * @throws IllegalArgumentException if the given propertyOrFieldName is {@code null} or empty.2359 * @throws IntrospectionError if the given propertyOrFieldName can't be found in one of the array elements.2360 */2361 @CheckReturnValue2362 public AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> filteredOn(String propertyOrFieldName,2363 Object expectedValue) {2364 Iterable<? extends ELEMENT> filteredIterable = filter(actual).with(propertyOrFieldName, expectedValue).get();2365 return newListAssertInstance(newArrayList(filteredIterable));2366 }2367 /**2368 * Filter the array under test into a list composed of the elements whose property or field specified 2369 * by {@code propertyOrFieldName} are null.2370 * <p>2371 * The filter first tries to get the value from a property (named {@code propertyOrFieldName}), if no such property2372 * exists it tries to read the value from a field. Reading private fields is supported by default, this can be2373 * globally disabled by calling {@link Assertions#setAllowExtractingPrivateFields(boolean)2374 * Assertions.setAllowExtractingPrivateFields(false)}.2375 * <p>2376 * When reading <b>nested</b> property/field, if an intermediate value is null the whole nested property/field is2377 * considered to be null, thus reading "address.street.name" value will return null if "street" value is null.2378 * <p>2379 * As an example, let's check all employees 800 years old (yes, special employees):2380 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2381 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2382 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2383 * Employee noname = new Employee(4L, null, 50);2384 *2385 * Employee[] employees = new Employee[] { yoda, luke, obiwan, noname };2386 *2387 * assertThat(employees).filteredOnNull("name")2388 * .containsOnly(noname);</code></pre>2389 *2390 * Nested properties/fields are supported:2391 * <pre><code class='java'> // Name is bean class with 'first' and 'last' String properties2392 *2393 * assertThat(employees).filteredOnNull("name.last")2394 * .containsOnly(yoda, obiwan, noname);</code></pre>2395 *2396 * An {@link IntrospectionError} is thrown if the given propertyOrFieldName can't be found in one of the array2397 * elements.2398 *2399 * @param propertyOrFieldName the name of the property or field to read2400 * @return a new assertion object with the filtered list under test2401 * @throws IntrospectionError if the given propertyOrFieldName can't be found in one of the array elements.2402 */2403 @CheckReturnValue2404 public AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> filteredOnNull(String propertyOrFieldName) {2405 // can't call filteredOn(String propertyOrFieldName, null) as it does not work with soft assertions proxying2406 // mechanism, it would lead to double proxying which is not handle properly (improvements needed in our proxy mechanism)2407 Iterable<? extends ELEMENT> filteredIterable = filter(actual).with(propertyOrFieldName, null).get();2408 return newListAssertInstance(newArrayList(filteredIterable));2409 }2410 /**2411 * Filter the array under test into a list composed of elements having a property or field matching the filter expressed with2412 * the {@link FilterOperator}, the property/field is specified by {@code propertyOrFieldName} parameter.2413 * <p>2414 * The existing filters are :2415 * <ul>2416 * <li> {@link Assertions#not(Object) not(Object)}</li>2417 * <li> {@link Assertions#in(Object...) in(Object...)}</li>2418 * <li> {@link Assertions#notIn(Object...) notIn(Object...)}</li>2419 * </ul>2420 * <p>2421 * Whatever filter is applied, it first tries to get the value from a property (named {@code propertyOrFieldName}), if2422 * no such property exists it tries to read the value from a field. Reading private fields is supported by default,2423 * this can be globally disabled by calling {@link Assertions#setAllowExtractingPrivateFields(boolean)2424 * Assertions.setAllowExtractingPrivateFields(false)}.2425 * <p>2426 * When reading <b>nested</b> property/field, if an intermediate value is null the whole nested property/field is2427 * considered to be null, thus reading "address.street.name" value will return null if "street" value is null.2428 * <p>2429 * As an example, let's check stuff on some special employees :2430 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2431 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2432 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2433 *2434 * Employee[] employees = new Employee[] { yoda, luke, obiwan, noname };2435 *2436 * // 'not' filter is statically imported from Assertions.not2437 * assertThat(employees).filteredOn("age", not(800))2438 * .containsOnly(luke);2439 *2440 * // 'in' filter is statically imported from Assertions.in2441 * // Name is bean class with 'first' and 'last' String properties2442 * assertThat(employees).filteredOn("name.first", in("Yoda", "Luke"))2443 * .containsOnly(yoda, luke);2444 *2445 * // 'notIn' filter is statically imported from Assertions.notIn2446 * assertThat(employees).filteredOn("name.first", notIn("Yoda", "Luke"))2447 * .containsOnly(obiwan);</code></pre>2448 *2449 * An {@link IntrospectionError} is thrown if the given propertyOrFieldName can't be found in one of the array2450 * elements.2451 * <p>2452 * Note that combining filter operators is not supported, thus the following code is not correct:2453 * <pre><code class='java'> // Combining filter operators like not(in(800)) is NOT supported2454 * // -> throws UnsupportedOperationException2455 * assertThat(employees).filteredOn("age", not(in(800)))2456 * .contains(luke);</code></pre>2457 * <p>2458 * You can chain filters:2459 * <pre><code class='java'> // fellowshipOfTheRing is an array of TolkienCharacter having race and name fields2460 * // 'not' filter is statically imported from Assertions.not2461 *2462 * assertThat(fellowshipOfTheRing).filteredOn("race.name", "Man")2463 * .filteredOn("name", not("Boromir"))2464 * .containsOnly(aragorn);</code></pre>2465 * <p>2466 * If you need more complex filter, use {@link #filteredOn(Condition)} or {@link #filteredOn(Predicate)} and 2467 * provide a {@link Condition} or {@link Predicate} to specify the filter to apply.2468 *2469 * @param propertyOrFieldName the name of the property or field to read2470 * @param filterOperator the filter operator to apply2471 * @return a new assertion object with the filtered list under test2472 * @throws IllegalArgumentException if the given propertyOrFieldName is {@code null} or empty.2473 */2474 @CheckReturnValue2475 public AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> filteredOn(String propertyOrFieldName,2476 FilterOperator<?> filterOperator) {2477 checkNotNull(filterOperator);2478 Filters<? extends ELEMENT> filter = filter(actual).with(propertyOrFieldName);2479 filterOperator.applyOn(filter);2480 return newListAssertInstance(newArrayList(filter.get()));2481 }2482 /**2483 * Filter the array under test into a list composed of the elements matching the given {@link Condition}, 2484 * allowing to perform assertions on the filtered list.2485 * <p>2486 * Let's check old employees whose age > 100:2487 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2488 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2489 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2490 * Employee noname = new Employee(4L, null, 50);2491 *2492 * Employee[] employees = new Employee[] { yoda, luke, obiwan, noname };2493 *2494 * // old employee condition, "old employees" describes the condition in error message2495 * // you just have to implement 'matches' method2496 * Condition<Employee> oldEmployees = new Condition<Employee>("old employees") {2497 * {@literal @}Override2498 * public boolean matches(Employee employee) {2499 * return employee.getAge() > 100;2500 * }2501 * };2502 * }2503 * assertThat(employees).filteredOn(oldEmployees)2504 * .containsOnly(yoda, obiwan);</code></pre>2505 *2506 * You can combine {@link Condition} with condition operator like {@link Not}:2507 * <pre><code class='java'> // 'not' filter is statically imported from Assertions.not2508 * assertThat(employees).filteredOn(not(oldEmployees))2509 * .contains(luke, noname);</code></pre>2510 *2511 * @param condition the filter condition / predicate2512 * @return a new assertion object with the filtered list under test2513 * @throws IllegalArgumentException if the given condition is {@code null}.2514 */2515 @CheckReturnValue2516 public AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> filteredOn(Condition<? super ELEMENT> condition) {2517 Iterable<? extends ELEMENT> filteredIterable = filter(actual).being(condition).get();2518 return newListAssertInstance(newArrayList(filteredIterable));2519 }2520 /**2521 * Filter the array under test into a list composed of the elements matching the given {@link Predicate}, 2522 * allowing to perform assertions on the filtered list.2523 * <p>2524 * Example : check old employees whose age > 100:2525 *2526 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2527 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2528 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2529 *2530 * Employee[] employees = new Employee[] { yoda, luke, obiwan };2531 *2532 * assertThat(employees).filteredOn(employee -> employee.getAge() > 100)2533 * .containsOnly(yoda, obiwan);</code></pre>2534 *2535 * @param predicate the filter predicate2536 * @return a new assertion object with the filtered list under test2537 * @throws IllegalArgumentException if the given predicate is {@code null}.2538 */2539 public AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> filteredOn(Predicate<? super ELEMENT> predicate) {2540 checkArgument(predicate != null, "The filter predicate should not be null");2541 List<ELEMENT> filtered = stream(actual).filter(predicate).collect(toList());2542 return newListAssertInstance(filtered);2543 }2544 /**2545 * Verifies that all elements match the given {@link Predicate}.2546 * <p>2547 * Example :2548 * <pre><code class='java'> String[] abc = {"a", "b", "c"};2549 * String[] abcc = {"a", "b", "cc"};2550 *2551 * // assertion will pass2552 * assertThat(abc).allMatch(s -> s.length() == 1);2553 *2554 * // assertion will fail2555 * assertThat(abcc).allMatch(s -> s.length() == 1);</code></pre>2556 *2557 * Note that you can achieve the same result with {@link #are(Condition) are(Condition)} or {@link #have(Condition) have(Condition)}.2558 *2559 * @param predicate the given {@link Predicate}.2560 * @return {@code this} object.2561 * @throws NullPointerException if the given predicate is {@code null}.2562 * @throws AssertionError if an element cannot be cast to ELEMENT.2563 * @throws AssertionError if one or more elements don't satisfy the given predicate.2564 */2565 @Override2566 public SELF allMatch(Predicate<? super ELEMENT> predicate) {2567 iterables.assertAllMatch(info, newArrayList(actual), predicate, PredicateDescription.GIVEN);2568 return myself;2569 }2570 /**2571 * {@inheritDoc}2572 */2573 @Override2574 public SELF allMatch(Predicate<? super ELEMENT> predicate, String predicateDescription) {2575 iterables.assertAllMatch(info, newArrayList(actual), predicate, new PredicateDescription(predicateDescription));2576 return myself;2577 }2578 /**2579 * {@inheritDoc}2580 */2581 @Override2582 public SELF allSatisfy(Consumer<? super ELEMENT> requirements) {2583 iterables.assertAllSatisfy(info, newArrayList(actual), requirements);2584 return myself;2585 }2586 /**2587 * Verifies whether any elements match the provided {@link Predicate}.2588 * <p>2589 * Example :2590 * <pre><code class='java'> String[] abcc = { "a", "b", "cc" };2591 *2592 * // assertion will pass2593 * assertThat(abc).anyMatch(s -> s.length() == 2);2594 *2595 * // assertion will fail2596 * assertThat(abcc).anyMatch(s -> s.length() > 2);</code></pre>2597 *2598 * Note that you can achieve the same result with {@link #areAtLeastOne(Condition) areAtLeastOne(Condition)}2599 * or {@link #haveAtLeastOne(Condition) haveAtLeastOne(Condition)}.2600 *2601 * @param predicate the given {@link Predicate}.2602 * @return {@code this} object.2603 * @throws NullPointerException if the given predicate is {@code null}.2604 * @throws AssertionError if no elements satisfy the given predicate.2605 * @since 3.9.02606 */2607 @Override2608 public SELF anyMatch(Predicate<? super ELEMENT> predicate) {2609 iterables.assertAnyMatch(info, newArrayList(actual), predicate, PredicateDescription.GIVEN);2610 return myself;2611 }2612 /**2613 * Verifies that the zipped pairs of actual and other elements, i.e: (actual 1st element, other 1st element), (actual 2nd element, other 2nd element), ... 2614 * all satisfy the given {@code zipRequirements}. 2615 * <p>2616 * This assertion assumes that actual and other have the same size but they can contain different type of elements 2617 * making it handy to compare objects converted to another type, for example Domain and View/DTO objects. 2618 * <p>2619 * Example:2620 * <pre><code class='java'> Adress[] addressModels = findGoodRestaurants();2621 * AdressView[] addressViews = convertToView(addressModels);2622 * 2623 * // compare addressViews and addressModels respective paired elements. 2624 * assertThat(addressViews).zipSatisfy(addressModels, (AdressView view, Adress model) -> {2625 * assertThat(view.getZipcode() + ' ' + view.getCity()).isEqualTo(model.getCityLine());2626 * assertThat(view.getStreet()).isEqualTo(model.getStreet().toUpperCase());2627 * });</code></pre>2628 *2629 * @param <OTHER_ELEMENT> the type of the other array elements.2630 * @param other the array to zip actual with.2631 * @param zipRequirements the given requirements that each pair must sastify.2632 * @return {@code this} assertion object.2633 * @throws NullPointerException if the given zipRequirements {@link BiConsumer} is {@code null}.2634 * @throws NullPointerException if the the other array to zip actual with is {@code null}.2635 * @throws AssertionError if the array under test is {@code null}.2636 * @throws AssertionError if actual and other don't have the same size.2637 * @throws AssertionError if one or more pairs don't satisfy the given requirements.2638 * @since 3.9.02639 */2640 public <OTHER_ELEMENT> SELF zipSatisfy(OTHER_ELEMENT[] other,2641 BiConsumer<? super ELEMENT, OTHER_ELEMENT> zipRequirements) {2642 iterables.assertZipSatisfy(info, newArrayList(actual), newArrayList(other), zipRequirements);2643 return myself;2644 }2645 /**2646 * {@inheritDoc}2647 */2648 @Override2649 public SELF anySatisfy(Consumer<? super ELEMENT> requirements) {2650 iterables.assertAnySatisfy(info, newArrayList(actual), requirements);2651 return myself;2652 }2653 /**2654 * Verifies that the actual array contains at least one of the given values.2655 * <p>2656 * Example :2657 * <pre><code class='java'> String[] abc = {"a", "b", "c"};2658 *2659 * // assertions will pass2660 * assertThat(abc).containsAnyOf("b")2661 * .containsAnyOf("b", "c")2662 * .containsAnyOf("a", "b", "c")2663 * .containsAnyOf("a", "b", "c", "d")2664 * .containsAnyOf("e", "f", "g", "b");2665 *2666 * // assertions will fail2667 * assertThat(abc).containsAnyOf("d");2668 * assertThat(abc).containsAnyOf("d", "e", "f", "g");</code></pre>2669 *2670 * @param values the values whose at least one which is expected to be in the array under test.2671 * @return {@code this} assertion object.2672 * @throws NullPointerException if the array of values is {@code null}.2673 * @throws IllegalArgumentException if the array of values is empty and the array under test is not empty.2674 * @throws AssertionError if the array under test is {@code null}.2675 * @throws AssertionError if the array under test does not contain any of the given {@code values}.2676 * @since 2.9.0 / 3.9.02677 */2678 @Override2679 public SELF containsAnyOf(@SuppressWarnings("unchecked") ELEMENT... values) {2680 arrays.assertContainsAnyOf(info, actual, values);2681 return myself;2682 }2683 /**2684 * Verifies that the actual array contains at least one of the given {@link Iterable} elements.2685 * <p>2686 * Example :2687 * <pre><code class='java'> String[] abc = {"a", "b", "c"};2688 *2689 * // assertions will pass2690 * assertThat(abc).containsAnyElementsOf(Arrays.asList("b"))2691 * .containsAnyElementsOf(Arrays.asList("b", "c"))2692 * .containsAnyElementsOf(Arrays.asList("a", "b", "c"))2693 * .containsAnyElementsOf(Arrays.asList("a", "b", "c", "d"))2694 * .containsAnyElementsOf(Arrays.asList("e", "f", "g", "b"));2695 *2696 * // assertions will fail2697 * assertThat(abc).containsAnyElementsOf(Arrays.asList("d"));2698 * assertThat(abc).containsAnyElementsOf(Arrays.asList("d", "e", "f", "g"));</code></pre>2699 *2700 * @param iterable the iterable whose at least one element is expected to be in the array under test.2701 * @return {@code this} assertion object.2702 * @throws NullPointerException if the iterable of expected values is {@code null}.2703 * @throws IllegalArgumentException if the iterable of expected values is empty and the array under test is not empty.2704 * @throws AssertionError if the array under test is {@code null}.2705 * @throws AssertionError if the array under test does not contain any of elements from the given {@code Iterable}.2706 * @since 2.9.0 / 3.9.02707 */2708 @Override2709 public SELF containsAnyElementsOf(Iterable<ELEMENT> iterable) {2710 return containsAnyOf(toArray(iterable));2711 }2712 /**2713 * Verifies that no elements match the given {@link Predicate}.2714 * <p>2715 * Example :2716 * <pre><code class='java'> String[] abcc = { "a", "b", "cc" };2717 *2718 * // assertion will pass2719 * assertThat(abcc).noneMatch(s -> s.isEmpty());2720 *2721 * // assertion will fail2722 * assertThat(abcc).noneMatch(s -> s.length() == 2);</code></pre>2723 *2724 * Note that you can achieve the same result with {@link #areNot(Condition) areNot(Condition)}2725 * or {@link #doNotHave(Condition) doNotHave(Condition)}.2726 *2727 * @param predicate the given {@link Predicate}.2728 * @return {@code this} object.2729 * @throws NullPointerException if the given predicate is {@code null}.2730 * @throws AssertionError if an element cannot be cast to ELEMENT.2731 * @throws AssertionError if any element satisfy the given predicate.2732 * @since 3.9.02733 */2734 @Override2735 public SELF noneMatch(Predicate<? super ELEMENT> predicate) {2736 iterables.assertNoneMatch(info, newArrayList(actual), predicate, PredicateDescription.GIVEN);2737 return myself;2738 }2739 /**2740 * Create a friendly soft or "hard" assertion.2741 * <p>2742 * Implementations need to redefine it so that some methods, such as {@link #extracting(Extractor)}, are able2743 * to build the appropriate list assert (eg: {@link ListAssert} versus {@link ProxyableListAssert}).2744 * <p>2745 * The default implementation will assume that this concrete implementation is NOT a soft assertion.2746 *2747 * @param <E> the type of elements.2748 * @param newActual new value2749 * @return a new {@link AbstractListAssert}.2750 */2751 protected <E> AbstractListAssert<?, List<? extends E>, E, ObjectAssert<E>> newListAssertInstance(List<? extends E> newActual) {2752 return new ListAssert<>(newActual);2753 }2754}...
Source:ProxyableObjectArrayAssert.java
...24 public ProxyableObjectArrayAssert(AtomicReferenceArray<ELEMENT> actual) {25 this(array(actual));26 }27 @Override28 protected <E> AbstractListAssert<?, List<? extends E>, E, ObjectAssert<E>> newListAssertInstance(List<? extends E> newActual) {29 return new ProxyableListAssert<>(newActual);30 }31}...
newListAssertInstance
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.assertj.core.api.ObjectArrayAssert;3import org.assertj.core.api.ObjectArrayAssertBaseTest;4import static org.mockito.Mockito.verify;5public class ObjectArrayAssert_newListAssertInstance_Test extends ObjectArrayAssertBaseTest {6 protected ObjectArrayAssert<Object> invoke_api_method() {7 return assertions.newListAssertInstance();8 }9 protected void verify_internal_effects() {10 verify(objects).assertIsInstanceOf(Assertions.assertThat(new Object[0]).actual, Object[].class);11 }12}13import org.assertj.core.api.ObjectArrayAssert;14import org.assertj.core.api.ObjectArrayAssertBaseTest;15import static org.assertj.core.util.Lists.list;16public class ObjectArrayAssert_newListAssertInstance_Test extends ObjectArrayAssertBaseTest {17 protected ObjectArrayAssert<Object> invoke_api_method() {18 return assertions.newListAssertInstance();19 }20 protected void verify_internal_effects() {21 assertions.newListAssertInstance().isEqualTo(list());22 }23}24import org.assertj.core.api.ObjectArrayAssert;25import org.assertj.core.api.ObjectArrayAssertBaseTest;26import static org.assertj.core.util.Lists.list;27public class ObjectArrayAssert_newListAssertInstance_Test extends ObjectArrayAssertBaseTest {28 protected ObjectArrayAssert<Object> invoke_api_method() {29 return assertions.newListAssertInstance();30 }31 protected void verify_internal_effects() {32 assertions.newListAssertInstance().containsExactlyElementsOf(list());33 }34}35import org.assertj.core.api.ObjectArrayAssert;36import org.assertj.core.api.ObjectArrayAssertBaseTest;37import static org.assertj.core.util.Lists.list;38public class ObjectArrayAssert_newListAssertInstance_Test extends ObjectArrayAssertBaseTest {39 protected ObjectArrayAssert<Object> invoke_api_method() {40 return assertions.newListAssertInstance();41 }42 protected void verify_internal_effects() {43 assertions.newListAssertInstance().containsExactlyElementsOf(list());44 }45}
newListAssertInstance
Using AI Code Generation
1import org.assertj.core.api.*;2import org.assertj.core.api.ObjectArrayAssert;3import org.assertj.core.api.ObjectArrayAssertBaseTest;4import org.junit.jupiter.api.Test;5public class NewListAssertInstance extends ObjectArrayAssertBaseTest {6 protected ObjectArrayAssert<Object> invoke_api_method() {7 return assertions.newListAssertInstance();8 }9 protected void verify_internal_effects() {10 }11}
newListAssertInstance
Using AI Code Generation
1public class Test {2 public static void main(String[] args) {3 Integer[] actual = {1, 2, 3};4 Integer[] expected = {1, 2, 3};5 Assertions.assertThat(actual).newListAssertInstance(expected);6 }7}8Exception in thread "main" java.lang.NoSuchMethodError: org.assertj.core.api.AbstractObjectArrayAssert.newListAssertInstance([Ljava/lang/Object;)Lorg/assertj/core/api/AbstractListAssert;9 at Test.main(Test.java:7)10public static <T> Stream<T> stream(Collection<T> collection)11public static <T> Stream<T> parallelStream(Collection<T> collection)12public static <T> Spliterator<T> spliterator(Collection<T> collection)13public static <K,V> Stream<Map.Entry<K,V>> stream(Map<K,V> map)14public static <K,V> Stream<Map.Entry<K,V>> parallelStream(Map<K,V> map)15public static <K,V> Spliterator<Map.Entry<K,V>> spliterator(Map<K,V> map)16public static <T> Stream<T> stream(Iterator<T> iterator)17public static <T> Stream<T> stream(Iterator<T> iterator, boolean isParallel)18public static <T> Spliterator<T> spliterator(Iterator<T> iterator)19public static <T> Stream<T> stream(Enumeration<T> enumeration)20public static <T> Stream<T> stream(Enumeration<T> enumeration, boolean isParallel)21public static <T> Spliterator<T> spliterator(Enumeration<T> enumeration)22public static <T> Stream<T> iterate(T seed, Predicate<? super T> hasNext, UnaryOperator<T> next)23public static <T> Stream<T> generate(Supplier<T> s)24public static <T> Stream<T> ofNullable(T t)25public static <T> Stream<T> empty()26public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)27public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b, Stream<? extends T> c)28public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b, Stream<? extends T> c
newListAssertInstance
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import java.util.List;3import java.util.Arrays;4public class 1 {5 public static void main(String[] args) {6 List<String> list = Arrays.asList("A", "B", "C");7 assertThat(list).newListAssertInstance();8 }9}
newListAssertInstance
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import java.util.List;3import org.assertj.core.api.AbstractObjectArrayAssert;4public class Test {5 public static void main(String[] args) {6 String[] array = new String[]{"a", "b", "c"};7 AbstractObjectArrayAssert<?, ?> assertInstance = newListAssertInstance(array);8 List<String> list = assertInstance.asList();9 System.out.println(list);10 }11}
newListAssertInstance
Using AI Code Generation
1import org.assertj.core.api.ObjectArrayAssert;2public class Demo1 {3public static void main(String[] args) {4ObjectArrayAssert<Integer> obj = ObjectArrayAssert.newListAssertInstance(new Integer[] { 1, 2, 3 });5System.out.println(obj);6}7}8import org.assertj.core.api.ObjectArrayAssert;9public class Demo2 {10public static void main(String[] args) {11ObjectArrayAssert<Integer> obj = ObjectArrayAssert.newListAssertInstance(new Integer[] { 1, 2, 3 });12System.out.println(obj);13}14}15import org.assertj.core.api.ObjectArrayAssert;16public class Demo3 {17public static void main(String[] args) {18ObjectArrayAssert<Integer> obj = ObjectArrayAssert.newListAssertInstance(new Integer[] { 1, 2, 3 });19System.out.println(obj);20}21}22import org.assertj.core.api.ObjectArrayAssert;23public class Demo4 {24public static void main(String[] args) {25ObjectArrayAssert<Integer> obj = ObjectArrayAssert.newListAssertInstance(new Integer[] { 1, 2, 3 });26System.out.println(obj);27}28}29import org.assertj.core.api.ObjectArrayAssert;30public class Demo5 {31public static void main(String[] args) {32ObjectArrayAssert<Integer> obj = ObjectArrayAssert.newListAssertInstance(new Integer[] { 1, 2, 3 });33System.out.println(obj);34}35}36import org.assertj.core.api.ObjectArrayAssert;37public class Demo6 {38public static void main(String[] args) {
newListAssertInstance
Using AI Code Generation
1package org.assertj.examples;2import org.assertj.core.api.AbstractObjectArrayAssert;3import org.assertj.core.api.ListAssert;4public class AssertJExample {5 public static void main(String[] args) {6 AbstractObjectArrayAssert<?, Object> assertInstance = AbstractObjectArrayAssert.newListAssertInstance();7 ListAssert<Object> listAssert = assertInstance.asList();8 listAssert.contains("1", "2", "3");9 }10}11package org.assertj.examples;12import org.assertj.core.api.AbstractObjectArrayAssert;13import org.assertj.core.api.ListAssert;14public class AssertJExample {15 public static void main(String[] args) {16 AbstractObjectArrayAssert<?, Object> assertInstance = AbstractObjectArrayAssert.newListAssertInstance();17 ListAssert<Object> listAssert = assertInstance.asList();18 listAssert.contains("1", "2", "3");19 }20}21package org.assertj.examples;22import org.assertj.core.api.AbstractObjectArrayAssert;23import org.assertj.core.api.ListAssert;24public class AssertJExample {25 public static void main(String[] args) {26 AbstractObjectArrayAssert<?, Object> assertInstance = AbstractObjectArrayAssert.newListAssertInstance();27 ListAssert<Object> listAssert = assertInstance.asList();28 listAssert.contains("1", "2", "3");29 }30}
newListAssertInstance
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import org.assertj.core.api.ObjectArrayAssert;3class Test {4public static void main(String[] args) {5ObjectArrayAssert<Object> objectArrayAssert = newListAssertInstance();6}7}8Exception in thread "main" java.lang.NoSuchMethodError: org.assertj.core.api.AbstractObjectArrayAssert.newListAssertInstance()Lorg/assertj/core/api/ObjectArrayAssert;9at Test.main(Test.java:8)10Exception in thread "main" java.lang.NoSuchMethodError: org.assertj.core.api.AbstractObjectArrayAssert.newListAssertInstance()Lorg/assertj/core/api/ObjectArrayAssert;11at Test.main(Test.java:8)
newListAssertInstance
Using AI Code Generation
1import org.assertj.core.api.*;2import java.util.*;3import java.util.stream.*;4import java.util.function.*;5import java.util.concurrent.*;6import java.util.regex.*;7import java.util.function.*;8import java.util.concurrent.*;9public class 1 {10 public static void main(String[] args) {11 List<String> list = new ArrayList<String>();12 list.add("abc");13 list.add("def");14 list.add("ghi");15 ListAssert<String> listAssert = Assertions.assertThat(list);16 ObjectArrayAssert<Object> objectArrayAssert = listAssert.newListAssertInstance();17 System.out.println(objectArrayAssert);18 }19}20import org.assertj.core.api.*;21import java.util.*;22import java.util.stream.*;23import java.util.function.*;24import java.util.concurrent.*;25import java.util.regex.*;26import java.util.function.*;27import java.util.concurrent.*;28public class 2 {29 public static void main(String[] args) {30 List<String> list = new ArrayList<String>();31 list.add("abc");32 list.add("def");33 list.add("ghi");34 ListAssert<String> listAssert = Assertions.assertThat(list);35 ObjectArrayAssert<Object> objectArrayAssert = listAssert.newListAssertInstance();36 System.out.println(objectArrayAssert);37 }38}39import org.assertj.core.api.*;40import java.util.*;41import java.util.stream.*;42import java.util.function.*;43import java.util.concurrent.*;44import java.util.regex.*;45import java.util.function.*;46import java.util.concurrent.*;47public class 3 {48 public static void main(String[] args) {49 List<String> list = new ArrayList<String>();50 list.add("abc");51 list.add("def");52 list.add("ghi");53 ListAssert<String> listAssert = Assertions.assertThat(list);54 ObjectArrayAssert<Object> objectArrayAssert = listAssert.newListAssertInstance();55 System.out.println(objectArrayAssert);56 }57}58import org.assertj.core.api.*;59import java.util.*;60import java.util.stream.*;61import java.util.function.*;62import java.util.concurrent.*;63import java.util.regex.*;64import java.util.function.*;65import java.util.concurrent.*;66public class 4 {67 public static void main(String
newListAssertInstance
Using AI Code Generation
1import org.assertj.core.api.*;2import org.junit.Test;3public class AssertJTest {4public void test() {5Object[] arr = new Object[]{1, 2, 3};6AbstractObjectArrayAssert<?, ?> assert1 = Assertions.newListAssertInstance(arr);7}8}
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!!