How to use getComparatorsForElementPropertyOrFieldTypes method of org.assertj.core.api.AtomicReferenceArrayAssert class

Best Assertj code snippet using org.assertj.core.api.AtomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes

Source:AtomicReferenceArrayAssert.java Github

copy

Full Screen

...1799 */1800 @CheckReturnValue1801 public <C> AtomicReferenceArrayAssert<T> usingComparatorForElementFieldsWithType(Comparator<C> comparator,1802 Class<C> type) {1803 getComparatorsForElementPropertyOrFieldTypes().put(type, comparator);1804 return myself;1805 }1806 /**1807 * Allows to set a specific comparator for the given type of elements or their fields.1808 * Extends {@link #usingComparatorForElementFieldsWithType} by applying comparator specified for given type1809 * to elements themselves, not only to their fields.1810 * <p>1811 * Usage of this method affects comparators set by next methods:1812 * <ul>1813 * <li>{@link #usingFieldByFieldElementComparator}</li>1814 * <li>{@link #usingElementComparatorOnFields}</li>1815 * <li>{@link #usingElementComparatorIgnoringFields}</li>1816 * <li>{@link #usingRecursiveFieldByFieldElementComparator}</li>1817 * </ul>1818 * <p>1819 * Example:1820 * <pre><code class='java'> // assertion will pass1821 * assertThat(new AtomicReferenceArray&lt;&gt;(new Object[] { "some", new BigDecimal("4.2") }))1822 * .usingComparatorForType(BIG_DECIMAL_COMPARATOR, BigDecimal.class)1823 * .contains(new BigDecimal("4.20"));1824 * </code></pre>1825 *1826 * @param <C> the type to compare.1827 * @param comparator the {@link java.util.Comparator} to use1828 * @param type the {@link java.lang.Class} of the type of the element or element fields the comparator should be used for1829 * @return {@code this} assertions object1830 * @since 2.9.0 / 3.9.01831 */1832 @CheckReturnValue1833 public <C> AtomicReferenceArrayAssert<T> usingComparatorForType(Comparator<C> comparator, Class<C> type) {1834 if (arrays.getComparator() == null) {1835 usingElementComparator(new ExtendedByTypesComparator(getComparatorsByType()));1836 }1837 getComparatorsForElementPropertyOrFieldTypes().put(type, comparator);1838 getComparatorsByType().put(type, comparator);1839 return myself;1840 }1841 /**1842 * Use field/property by field/property comparison (including inherited fields/properties) instead of relying on1843 * actual type A <code>equals</code> method to compare AtomicReferenceArray elements for incoming assertion checks. Private fields1844 * are included but this can be disabled using {@link Assertions#setAllowExtractingPrivateFields(boolean)}.1845 * <p>1846 * This can be handy if <code>equals</code> method of the objects to compare does not suit you.1847 * <p>1848 * You can specify a custom comparator per name or type of element field with1849 * {@link #usingComparatorForElementFieldsWithNames(Comparator, String...)}1850 * and {@link #usingComparatorForElementFieldsWithType(Comparator, Class)}.1851 * <p>1852 * Note that the comparison is <b>not</b> recursive, if one of the fields/properties is an Object, it will be compared1853 * to the other field/property using its <code>equals</code> method.1854 * </p>1855 * Example:1856 * <pre><code class='java'> TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);1857 * TolkienCharacter frodoClone = new TolkienCharacter("Frodo", 33, HOBBIT);1858 *1859 * // Fail if equals has not been overridden in TolkienCharacter as equals default implementation only compares references1860 * assertThat(atomicArray(frodo)).contains(frodoClone);1861 *1862 * // frodo and frodoClone are equals when doing a field by field comparison.1863 * assertThat(atomicArray(frodo)).usingFieldByFieldElementComparator().contains(frodoClone);</code></pre>1864 *1865 * @return {@code this} assertion object.1866 * @since 2.7.0 / 3.7.01867 */1868 @CheckReturnValue1869 public AtomicReferenceArrayAssert<T> usingFieldByFieldElementComparator() {1870 return usingExtendedByTypesElementComparator(new FieldByFieldComparator(comparatorsForElementPropertyOrFieldNames,1871 getComparatorsForElementPropertyOrFieldTypes()));1872 }1873 /**1874 * Use a recursive field/property by field/property comparison (including inherited fields/properties)1875 * instead of relying on actual type A <code>equals</code> method to compare AtomicReferenceArray elements for incoming1876 * assertion checks. This can be useful if actual's {@code equals} implementation does not suit you.1877 * <p>1878 * The recursive property/field comparison is <b>not</b> applied on fields having a custom {@code equals}1879 * implementation, i.e. the overridden {@code equals} method will be used instead of a field/property by field/property comparison.1880 * <p>1881 * You can specify a custom comparator per (nested) name or type of element field with1882 * {@link #usingComparatorForElementFieldsWithNames(Comparator, String...) usingComparatorForElementFieldsWithNames}1883 * and {@link #usingComparatorForElementFieldsWithType(Comparator, Class) usingComparatorForElementFieldsWithType}.1884 * <p>1885 * The recursive comparison handles cycles.1886 * <p>1887 * The objects to compare can be of different types but must have the same properties/fields. For example if actual object has a1888 * {@code name} String field, the other object must also have one.1889 * <p>1890 * If an object has a field and a property with the same name, the property value will be used over the field.1891 * <p>1892 * Example:1893 *1894 * <pre><code class='java'> TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);1895 * TolkienCharacter pippin = new TolkienCharacter("Pippin", 28, HOBBIT);1896 * frodo.setFriend(pippin);1897 * pippin.setFriend(frodo);1898 *1899 * TolkienCharacter frodoClone = new TolkienCharacter("Frodo", 33, HOBBIT);1900 * TolkienCharacter pippinClone = new TolkienCharacter("Pippin", 28, HOBBIT);1901 * frodoClone.setFriend(pippinClone);1902 * pippinClone.setFriend(frodoClone);1903 *1904 * AtomicReferenceArray&lt;TolkienCharacter&gt; hobbits = new AtomicReferenceArray&lt;&gt;(new TolkienCharacter[] {frodo, pippin});1905 *1906 * // fails if equals has not been overridden in TolkienCharacter as it would compares object references1907 * assertThat(hobbits).contains(frodoClone, pippinClone);1908 *1909 * // frodo/frodoClone and pippin/pippinClone are equals when doing a recursive property/field by property/field comparison1910 * assertThat(hobbits).usingRecursiveFieldByFieldElementComparator()1911 * .contains(frodoClone, pippinClone);</code></pre>1912 *1913 * @return {@code this} assertion object.1914 * @since 2.7.0 / 3.7.01915 */1916 @CheckReturnValue1917 public AtomicReferenceArrayAssert<T> usingRecursiveFieldByFieldElementComparator() {1918 return usingExtendedByTypesElementComparator(new RecursiveFieldByFieldComparator(comparatorsForElementPropertyOrFieldNames,1919 getComparatorsForElementPropertyOrFieldTypes()));1920 }1921 /**1922 * Use field/property by field/property comparison on the <b>given fields/properties only</b> (including inherited1923 * fields/properties) instead of relying on actual type A <code>equals</code> method to compare AtomicReferenceArray elements for1924 * incoming assertion checks. Private fields are included but this can be disabled using1925 * {@link Assertions#setAllowExtractingPrivateFields(boolean)}.1926 * <p>1927 * This can be handy if <code>equals</code> method of the objects to compare does not suit you.1928 * <p>1929 * You can specify a custom comparator per name or type of element field with1930 * {@link #usingComparatorForElementFieldsWithNames(Comparator, String...)}1931 * and {@link #usingComparatorForElementFieldsWithType(Comparator, Class)}.1932 * <p>1933 * Note that the comparison is <b>not</b> recursive, if one of the fields/properties is an Object, it will be compared1934 * to the other field/property using its <code>equals</code> method.1935 * </p>1936 * Example:1937 * <pre><code class='java'> TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);1938 * TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT);1939 *1940 * // frodo and sam both are hobbits, so they are equals when comparing only race1941 * assertThat(atomicArray(frodo)).usingElementComparatorOnFields("race").contains(sam); // OK1942 *1943 * // ... but not when comparing both name and race1944 * assertThat(atomicArray(frodo)).usingElementComparatorOnFields("name", "race").contains(sam); // FAIL</code></pre>1945 *1946 * @param fields the fields to compare field/property by field/property.1947 * @return {@code this} assertion object.1948 * @since 2.7.0 / 3.7.01949 */1950 @CheckReturnValue1951 public AtomicReferenceArrayAssert<T> usingElementComparatorOnFields(String... fields) {1952 return usingExtendedByTypesElementComparator(new OnFieldsComparator(comparatorsForElementPropertyOrFieldNames,1953 getComparatorsForElementPropertyOrFieldTypes(), fields));1954 }1955 /**1956 * Use field/property by field/property on all fields/properties <b>except</b> the given ones (including inherited1957 * fields/properties) instead of relying on actual type A <code>equals</code> method to compare AtomicReferenceArray elements for1958 * incoming assertion checks. Private fields are included but this can be disabled using1959 * {@link Assertions#setAllowExtractingPrivateFields(boolean)}.1960 * <p>1961 * This can be handy if <code>equals</code> method of the objects to compare does not suit you.1962 * <p>1963 * You can specify a custom comparator per name or type of element field with1964 * {@link #usingComparatorForElementFieldsWithNames(Comparator, String...)}1965 * and {@link #usingComparatorForElementFieldsWithType(Comparator, Class)}.1966 * <p>1967 * Note that the comparison is <b>not</b> recursive, if one of the fields/properties is an Object, it will be compared1968 * to the other field/property using its <code>equals</code> method.1969 * </p>1970 * Example:1971 * <pre><code class='java'> TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);1972 * TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT);1973 *1974 * // frodo and sam both are hobbits, so they are equals when comparing only race (i.e. ignoring all other fields)1975 * assertThat(atomicArray(frodo)).usingElementComparatorIgnoringFields("name", "age").contains(sam); // OK1976 *1977 * // ... but not when comparing both name and race1978 * assertThat(atomicArray(frodo)).usingElementComparatorIgnoringFields("age").contains(sam); // FAIL</code></pre>1979 *1980 * @param fields the names of the fields/properties to ignore1981 * @return {@code this} assertion object.1982 * @since 2.7.0 / 3.7.01983 */1984 @CheckReturnValue1985 public AtomicReferenceArrayAssert<T> usingElementComparatorIgnoringFields(String... fields) {1986 return usingExtendedByTypesElementComparator(new IgnoringFieldsComparator(comparatorsForElementPropertyOrFieldNames,1987 getComparatorsForElementPropertyOrFieldTypes(),1988 fields));1989 }1990 /**1991 * Extract the values of given field or property from the array's elements under test into a new array, this new array1992 * becoming the array under test.1993 * <p>1994 * It allows you to test a field/property of the array's elements instead of testing the elements themselves, which can1995 * be much less work !1996 * <p>1997 * Let's take an example to make things clearer :1998 * <pre><code class='java'> // Build a 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 * AtomicReferenceArray&lt;TolkienCharacter&gt; fellowshipOfTheRing = new AtomicReferenceArray&lt;&gt;(new TolkienCharacter[]{2001 * new TolkienCharacter(&quot;Frodo&quot;, 33, HOBBIT),2002 * new TolkienCharacter(&quot;Sam&quot;, 38, HOBBIT),2003 * new TolkienCharacter(&quot;Gandalf&quot;, 2020, MAIA),2004 * new TolkienCharacter(&quot;Legolas&quot;, 1000, ELF),2005 * new TolkienCharacter(&quot;Pippin&quot;, 28, HOBBIT),2006 * new TolkienCharacter(&quot;Gimli&quot;, 139, DWARF),2007 * new TolkienCharacter(&quot;Aragorn&quot;, 87, MAN,2008 * new TolkienCharacter(&quot;Boromir&quot;, 37, MAN)2009 * };2010 *2011 * // let's verify the names of TolkienCharacter in fellowshipOfTheRing :2012 *2013 * assertThat(fellowshipOfTheRing).extracting(&quot;name&quot;)2014 * .contains(&quot;Boromir&quot;, &quot;Gandalf&quot;, &quot;Frodo&quot;)2015 * .doesNotContain(&quot;Sauron&quot;, &quot;Elrond&quot;);2016 *2017 * // you can also extract nested field/property like the name of Race :2018 *2019 * assertThat(fellowshipOfTheRing).extracting(&quot;race.name&quot;)2020 * .contains(&quot;Hobbit&quot;, &quot;Elf&quot;)2021 * .doesNotContain(&quot;Orc&quot;);</code></pre>2022 *2023 * A property with the given name is looked for first, if it does not exist then a field with the given name2024 * is looked for.2025 * <p>2026 * Note that the order of extracted field/property values is consistent with the array order.2027 *2028 * @param fieldOrProperty the field/property to extract from the array under test2029 * @return a new assertion object whose object under test is the array of extracted field/property values.2030 * @throws IntrospectionError if no field or property exists with the given name2031 * @since 2.7.0 / 3.7.02032 */2033 @CheckReturnValue2034 public ObjectArrayAssert<Object> extracting(String fieldOrProperty) {2035 Object[] values = FieldsOrPropertiesExtractor.extract(array, byName(fieldOrProperty));2036 String extractedDescription = extractedDescriptionOf(fieldOrProperty);2037 String description = mostRelevantDescription(info.description(), extractedDescription);2038 return new ObjectArrayAssert<>(values).as(description);2039 }2040 /**2041 * Extract the values of given field or property from the array's elements under test into a new array, this new array2042 * becoming the array under test with type.2043 * <p>2044 * It allows you to test a field/property of the array's elements instead of testing the elements themselves, which can2045 * be much less work !2046 * <p>2047 * Let's take an example to make things clearer :2048 * <pre><code class='java'> // Build an array of TolkienCharacter, a TolkienCharacter has a name (String) and a Race (a class)2049 * // they can be public field or properties, both works when extracting their values.2050 * AtomicReferenceArray&lt;TolkienCharacter&gt; fellowshipOfTheRing = new AtomicReferenceArray&lt;&gt;(new TolkienCharacter[]{2051 * new TolkienCharacter(&quot;Frodo&quot;, 33, HOBBIT),2052 * new TolkienCharacter(&quot;Sam&quot;, 38, HOBBIT),2053 * new TolkienCharacter(&quot;Gandalf&quot;, 2020, MAIA),2054 * new TolkienCharacter(&quot;Legolas&quot;, 1000, ELF),2055 * new TolkienCharacter(&quot;Pippin&quot;, 28, HOBBIT),2056 * new TolkienCharacter(&quot;Gimli&quot;, 139, DWARF),2057 * new TolkienCharacter(&quot;Aragorn&quot;, 87, MAN,2058 * new TolkienCharacter(&quot;Boromir&quot;, 37, MAN)2059 * };2060 *2061 * // let's verify the names of TolkienCharacter in fellowshipOfTheRing :2062 *2063 * assertThat(fellowshipOfTheRing).extracting(&quot;name&quot;, String.class)2064 * .contains(&quot;Boromir&quot;, &quot;Gandalf&quot;, &quot;Frodo&quot;)2065 * .doesNotContain(&quot;Sauron&quot;, &quot;Elrond&quot;);2066 *2067 * // you can also extract nested field/property like the name of Race :2068 *2069 * assertThat(fellowshipOfTheRing).extracting(&quot;race.name&quot;, String.class)2070 * .contains(&quot;Hobbit&quot;, &quot;Elf&quot;)2071 * .doesNotContain(&quot;Orc&quot;);</code></pre>2072 *2073 * A property with the given name is looked for first, if it does not exist then a field with the given name2074 * is looked for.2075 * <p>2076 * Note that the order of extracted field/property values is consistent with the order of the array under test.2077 *2078 * @param <P> the extracted type2079 * @param fieldOrProperty the field/property to extract from the array under test2080 * @param extractingType type to return2081 * @return a new assertion object whose object under test is the array of extracted field/property values.2082 * @throws IntrospectionError if no field or property exists with the given name2083 * @since 2.7.0 / 3.7.02084 */2085 @CheckReturnValue2086 public <P> ObjectArrayAssert<P> extracting(String fieldOrProperty, Class<P> extractingType) {2087 @SuppressWarnings("unchecked")2088 P[] values = (P[]) FieldsOrPropertiesExtractor.extract(array, byName(fieldOrProperty));2089 String extractedDescription = extractedDescriptionOf(fieldOrProperty);2090 String description = mostRelevantDescription(info.description(), extractedDescription);2091 return new ObjectArrayAssert<>(values).as(description);2092 }2093 /**2094 * Extract the values of given fields/properties from the array's elements under test into a new array composed of2095 * Tuple (a simple data structure), this new array becoming the array under test.2096 * <p>2097 * It allows you to test fields/properties of the array's elements instead of testing the elements themselves, it2098 * can be sometimes much less work !2099 * <p>2100 * The Tuple data corresponds to the extracted values of the given fields/properties, for instance if you ask to2101 * extract "id", "name" and "email" then each Tuple data will be composed of id, name and email extracted from the2102 * element of the initial array (the Tuple's data order is the same as the given fields/properties order).2103 * <p>2104 * Let's take an example to make things clearer :2105 * <pre><code class='java'> // Build an array of TolkienCharacter, a TolkienCharacter has a name (String) and a Race (a class)2106 * // they can be public field or properties, both works when extracting their values.2107 * AtomicReferenceArray&lt;TolkienCharacter&gt; fellowshipOfTheRing = new AtomicReferenceArray&lt;&gt;(new TolkienCharacter[]{2108 * new TolkienCharacter(&quot;Frodo&quot;, 33, HOBBIT),2109 * new TolkienCharacter(&quot;Sam&quot;, 38, HOBBIT),2110 * new TolkienCharacter(&quot;Gandalf&quot;, 2020, MAIA),2111 * new TolkienCharacter(&quot;Legolas&quot;, 1000, ELF),2112 * new TolkienCharacter(&quot;Pippin&quot;, 28, HOBBIT),2113 * new TolkienCharacter(&quot;Gimli&quot;, 139, DWARF),2114 * new TolkienCharacter(&quot;Aragorn&quot;, 87, MAN,2115 * new TolkienCharacter(&quot;Boromir&quot;, 37, MAN)2116 * };2117 *2118 * // let's verify 'name' and 'age' of some TolkienCharacter in fellowshipOfTheRing :2119 *2120 * assertThat(fellowshipOfTheRing).extracting(&quot;name&quot;, &quot;age&quot;)2121 * .contains(tuple(&quot;Boromir&quot;, 37),2122 * tuple(&quot;Sam&quot;, 38),2123 * tuple(&quot;Legolas&quot;, 1000));2124 *2125 *2126 * // extract 'name', 'age' and Race name values.2127 *2128 * assertThat(fellowshipOfTheRing).extracting(&quot;name&quot;, &quot;age&quot;, &quot;race.name&quot;)2129 * .contains(tuple(&quot;Boromir&quot;, 37, &quot;Man&quot;),2130 * tuple(&quot;Sam&quot;, 38, &quot;Hobbit&quot;),2131 * tuple(&quot;Legolas&quot;, 1000, &quot;Elf&quot;));</code></pre>2132 *2133 * A property with the given name is looked for first, if it does not exist the a field with the given name is2134 * looked for.2135 * <p>2136 * Note that the order of extracted property/field values is consistent with the iteration order of the array under2137 * test.2138 *2139 * @param propertiesOrFields the properties/fields to extract from the initial array under test2140 * @return a new assertion object whose object under test is the list of Tuple with extracted properties/fields values2141 * as data.2142 * @throws IntrospectionError if one of the given name does not match a field or property in one of the initial2143 * Iterable's element.2144 */2145 @CheckReturnValue2146 public ObjectArrayAssert<Tuple> extracting(String... propertiesOrFields) {2147 Object[] values = FieldsOrPropertiesExtractor.extract(array, byName(propertiesOrFields));2148 Tuple[] result = Arrays.copyOf(values, values.length, Tuple[].class);2149 String extractedDescription = extractedDescriptionOf(propertiesOrFields);2150 String description = mostRelevantDescription(info.description(), extractedDescription);2151 return new ObjectArrayAssert<>(result).as(description);2152 }2153 /**2154 * Extract the values from the array's elements by applying an extracting function on them. The returned2155 * array becomes a new object under test.2156 * <p>2157 * It allows to test values from the elements in safer way than by using {@link #extracting(String)}, as it2158 * doesn't utilize introspection.2159 * <p>2160 * Let's take a look an example:2161 * <pre><code class='java'> // Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class)2162 * // they can be public field or properties, both can be extracted.2163 * AtomicReferenceArray&lt;TolkienCharacter&gt; fellowshipOfTheRing = new AtomicReferenceArray&lt;&gt;(new TolkienCharacter[]{2164 * new TolkienCharacter(&quot;Frodo&quot;, 33, HOBBIT),2165 * new TolkienCharacter(&quot;Sam&quot;, 38, HOBBIT),2166 * new TolkienCharacter(&quot;Gandalf&quot;, 2020, MAIA),2167 * new TolkienCharacter(&quot;Legolas&quot;, 1000, ELF),2168 * new TolkienCharacter(&quot;Pippin&quot;, 28, HOBBIT),2169 * new TolkienCharacter(&quot;Gimli&quot;, 139, DWARF),2170 * new TolkienCharacter(&quot;Aragorn&quot;, 87, MAN,2171 * new TolkienCharacter(&quot;Boromir&quot;, 37, MAN)2172 * };2173 *2174 *2175 * // this extracts the race2176 * Function&lt;TolkienCharacter, Race&gt; race = new Function&lt;TolkienCharacter, Race&gt;() {2177 * {@literal @}Override2178 * public Race extract(TolkienCharacter input) {2179 * return input.getRace();2180 * }2181 * }2182 *2183 * // fellowship has hobbits, right, my presioussss?2184 * assertThat(fellowshipOfTheRing).extracting(race).contains(HOBBIT);</code></pre>2185 *2186 * Note that the order of extracted property/field values is consistent with the iteration order of the Iterable under2187 * test, for example if it's a {@link HashSet}, you won't be able to make any assumptions on the extracted values2188 * order.2189 *2190 * @param <U> the extracted values type2191 * @param extractor the object transforming input object to desired one2192 * @return a new assertion object whose object under test is the list of values extracted2193 * @since 2.7.0 / 3.7.02194 */2195 @CheckReturnValue2196 public <U> ObjectArrayAssert<U> extracting(Function<? super T, U> extractor) {2197 U[] extracted = FieldsOrPropertiesExtractor.extract(array, extractor);2198 return new ObjectArrayAssert<>(extracted);2199 }2200 /**2201 * Extract the values from the array's elements by applying an extracting function (which might throw an2202 * exception) on them. The returned array becomes a new object under test.2203 * <p>2204 * Any checked exception raised in the extractor is rethrown wrapped in a {@link RuntimeException}.2205 * <p>2206 * It allows to test values from the elements in safer way than by using {@link #extracting(String)}, as it2207 * doesn't utilize introspection.2208 * <p>2209 * Let's take a look an example:2210 * <pre><code class='java'> // Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class)2211 * // they can be public field or properties, both can be extracted.2212 * AtomicReferenceArray&lt;TolkienCharacter&gt; fellowshipOfTheRing = new AtomicReferenceArray&lt;&gt;(new TolkienCharacter[]{2213 * new TolkienCharacter(&quot;Frodo&quot;, 33, HOBBIT),2214 * new TolkienCharacter(&quot;Sam&quot;, 38, HOBBIT),2215 * new TolkienCharacter(&quot;Gandalf&quot;, 2020, MAIA),2216 * new TolkienCharacter(&quot;Legolas&quot;, 1000, ELF),2217 * new TolkienCharacter(&quot;Pippin&quot;, 28, HOBBIT),2218 * new TolkienCharacter(&quot;Gimli&quot;, 139, DWARF),2219 * new TolkienCharacter(&quot;Aragorn&quot;, 87, MAN,2220 * new TolkienCharacter(&quot;Boromir&quot;, 37, MAN)2221 * };2222 *2223 * assertThat(fellowshipOfTheRing).extracting(input -&gt; {2224 * if (input.getAge() &lt; 20) {2225 * throw new Exception("age &lt; 20");2226 * }2227 * return input.getName();2228 * }).contains("Frodo");</code></pre>2229 *2230 * Note that the order of extracted property/field values is consistent with the iteration order of the Iterable under2231 * test, for example if it's a {@link HashSet}, you won't be able to make any assumptions on the extracted values2232 * order.2233 *2234 * @param <U> the extracted values type2235 * @param <EXCEPTION> the exception type2236 * @param extractor the object transforming input object to desired one2237 * @return a new assertion object whose object under test is the list of values extracted2238 * @since 3.7.02239 */2240 @CheckReturnValue2241 public <U, EXCEPTION extends Exception> ObjectArrayAssert<U> extracting(ThrowingExtractor<? super T, U, EXCEPTION> extractor) {2242 U[] extracted = FieldsOrPropertiesExtractor.extract(array, extractor);2243 return new ObjectArrayAssert<>(extracted);2244 }2245 /**2246 * Extract the Iterable values from the array's elements by applying an Iterable extracting function on them2247 * and concatenating the result lists into an array which becomes the new object under test.2248 * <p>2249 * It allows testing the results of extracting values that are represented by Iterables.2250 * <p>2251 * For example:2252 * <pre><code class='java'> CartoonCharacter bart = new CartoonCharacter("Bart Simpson");2253 * CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson");2254 * CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson");2255 * CartoonCharacter homer = new CartoonCharacter("Homer Simpson");2256 * homer.addChildren(bart, lisa, maggie);2257 *2258 * CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone");2259 * CartoonCharacter fred = new CartoonCharacter("Fred Flintstone");2260 * fred.getChildren().add(pebbles);2261 *2262 * Function&lt;CartoonCharacter, List&lt;CartoonCharacter&gt;&gt; childrenOf = new Function&lt;CartoonCharacter, List&lt;CartoonCharacter&gt;&gt;() {2263 * {@literal @}Override2264 * public List&lt;CartoonChildren&gt; extract(CartoonCharacter input) {2265 * return input.getChildren();2266 * }2267 * }2268 *2269 * AtomicReferenceArray&lt;CartoonCharacter&gt; parents = new AtomicReferenceArray&lt;&gt;(new CartoonCharacter[]{ homer, fred });2270 * // check children2271 * assertThat(parents).flatExtracting(childrenOf)2272 * .containsOnly(bart, lisa, maggie, pebbles);</code></pre>2273 *2274 * The order of extracted values is consisted with both the order of the collection itself, as well as the extracted2275 * collections.2276 *2277 * @param <U> the type of elements to extract.2278 * @param <C> the type of collection to flat/extract.2279 * @param extractor the object transforming input object to an Iterable of desired ones2280 * @return a new assertion object whose object under test is the list of values extracted2281 * @since 2.7.0 / 3.7.02282 */2283 @CheckReturnValue2284 public <U, C extends Collection<U>> ObjectArrayAssert<U> flatExtracting(Function<? super T, C> extractor) {2285 return doFlatExtracting(extractor);2286 }2287 /**2288 * Extract the Iterable values from the array's elements by applying an Iterable extracting function (which might2289 * throw an exception) on them and concatenating the result lists into an array which becomes the new object under2290 * test.2291 * <p>2292 * It allows testing the results of extracting values that are represented by Iterables.2293 * <p>2294 * For example:2295 * <pre><code class='java'> CartoonCharacter bart = new CartoonCharacter("Bart Simpson");2296 * CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson");2297 * CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson");2298 * CartoonCharacter homer = new CartoonCharacter("Homer Simpson");2299 * homer.addChildren(bart, lisa, maggie);2300 *2301 * CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone");2302 * CartoonCharacter fred = new CartoonCharacter("Fred Flintstone");2303 * fred.getChildren().add(pebbles);2304 *2305 * AtomicReferenceArray&lt;CartoonCharacter&gt; parents = new AtomicReferenceArray&lt;&gt;(new CartoonCharacter[]{ homer, fred });2306 * // check children2307 * assertThat(parents).flatExtracting(input -&gt; {2308 * if (input.getChildren().size() == 0) {2309 * throw new Exception("no children");2310 * }2311 * return input.getChildren();2312 * }).containsOnly(bart, lisa, maggie, pebbles);</code></pre>2313 *2314 * The order of extracted values is consisted with both the order of the collection itself, as well as the extracted2315 * collections.2316 *2317 * @param <U> the type of elements to extract.2318 * @param <C> the type of collection to flat/extract.2319 * @param <EXCEPTION> the exception type2320 * @param extractor the object transforming input object to an Iterable of desired ones2321 * @return a new assertion object whose object under test is the list of values extracted2322 * @since 3.7.02323 */2324 @CheckReturnValue2325 public <U, C extends Collection<U>, EXCEPTION extends Exception> ObjectArrayAssert<U> flatExtracting(ThrowingExtractor<? super T, C, EXCEPTION> extractor) {2326 return doFlatExtracting(extractor);2327 }2328 private <U, C extends Collection<U>> ObjectArrayAssert<U> doFlatExtracting(Function<? super T, C> extractor) {2329 List<U> result = FieldsOrPropertiesExtractor.extract(Arrays.asList(array), extractor).stream()2330 .flatMap(Collection::stream).collect(toList());2331 return new ObjectArrayAssert<>(toArray(result));2332 }2333 /**2334 * Extract from array's elements the Iterable/Array values corresponding to the given property/field name and2335 * concatenate them into a single array becoming the new object under test.2336 * <p>2337 * It allows testing the elements of extracting values that are represented by iterables or arrays.2338 * <p>2339 * For example:2340 * <pre><code class='java'> CartoonCharacter bart = new CartoonCharacter("Bart Simpson");2341 * CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson");2342 * CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson");2343 * CartoonCharacter homer = new CartoonCharacter("Homer Simpson");2344 * homer.addChildren(bart, lisa, maggie);2345 *2346 * CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone");2347 * CartoonCharacter fred = new CartoonCharacter("Fred Flintstone");2348 * fred.getChildren().add(pebbles);2349 *2350 * AtomicReferenceArray&lt;CartoonCharacter&gt; parents = new AtomicReferenceArray&lt;&gt;(new CartoonCharacter[]{ homer, fred });2351 * // check children2352 * assertThat(parents).flatExtracting("children")2353 * .containsOnly(bart, lisa, maggie, pebbles);</code></pre>2354 *2355 * The order of extracted values is consisted with both the order of the collection itself, as well as the extracted2356 * collections.2357 *2358 * @param propertyName the object transforming input object to an Iterable of desired ones2359 * @return a new assertion object whose object under test is the list of values extracted2360 * @throws IllegalArgumentException if one of the extracted property value was not an array or an iterable.2361 * @since 2.7.0 / 3.7.02362 */2363 @CheckReturnValue2364 public ObjectArrayAssert<Object> flatExtracting(String propertyName) {2365 List<Object> extractedValues = newArrayList();2366 List<?> extractedGroups = FieldsOrPropertiesExtractor.extract(Arrays.asList(array), byName(propertyName));2367 for (Object group : extractedGroups) {2368 // expecting AtomicReferenceArray to be an iterable or an array2369 if (isArray(group)) {2370 int size = Array.getLength(group);2371 for (int i = 0; i < size; i++) {2372 extractedValues.add(Array.get(group, i));2373 }2374 } else if (group instanceof Iterable) {2375 Iterable<?> iterable = (Iterable<?>) group;2376 for (Object value : iterable) {2377 extractedValues.add(value);2378 }2379 } else {2380 CommonErrors.wrongElementTypeForFlatExtracting(group);2381 }2382 }2383 return new ObjectArrayAssert<>(extractedValues.toArray());2384 }2385 /**2386 * Extract the result of given method invocation from the array's elements under test into a new array, this new array2387 * becoming the array under test.2388 * <p>2389 * It allows you to test a method results of the array's elements instead of testing the elements themselves, which can be2390 * much less work!2391 * <p>2392 * It is especially useful for classes that does not conform to the Java Bean's getter specification (i.e. public String2393 * toString() or public String status() instead of public String getStatus()).2394 * <p>2395 * Let's take an example to make things clearer :2396 * <pre><code class='java'> // Build a array of WesterosHouse, a WesterosHouse has a method: public String sayTheWords()2397 * AtomicReferenceArray&lt;WesterosHouse&gt; greatHousesOfWesteros = new AtomicReferenceArray&lt;&gt;(new WesterosHouse[]{2398 * new WesterosHouse(&quot;Stark&quot;, &quot;Winter is Coming&quot;),2399 * new WesterosHouse(&quot;Lannister&quot;, &quot;Hear Me Roar!&quot;),2400 * new WesterosHouse(&quot;Greyjoy&quot;, &quot;We Do Not Sow&quot;),2401 * new WesterosHouse(&quot;Baratheon&quot;, &quot;Our is the Fury&quot;),2402 * new WesterosHouse(&quot;Martell&quot;, &quot;Unbowed, Unbent, Unbroken&quot;),2403 * new WesterosHouse(&quot;Tyrell&quot;, &quot;Growing Strong&quot;) });2404 *2405 * // let's verify the words of the great houses of Westeros:2406 * assertThat(greatHousesOfWesteros).extractingResultOf(&quot;sayTheWords&quot;)2407 * .contains(&quot;Winter is Coming&quot;, &quot;We Do Not Sow&quot;, &quot;Hear Me Roar&quot;)2408 * .doesNotContain(&quot;Lannisters always pay their debts&quot;);</code></pre>2409 *2410 * <p>2411 * Following requirements have to be met to extract method results:2412 * <ul>2413 * <li>method has to be public,</li>2414 * <li>method cannot accept any arguments,</li>2415 * <li>method cannot return void.</li>2416 * </ul>2417 * <p>2418 * Note that the order of extracted values is consistent with the order of the array under test.2419 *2420 * @param method the name of the method which result is to be extracted from the array under test2421 * @return a new assertion object whose object under test is the array of extracted values.2422 * @throws IllegalArgumentException if no method exists with the given name, or method is not public, or method does2423 * return void, or method accepts arguments.2424 * @since 2.7.0 / 3.7.02425 */2426 @CheckReturnValue2427 public ObjectArrayAssert<Object> extractingResultOf(String method) {2428 Object[] values = FieldsOrPropertiesExtractor.extract(array, resultOf(method));2429 String extractedDescription = extractedDescriptionOfMethod(method);2430 String description = mostRelevantDescription(info.description(), extractedDescription);2431 return new ObjectArrayAssert<>(values).as(description);2432 }2433 /**2434 * Extract the result of given method invocation from the array's elements under test into a new array, this new array2435 * becoming the array under test.2436 * <p>2437 * It allows you to test a method results of the array's elements instead of testing the elements themselves, which can be2438 * much less work!2439 * <p>2440 * It is especially useful for classes that do not conform to the Java Bean's getter specification (i.e. public String2441 * toString() or public String status() instead of public String getStatus()).2442 * <p>2443 * Let's take an example to make things clearer :2444 * <pre><code class='java'> // Build a array of WesterosHouse, a WesterosHouse has a method: public String sayTheWords()2445 * AtomicReferenceArray&lt;WesterosHouse&gt; greatHousesOfWesteros = new AtomicReferenceArray&lt;&gt;(new WesterosHouse[]{2446 * new WesterosHouse(&quot;Stark&quot;, &quot;Winter is Coming&quot;),2447 * new WesterosHouse(&quot;Lannister&quot;, &quot;Hear Me Roar!&quot;),2448 * new WesterosHouse(&quot;Greyjoy&quot;, &quot;We Do Not Sow&quot;),2449 * new WesterosHouse(&quot;Baratheon&quot;, &quot;Our is the Fury&quot;),2450 * new WesterosHouse(&quot;Martell&quot;, &quot;Unbowed, Unbent, Unbroken&quot;),2451 * new WesterosHouse(&quot;Tyrell&quot;, &quot;Growing Strong&quot;) });2452 *2453 * // let's verify the words of the great houses of Westeros:2454 * assertThat(greatHousesOfWesteros).extractingResultOf(&quot;sayTheWords&quot;, String.class)2455 * .contains(&quot;Winter is Coming&quot;, &quot;We Do Not Sow&quot;, &quot;Hear Me Roar&quot;)2456 * .doesNotContain(&quot;Lannisters always pay their debts&quot;);</code></pre>2457 *2458 * <p>2459 * Following requirements have to be met to extract method results:2460 * <ul>2461 * <li>method has to be public,</li>2462 * <li>method can not accept any arguments,</li>2463 * <li>method can not return void.</li>2464 * </ul>2465 * <p>2466 * Note that the order of extracted values is consistent with the order of the array under test.2467 *2468 * @param <P> the extracted type2469 * @param method the name of the method which result is to be extracted from the array under test2470 * @param extractingType type to return2471 * @return a new assertion object whose object under test is the array of extracted values.2472 * @throws IllegalArgumentException if no method exists with the given name, or method is not public, or method does2473 * return void, or method accepts arguments.2474 * @since 2.7.0 / 3.7.02475 */2476 @CheckReturnValue2477 public <P> ObjectArrayAssert<P> extractingResultOf(String method, Class<P> extractingType) {2478 @SuppressWarnings("unchecked")2479 P[] values = (P[]) FieldsOrPropertiesExtractor.extract(array, resultOf(method));2480 String extractedDescription = extractedDescriptionOfMethod(method);2481 String description = mostRelevantDescription(info.description(), extractedDescription);2482 return new ObjectArrayAssert<>(values).as(description);2483 }2484 /**2485 * Enable hexadecimal object representation of Iterable elements instead of standard java representation in error2486 * messages.2487 * <p>2488 * It can be useful to better understand what the error was with a more meaningful error message.2489 * <p>2490 * Example2491 * <pre><code class='java'>2492 * AtomicReferenceArray&lt;Byte&gt; bytes = new AtomicReferenceArray&lt;&gt;(new Byte[]{ 0x10, 0x20 });2493 * assertThat(bytes).inHexadecimal().contains(new Byte[] { 0x30 });</code></pre>2494 *2495 * With standard error message:2496 * <pre><code class='java'> Expecting:2497 * &lt;[16, 32]&gt;2498 * to contain:2499 * &lt;[48]&gt;2500 * but could not find:2501 * &lt;[48]&gt;</code></pre>2502 *2503 * With Hexadecimal error message:2504 * <pre><code class='java'> Expecting:2505 * &lt;[0x10, 0x20]&gt;2506 * to contain:2507 * &lt;[0x30]&gt;2508 * but could not find:2509 * &lt;[0x30]&gt;</code></pre>2510 *2511 * @return {@code this} assertion object.2512 * @since 2.7.0 / 3.7.02513 */2514 @Override2515 @CheckReturnValue2516 public AtomicReferenceArrayAssert<T> inHexadecimal() {2517 return super.inHexadecimal();2518 }2519 @Override2520 @CheckReturnValue2521 public AtomicReferenceArrayAssert<T> inBinary() {2522 return super.inBinary();2523 }2524 /**2525 * Filter the array under test keeping only elements having a property or field equal to {@code expectedValue}, the2526 * property/field is specified by {@code propertyOrFieldName} parameter.2527 * <p>2528 * The filter first tries to get the value from a property (named {@code propertyOrFieldName}), if no such property2529 * exists it tries to read the value from a field. Reading private fields is supported by default, this can be2530 * globally disabled by calling {@link Assertions#setAllowExtractingPrivateFields(boolean)2531 * Assertions.setAllowExtractingPrivateFields(false)}.2532 * <p>2533 * When reading <b>nested</b> property/field, if an intermediate value is null the whole nested property/field is2534 * considered to be null, thus reading "address.street.name" value will return null if "street" value is null.2535 * <p>2536 *2537 * As an example, let's check all employees 800 years old (yes, special employees):2538 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2539 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2540 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2541 * Employee noname = new Employee(4L, null, 50);2542 *2543 * AtomicReferenceArray&lt;Employee&gt; employees = new AtomicReferenceArray&lt;&gt;(new Employee[]{ yoda, luke, obiwan, noname });2544 *2545 * assertThat(employees).filteredOn("age", 800)2546 * .containsOnly(yoda, obiwan);</code></pre>2547 *2548 * Nested properties/fields are supported:2549 * <pre><code class='java'> // Name is bean class with 'first' and 'last' String properties2550 *2551 * // name is null for noname =&gt; it does not match the filter on "name.first"2552 * assertThat(employees).filteredOn("name.first", "Luke")2553 * .containsOnly(luke);2554 *2555 * assertThat(employees).filteredOn("name.last", "Vader")2556 * .isEmpty();</code></pre>2557 * <p>2558 * If you want to filter on null value, use {@link #filteredOnNull(String)} as Java will resolve the call to2559 * {@link #filteredOn(String, FilterOperator)} instead of this method.2560 * <p>2561 * An {@link IntrospectionError} is thrown if the given propertyOrFieldName can't be found in one of the array2562 * elements.2563 * <p>2564 * You can chain filters:2565 * <pre><code class='java'> // fellowshipOfTheRing is an array of TolkienCharacter having race and name fields2566 * // 'not' filter is statically imported from Assertions.not2567 *2568 * assertThat(fellowshipOfTheRing).filteredOn("race.name", "Man")2569 * .filteredOn("name", not("Boromir"))2570 * .containsOnly(aragorn);</code></pre>2571 * If you need more complex filter, use {@link #filteredOn(Condition)} and provide a {@link Condition} to specify the2572 * filter to apply.2573 *2574 * @param propertyOrFieldName the name of the property or field to read2575 * @param expectedValue the value to compare element's property or field with2576 * @return a new assertion object with the filtered array under test2577 * @throws IllegalArgumentException if the given propertyOrFieldName is {@code null} or empty.2578 * @throws IntrospectionError if the given propertyOrFieldName can't be found in one of the array elements.2579 * @since 2.7.0 / 3.7.02580 */2581 @CheckReturnValue2582 public AtomicReferenceArrayAssert<T> filteredOn(String propertyOrFieldName, Object expectedValue) {2583 return internalFilteredOn(propertyOrFieldName, expectedValue);2584 }2585 /**2586 * Filter the array under test keeping only elements whose property or field specified by {@code propertyOrFieldName}2587 * is null.2588 * <p>2589 * exists it tries to read the value from a field. Reading private fields is supported by default, this can be2590 * globally disabled by calling {@link Assertions#setAllowExtractingPrivateFields(boolean)2591 * Assertions.setAllowExtractingPrivateFields(false)}.2592 * <p>2593 * When reading <b>nested</b> property/field, if an intermediate value is null the whole nested property/field is2594 * considered to be null, thus reading "address.street.name" value will return null if "street" value is null.2595 * <p>2596 * As an example, let's check all employees 800 years old (yes, special employees):2597 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2598 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2599 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2600 * Employee noname = new Employee(4L, null, 50);2601 *2602 * AtomicReferenceArray&lt;Employee&gt; employees = new AtomicReferenceArray&lt;&gt;(new Employee[]{ yoda, luke, obiwan, noname });2603 *2604 * assertThat(employees).filteredOnNull("name")2605 * .containsOnly(noname);</code></pre>2606 *2607 * Nested properties/fields are supported:2608 * <pre><code class='java'> // Name is bean class with 'first' and 'last' String properties2609 *2610 * assertThat(employees).filteredOnNull("name.last")2611 * .containsOnly(yoda, obiwan, noname);</code></pre>2612 *2613 * An {@link IntrospectionError} is thrown if the given propertyOrFieldName can't be found in one of the array2614 * elements.2615 * <p>2616 * If you need more complex filter, use {@link #filteredOn(Condition)} and provide a {@link Condition} to specify the2617 * filter to apply.2618 *2619 * @param propertyOrFieldName the name of the property or field to read2620 * @return a new assertion object with the filtered array under test2621 * @throws IntrospectionError if the given propertyOrFieldName can't be found in one of the array elements.2622 * @since 2.7.0 / 3.7.02623 */2624 @CheckReturnValue2625 public AtomicReferenceArrayAssert<T> filteredOnNull(String propertyOrFieldName) {2626 // call internalFilteredOn to avoid double proxying in soft assertions2627 return internalFilteredOn(propertyOrFieldName, null);2628 }2629 /**2630 * Filter the array under test keeping only elements having a property or field matching the filter expressed with2631 * the {@link FilterOperator}, the property/field is specified by {@code propertyOrFieldName} parameter.2632 * <p>2633 * The existing filters are :2634 * <ul>2635 * <li> {@link Assertions#not(Object) not(Object)}</li>2636 * <li> {@link Assertions#in(Object...) in(Object...)}</li>2637 * <li> {@link Assertions#notIn(Object...) notIn(Object...)}</li>2638 * </ul>2639 * <p>2640 * Whatever filter is applied, it first tries to get the value from a property (named {@code propertyOrFieldName}), if2641 * no such property exists it tries to read the value from a field. Reading private fields is supported by default,2642 * this can be globally disabled by calling {@link Assertions#setAllowExtractingPrivateFields(boolean)2643 * Assertions.setAllowExtractingPrivateFields(false)}.2644 * <p>2645 * When reading <b>nested</b> property/field, if an intermediate value is null the whole nested property/field is2646 * considered to be null, thus reading "address.street.name" value will return null if "street" value is null.2647 * <p>2648 *2649 * As an example, let's check stuff on some special employees :2650 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2651 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2652 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2653 *2654 * AtomicReferenceArray&lt;Employee&gt; employees = new AtomicReferenceArray&lt;&gt;(new Employee[]{ yoda, luke, obiwan, noname });2655 *2656 * // 'not' filter is statically imported from Assertions.not2657 * assertThat(employees).filteredOn("age", not(800))2658 * .containsOnly(luke);2659 *2660 * // 'in' filter is statically imported from Assertions.in2661 * // Name is bean class with 'first' and 'last' String properties2662 * assertThat(employees).filteredOn("name.first", in("Yoda", "Luke"))2663 * .containsOnly(yoda, luke);2664 *2665 * // 'notIn' filter is statically imported from Assertions.notIn2666 * assertThat(employees).filteredOn("name.first", notIn("Yoda", "Luke"))2667 * .containsOnly(obiwan);</code></pre>2668 *2669 * An {@link IntrospectionError} is thrown if the given propertyOrFieldName can't be found in one of the array2670 * elements.2671 * <p>2672 * Note that combining filter operators is not supported, thus the following code is not correct:2673 * <pre><code class='java'> // Combining filter operators like not(in(800)) is NOT supported2674 * // -&gt; throws UnsupportedOperationException2675 * assertThat(employees).filteredOn("age", not(in(800)))2676 * .contains(luke);</code></pre>2677 * <p>2678 * You can chain filters:2679 * <pre><code class='java'> // fellowshipOfTheRing is an array of TolkienCharacter having race and name fields2680 * // 'not' filter is statically imported from Assertions.not2681 *2682 * assertThat(fellowshipOfTheRing).filteredOn("race.name", "Man")2683 * .filteredOn("name", not("Boromir"))2684 * .containsOnly(aragorn);</code></pre>2685 *2686 * If you need more complex filter, use {@link #filteredOn(Condition)} or {@link #filteredOn(Predicate)} and2687 * provide a {@link Condition} or {@link Predicate} to specify the filter to apply.2688 *2689 * @param propertyOrFieldName the name of the property or field to read2690 * @param filterOperator the filter operator to apply2691 * @return a new assertion object with the filtered array under test2692 * @throws IllegalArgumentException if the given propertyOrFieldName is {@code null} or empty.2693 * @since 2.7.0 / 3.7.02694 */2695 @CheckReturnValue2696 public AtomicReferenceArrayAssert<T> filteredOn(String propertyOrFieldName, FilterOperator<?> filterOperator) {2697 checkNotNull(filterOperator);2698 Filters<? extends T> filter = filter(array).with(propertyOrFieldName);2699 filterOperator.applyOn(filter);2700 return new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(toArray(filter.get())));2701 }2702 /**2703 * Filter the array under test keeping only elements matching the given {@link Condition}.2704 * <p>2705 * Let's check old employees whose age &gt; 100:2706 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2707 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2708 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2709 * Employee noname = new Employee(4L, null, 50);2710 *2711 * AtomicReferenceArray&lt;Employee&gt; employees = new AtomicReferenceArray&lt;&gt;(new Employee[]{ yoda, luke, obiwan, noname });2712 *2713 * // old employee condition, "old employees" describes the condition in error message2714 * // you just have to implement 'matches' method2715 * Condition&lt;Employee&gt; oldEmployees = new Condition&lt;Employee&gt;("old employees") {2716 * {@literal @}Override2717 * public boolean matches(Employee employee) {2718 * return employee.getAge() &gt; 100;2719 * }2720 * };2721 * }2722 * assertThat(employees).filteredOn(oldEmployees)2723 * .containsOnly(yoda, obiwan);</code></pre>2724 *2725 * You can combine {@link Condition} with condition operator like {@link Not}:2726 * <pre><code class='java'> // 'not' filter is statically imported from Assertions.not2727 * assertThat(employees).filteredOn(not(oldEmployees))2728 * .contains(luke, noname);</code></pre>2729 *2730 * @param condition the filter condition / predicate2731 * @return a new assertion object with the filtered array under test2732 * @throws IllegalArgumentException if the given condition is {@code null}.2733 * @since 2.7.0 / 3.7.02734 */2735 @CheckReturnValue2736 public AtomicReferenceArrayAssert<T> filteredOn(Condition<? super T> condition) {2737 Iterable<? extends T> filteredIterable = filter(array).being(condition).get();2738 return new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(toArray(filteredIterable)));2739 }2740 /**2741 * Filter the array under test into a list composed of the elements matching the given {@link Predicate},2742 * allowing to perform assertions on the filtered list.2743 * <p>2744 * Example : check old employees whose age &gt; 100:2745 *2746 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2747 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2748 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2749 *2750 * AtomicReferenceArray&lt;Employee&gt; employees = new AtomicReferenceArray&lt;&gt;(new Employee[]{ yoda, luke, obiwan, noname });2751 *2752 * assertThat(employees).filteredOn(employee -&gt; employee.getAge() &gt; 100)2753 * .containsOnly(yoda, obiwan);</code></pre>2754 *2755 * @param predicate the filter predicate2756 * @return a new assertion object with the filtered array under test2757 * @throws IllegalArgumentException if the given predicate is {@code null}.2758 * @since 3.16.02759 */2760 public AtomicReferenceArrayAssert<T> filteredOn(Predicate<? super T> predicate) {2761 return internalFilteredOn(predicate);2762 }2763 /**2764 * Filter the array under test into a list composed of the elements for which the result of the {@code function} is equal to {@code expectedValue}.2765 * <p>2766 * It allows to filter elements in more safe way than by using {@link #filteredOn(String, Object)} as it doesn't utilize introspection.2767 * <p>2768 * As an example, let's check all employees 800 years old (yes, special employees):2769 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);2770 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);2771 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);2772 * Employee noname = new Employee(4L, null, 50);2773 *2774 * AtomicReferenceArray&lt;Employee&gt; employees = new AtomicReferenceArray&lt;&gt;(new Employee[]{ yoda, luke, obiwan, noname });2775 *2776 * assertThat(employees).filteredOn(Employee::getAge, 800)2777 * .containsOnly(yoda, obiwan);2778 *2779 * assertThat(employees).filteredOn(e -&gt; e.getName(), null)2780 * .containsOnly(noname);</code></pre>2781 *2782 * If you need more complex filter, use {@link #filteredOn(Predicate)} or {@link #filteredOn(Condition)}.2783 *2784 * @param <U> result type of the filter function2785 * @param function the filter function2786 * @param expectedValue the expected value of the filter function2787 * @return a new assertion object with the filtered array under test2788 * @throws IllegalArgumentException if the given function is {@code null}.2789 * @since 3.17.02790 */2791 @CheckReturnValue2792 public <U> AtomicReferenceArrayAssert<T> filteredOn(Function<? super T, U> function, U expectedValue) {2793 checkArgument(function != null, "The filter function should not be null");2794 // call internalFilteredOn to avoid double proxying in soft assertions2795 return internalFilteredOn(element -> java.util.Objects.equals(function.apply(element), expectedValue));2796 }2797 /**2798 * Verifies that all elements match the given {@link Predicate}.2799 * <p>2800 * Example :2801 * <pre><code class='java'> AtomicReferenceArray&lt;String&gt; abc = new AtomicReferenceArray&lt;&gt;(new String[] {"a", "b", "c"});2802 * AtomicReferenceArray&lt;String&gt; abcc = new AtomicReferenceArray&lt;&gt;(new String[] {"a", "b", "cc"});2803 *2804 * // assertion will pass2805 * assertThat(abc).allMatch(s -&gt; s.length() == 1);2806 *2807 * // assertion will fail2808 * assertThat(abcc).allMatch(s -&gt; s.length() == 1);</code></pre>2809 *2810 * Note that you can achieve the same result with {@link #are(Condition) are(Condition)} or {@link #have(Condition) have(Condition)}.2811 *2812 * @param predicate the given {@link Predicate}.2813 * @return {@code this} object.2814 * @throws NullPointerException if the given predicate is {@code null}.2815 * @throws AssertionError if an element cannot be cast to T.2816 * @throws AssertionError if one or more elements don't satisfy the given predicate.2817 * @since 3.7.02818 */2819 @Override2820 public AtomicReferenceArrayAssert<T> allMatch(Predicate<? super T> predicate) {2821 iterables.assertAllMatch(info, newArrayList(array), predicate, PredicateDescription.GIVEN);2822 return myself;2823 }2824 /**2825 * Verifies that all the elements of actual's array match the given {@link Predicate}. The predicate description is used2826 * to get an informative error message.2827 * <p>2828 * Example :2829 * <pre><code class='java'> AtomicReferenceArray&lt;String&gt; abc = new AtomicReferenceArray&lt;&gt;(new String[] {"a", "b", "c"});2830 * AtomicReferenceArray&lt;String&gt; abcc = new AtomicReferenceArray&lt;&gt;(new String[] {"a", "b", "cc"});2831 *2832 * // assertion will pass2833 * assertThat(abc).allMatch(s -&gt; s.length() == 1, "length of 1");2834 *2835 * // assertion will fail2836 * assertThat(abcc).allMatch(s -&gt; s.length() == 1, "length of 1");</code></pre>2837 *2838 * The message of the failed assertion would be:2839 * <pre><code class='java'>Expecting all elements of:2840 * &lt;["a", "b", "cc"]&gt;2841 * to match 'length of 1' predicate but this element did not:2842 * &lt;"cc"&gt;</code></pre>2843 *2844 *2845 * @param predicate the given {@link Predicate}.2846 * @param predicateDescription a description of the {@link Predicate} used in the error message2847 * @return {@code this} object.2848 * @throws NullPointerException if the given predicate is {@code null}.2849 * @throws AssertionError if an element cannot be cast to T.2850 * @throws AssertionError if one or more elements don't satisfy the given predicate.2851 * @since 3.7.02852 */2853 @Override2854 public AtomicReferenceArrayAssert<T> allMatch(Predicate<? super T> predicate, String predicateDescription) {2855 iterables.assertAllMatch(info, newArrayList(array), predicate, new PredicateDescription(predicateDescription));2856 return myself;2857 }2858 /**2859 * Verifies that all the elements satisfy given requirements expressed as a {@link Consumer}.2860 * <p>2861 * This is useful to perform a group of assertions on elements.2862 * <p>2863 * Grouping assertions example:2864 * <pre><code class='java'> // myIcelanderFriends is an AtomicReferenceArray&lt;Person&gt;2865 * assertThat(myIcelanderFriends).allSatisfy(person -&gt; {2866 * assertThat(person.getCountry()).isEqualTo("Iceland");2867 * assertThat(person.getPhoneCountryCode()).isEqualTo("+354");2868 * });</code></pre>2869 *2870 * @param requirements the given {@link Consumer}.2871 * @return {@code this} object.2872 * @throws NullPointerException if the given {@link Consumer} is {@code null}.2873 * @throws AssertionError if one or more elements don't satisfy given requirements.2874 * @since 3.7.02875 */2876 @Override2877 public AtomicReferenceArrayAssert<T> allSatisfy(Consumer<? super T> requirements) {2878 iterables.assertAllSatisfy(info, newArrayList(array), requirements);2879 return myself;2880 }2881 /**2882 * Verifies whether any elements match the provided {@link Predicate}.2883 * <p>2884 * Example :2885 * <pre><code class='java'> AtomicReferenceArray&lt;String&gt; abc = new AtomicReferenceArray&lt;&gt;(new String[] {"a", "b", "c"});2886 * AtomicReferenceArray&lt;String&gt; abcc = new AtomicReferenceArray&lt;&gt;(new String[] {"a", "b", "cc"});2887 *2888 * // assertion will pass2889 * assertThat(abc).anyMatch(s -&gt; s.length() == 2);2890 *2891 * // assertion will fail2892 * assertThat(abcc).anyMatch(s -&gt; s.length() &gt; 2);</code></pre>2893 *2894 * Note that you can achieve the same result with {@link #areAtLeastOne(Condition) areAtLeastOne(Condition)}2895 * or {@link #haveAtLeastOne(Condition) haveAtLeastOne(Condition)}.2896 *2897 * @param predicate the given {@link Predicate}.2898 * @return {@code this} object.2899 * @throws NullPointerException if the given predicate is {@code null}.2900 * @throws AssertionError if no elements satisfy the given predicate.2901 * @since 3.9.02902 */2903 @Override2904 public AtomicReferenceArrayAssert<T> anyMatch(Predicate<? super T> predicate) {2905 iterables.assertAnyMatch(info, newArrayList(array), predicate, PredicateDescription.GIVEN);2906 return myself;2907 }2908 /**2909 * Verifies that at least one element satisfies the given requirements expressed as a {@link Consumer}.2910 * <p>2911 * This is useful to check that a group of assertions is verified by (at least) one element.2912 * <p>2913 * If the {@link AtomicReferenceArray} to assert is empty, the assertion will fail.2914 * <p>2915 * Grouping assertions example:2916 * <pre><code class='java'> // myIcelanderFriends is an AtomicReferenceArray&lt;Person&gt;2917 * assertThat(myIcelanderFriends).anySatisfy(person -&gt; {2918 * assertThat(person.getCountry()).isEqualTo("Iceland");2919 * assertThat(person.getPhoneCountryCode()).isEqualTo("+354");2920 * assertThat(person.getSurname()).endsWith("son");2921 * });2922 *2923 * // assertion fails for empty group, whatever the requirements are.2924 * assertThat(emptyArray).anySatisfy($ -&gt; {2925 * assertThat(true).isTrue();2926 * });</code></pre>2927 *2928 * @param requirements the given {@link Consumer}.2929 * @return {@code this} object.2930 * @throws NullPointerException if the given {@link Consumer} is {@code null}.2931 * @throws AssertionError if all elements don't satisfy given requirements.2932 * @since 3.7.02933 */2934 @Override2935 public AtomicReferenceArrayAssert<T> anySatisfy(Consumer<? super T> requirements) {2936 iterables.assertAnySatisfy(info, newArrayList(array), requirements);2937 return myself;2938 }2939 /*2940 * {@inheritDoc}2941 */2942 @Override2943 public AtomicReferenceArrayAssert<T> noneSatisfy(Consumer<? super T> restrictions) {2944 iterables.assertNoneSatisfy(info, newArrayList(array), restrictions);2945 return myself;2946 }2947 /**2948 * Verifies that the actual AtomicReferenceArray contains at least one of the given values.2949 * <p>2950 * Example :2951 * <pre><code class='java'> AtomicReferenceArray&lt;String&gt; abc = new AtomicReferenceArray&lt;&gt;(new String[]{"a", "b", "c"});2952 *2953 * // assertions will pass2954 * assertThat(abc).containsAnyOf("b")2955 * .containsAnyOf("b", "c")2956 * .containsAnyOf("a", "b", "c")2957 * .containsAnyOf("a", "b", "c", "d")2958 * .containsAnyOf("e", "f", "g", "b");2959 *2960 * // assertions will fail2961 * assertThat(abc).containsAnyOf("d");2962 * assertThat(abc).containsAnyOf("d", "e", "f", "g");</code></pre>2963 *2964 * @param values the values whose at least one which is expected to be in the {@code AtomicReferenceArray} under test.2965 * @return {@code this} assertion object.2966 * @throws NullPointerException if the array of values is {@code null}.2967 * @throws IllegalArgumentException if the array of values is empty and the {@code AtomicReferenceArray} under test is not empty.2968 * @throws AssertionError if the {@code AtomicReferenceArray} under test is {@code null}.2969 * @throws AssertionError if the {@code AtomicReferenceArray} under test does not contain any of the given {@code values}.2970 * @since 2.9.0 / 3.9.02971 */2972 @Override2973 public AtomicReferenceArrayAssert<T> containsAnyOf(@SuppressWarnings("unchecked") T... values) {2974 arrays.assertContainsAnyOf(info, array, values);2975 return myself;2976 }2977 /**2978 * Verifies that the actual AtomicReferenceArray contains at least one of the given {@link Iterable} elements.2979 * <p>2980 * Example :2981 * <pre><code class='java'> AtomicReferenceArray&lt;String&gt; abc = new AtomicReferenceArray&lt;&gt;(new String[]{"a", "b", "c"});2982 *2983 * // assertions will pass2984 * assertThat(abc).containsAnyElementsOf(Arrays.asList("b"))2985 * .containsAnyElementsOf(Arrays.asList("b", "c"))2986 * .containsAnyElementsOf(Arrays.asList("a", "b", "c"))2987 * .containsAnyElementsOf(Arrays.asList("a", "b", "c", "d"))2988 * .containsAnyElementsOf(Arrays.asList("e", "f", "g", "b"));2989 *2990 * // assertions will fail2991 * assertThat(abc).containsAnyElementsOf(Arrays.asList("d"));2992 * assertThat(abc).containsAnyElementsOf(Arrays.asList("d", "e", "f", "g"));</code></pre>2993 *2994 * @param iterable the iterable whose at least one element is expected to be in the {@code AtomicReferenceArray} under test.2995 * @return {@code this} assertion object.2996 * @throws NullPointerException if the iterable of expected values is {@code null}.2997 * @throws IllegalArgumentException if the iterable of expected values is empty and the {@code AtomicReferenceArray} under test is not empty.2998 * @throws AssertionError if the {@code AtomicReferenceArray} under test is {@code null}.2999 * @throws AssertionError if the {@code AtomicReferenceArray} under test does not contain any of elements from the given {@code Iterable}.3000 * @since 2.9.0 / 3.9.03001 */3002 @Override3003 public AtomicReferenceArrayAssert<T> containsAnyElementsOf(Iterable<? extends T> iterable) {3004 return containsAnyOf(toArray(iterable));3005 }3006 /**3007 * Verifies that no elements match the given {@link Predicate}.3008 * <p>3009 * Example :3010 * <pre><code class='java'> AtomicReferenceArray&lt;String&gt; abcc = new AtomicReferenceArray&lt;&gt;(new String[]{"a", "b", "cc"});3011 *3012 * // assertion will pass3013 * assertThat(abcc).noneMatch(s -&gt; s.isEmpty());3014 *3015 * // assertion will fail3016 * assertThat(abcc).noneMatch(s -&gt; s.length() == 2);</code></pre>3017 *3018 * Note that you can achieve the same result with {@link #areNot(Condition) areNot(Condition)}3019 * or {@link #doNotHave(Condition) doNotHave(Condition)}.3020 *3021 * @param predicate the given {@link Predicate}.3022 * @return {@code this} object.3023 * @throws NullPointerException if the given predicate is {@code null}.3024 * @throws AssertionError if an element cannot be cast to T.3025 * @throws AssertionError if any element satisfy the given predicate.3026 * @since 3.9.03027 */3028 @Override3029 public AtomicReferenceArrayAssert<T> noneMatch(Predicate<? super T> predicate) {3030 iterables.assertNoneMatch(info, newArrayList(array), predicate, PredicateDescription.GIVEN);3031 return myself;3032 }3033 // lazy init TypeComparators3034 protected TypeComparators getComparatorsByType() {3035 if (comparatorsByType == null) comparatorsByType = defaultTypeComparators();3036 return comparatorsByType;3037 }3038 // lazy init TypeComparators3039 protected TypeComparators getComparatorsForElementPropertyOrFieldTypes() {3040 if (comparatorsForElementPropertyOrFieldTypes == null) comparatorsForElementPropertyOrFieldTypes = defaultTypeComparators();3041 return comparatorsForElementPropertyOrFieldTypes;3042 }3043 private AtomicReferenceArrayAssert<T> internalFilteredOn(String propertyOrFieldName, Object expectedValue) {3044 Iterable<? extends T> filteredIterable = filter(array).with(propertyOrFieldName, expectedValue).get();3045 return new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(toArray(filteredIterable)));3046 }3047 private AtomicReferenceArrayAssert<T> internalFilteredOn(Predicate<? super T> predicate) {3048 checkArgument(predicate != null, "The filter predicate should not be null");3049 List<T> filteredList = stream(array).filter(predicate).collect(toList());3050 return new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(toArray(filteredList)));3051 }3052}...

Full Screen

Full Screen

getComparatorsForElementPropertyOrFieldTypes

Using AI Code Generation

copy

Full Screen

1AtomicReferenceArrayAssert<String> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new String[]{"a", "b", "c"}));2atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();3public List<Comparator<?>> getComparatorsForElementPropertyOrFieldTypes() {4 return comparatorsForElementPropertyOrFieldTypes;5}6public List<Comparator<?>> getComparatorsForElementPropertyOrFieldTypes() {7 return comparatorsForElementPropertyOrFieldTypes;8}9public List<Comparator<?>> getComparatorsForElementPropertyOrFieldTypes() {10 return comparatorsForElementPropertyOrFieldTypes;11}12public List<Comparator<?>> getComparatorsForElementPropertyOrFieldTypes() {13 return comparatorsForElementPropertyOrFieldTypes;14}

Full Screen

Full Screen

getComparatorsForElementPropertyOrFieldTypes

Using AI Code Generation

copy

Full Screen

1AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));2AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();3AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));4AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();5AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));6AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();7AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));8AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();9AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));10AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();11AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));12AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();13AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));14AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();15AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object[]{}));16AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert1 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();17AtomicReferenceArrayAssert<Object> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new Object

Full Screen

Full Screen

getComparatorsForElementPropertyOrFieldTypes

Using AI Code Generation

copy

Full Screen

1AtomicReferenceArrayAssert<String> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<String>(new String[] {"a", "b", "c"});2atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();3AtomicReferenceArrayAssert<Integer> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<Integer>(new Integer[] {1, 2, 3});4atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();5AtomicReferenceArrayAssert<AtomicReferenceArrayAssert> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<AtomicReferenceArrayAssert>(new AtomicReferenceArrayAssert[] {new AtomicReferenceArrayAssert("a"), new AtomicReferenceArrayAssert("b")});6atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();7AtomicReferenceArrayAssert<AtomicReferenceArrayAssert> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<AtomicReferenceArrayAssert>(new AtomicReferenceArrayAssert[] {new AtomicReferenceArrayAssert("a"), new AtomicReferenceArrayAssert("b")});8atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();9AtomicReferenceArrayAssert<AtomicReferenceArrayAssert> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<AtomicReferenceArrayAssert>(new AtomicReferenceArrayAssert[] {new AtomicReferenceArrayAssert("a"), new AtomicReferenceArrayAssert("b")});10atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();11AtomicReferenceArrayAssert<AtomicReferenceArrayAssert> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<AtomicReferenceArrayAssert>(new AtomicReferenceArrayAssert[] {new AtomicReferenceArrayAssert("a"), new AtomicReferenceArrayAssert("b")});12atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes();

Full Screen

Full Screen

getComparatorsForElementPropertyOrFieldTypes

Using AI Code Generation

copy

Full Screen

1AtomicReferenceArrayAssert<String> atomicReferenceArrayAssert = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new String[]{"A", "B"}));2Comparator<String>[] comparators = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes(String.class);3assertThat(comparators).hasSize(1);4assertThat(comparators[0]).isInstanceOf(ComparatorBasedComparisonStrategy.class);5Comparator<String>[] comparators2 = atomicReferenceArrayAssert.getComparatorsForElementPropertyOrFieldTypes(String.class, String.class);6assertThat(comparators2).hasSize(2);7assertThat(comparators2[0]).isInstanceOf(ComparatorBasedComparisonStrategy.class);8assertThat(comparators2[1]).isInstanceOf(ComparatorBasedComparisonStrategy.class);9AtomicReferenceArrayAssert<String> atomicReferenceArrayAssert2 = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new String[]{"A", "B"}));10Comparator<String>[] comparators3 = atomicReferenceArrayAssert2.getComparatorsForElementPropertyOrFieldTypes(String.class, String.class);11assertThat(comparators3).hasSize(2);12assertThat(comparators3[0]).isInstanceOf(ComparatorBasedComparisonStrategy.class);13assertThat(comparators3[1]).isInstanceOf(ComparatorBasedComparisonStrategy.class);14AtomicReferenceArrayAssert<String> atomicReferenceArrayAssert3 = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new String[]{"A", "B"}));15Comparator<String>[] comparators4 = atomicReferenceArrayAssert3.getComparatorsForElementPropertyOrFieldTypes(String.class, String.class);16assertThat(comparators4).hasSize(2);17assertThat(comparators4[0]).isInstanceOf(ComparatorBasedComparisonStrategy.class);18assertThat(comparators4[1]).isInstanceOf(ComparatorBasedComparisonStrategy.class);19AtomicReferenceArrayAssert<String> atomicReferenceArrayAssert4 = new AtomicReferenceArrayAssert<>(new AtomicReferenceArray<>(new String[]{"A", "B"}));

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Assertj automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in AtomicReferenceArrayAssert

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful