How to use entry method of org.assertj.core.api.AssertionsForClassTypes class

Best Assertj code snippet using org.assertj.core.api.AssertionsForClassTypes.entry

Source:CustomAssertJ.java Github

copy

Full Screen

...1076 public static ThrowableTypeAssert<IllegalStateException> assertThatIllegalStateException() {1077 return assertThatExceptionOfType(IllegalStateException.class);1078 }1079 // -------------------------------------------------------------------------------------------------1080 // fail methods : not assertions but here to have a single entry point to all AssertJ features.1081 // -------------------------------------------------------------------------------------------------1082 /**1083 * Sets whether we remove elements related to AssertJ from assertion error stack trace.1084 * <p>1085 * Default is {@value org.assertj.core.configuration.Configuration#REMOVE_ASSERTJ_RELATED_ELEMENTS_FROM_STACK_TRACE}.1086 *1087 * @param removeAssertJRelatedElementsFromStackTrace flag.1088 */1089 public static void setRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace) {1090 Fail.setRemoveAssertJRelatedElementsFromStackTrace(removeAssertJRelatedElementsFromStackTrace);1091 }1092 /**1093 * Throws an {@link AssertionError} with the given message.1094 *1095 * @param <T> dummy return value type1096 * @param failureMessage error message.1097 * @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; fail("boom")));.1098 * @throws AssertionError with the given message.1099 */1100 @CanIgnoreReturnValue1101 public static <T> T fail(String failureMessage) {1102 return Fail.fail(failureMessage);1103 }1104 /**1105 * Throws an {@link AssertionError} with the given message built as {@link String#format(String, Object...)}.1106 *1107 * @param <T> dummy return value type1108 * @param failureMessage error message.1109 * @param args Arguments referenced by the format specifiers in the format string.1110 * @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; fail("b%s", ""oom)));.1111 * @throws AssertionError with the given built message.1112 */1113 @CanIgnoreReturnValue1114 public static <T> T fail(String failureMessage, Object... args) {1115 return Fail.fail(failureMessage, args);1116 }1117 /**1118 * Throws an {@link AssertionError} with the given message and with the {@link Throwable} that caused the failure.1119 * @param <T> dummy return value type1120 * @param failureMessage the description of the failed assertion. It can be {@code null}.1121 * @param realCause cause of the error.1122 * @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; fail("boom", cause)));.1123 * @throws AssertionError with the given message and with the {@link Throwable} that caused the failure.1124 */1125 @CanIgnoreReturnValue1126 public static <T> T fail(String failureMessage, Throwable realCause) {1127 return Fail.fail(failureMessage, realCause);1128 }1129 /**1130 * Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown1131 * but had not been.1132 * <p>1133 * {@link Assertions#shouldHaveThrown(Class)} can be used as a replacement.1134 * <p>1135 * @param <T> dummy return value type1136 * @param throwableClass the Throwable class that was expected to be thrown.1137 * @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; failBecauseExceptionWasNotThrown(IOException.class)));.1138 * @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had1139 * not been.1140 *1141 */1142 @CanIgnoreReturnValue1143 public static <T> T failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass) {1144 return Fail.shouldHaveThrown(throwableClass);1145 }1146 /**1147 * Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown1148 * but had not been.1149 * @param <T> dummy return value type1150 * @param throwableClass the Throwable class that was expected to be thrown.1151 * @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; shouldHaveThrown(IOException.class)));.1152 * @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had1153 * not been.1154 */1155 @CanIgnoreReturnValue1156 public static <T> T shouldHaveThrown(Class<? extends Throwable> throwableClass) {1157 return Fail.shouldHaveThrown(throwableClass);1158 }1159 /**1160 * In error messages, sets the threshold when iterable/array formatting will be on one line (if their String description1161 * is less than this parameter) or it will be formatted with one element per line.1162 * <p>1163 * The following array will be formatted on one line as its length &lt; 80:1164 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice");1165 *1166 * // formatted as:1167 *1168 * ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"]</code></pre>1169 * whereas this array is formatted on multiple lines (one element per line)1170 *1171 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards! (Discworld)");1172 *1173 * // formatted as:1174 *1175 * ["A Game of Thrones",1176 * "The Lord of the Rings",1177 * "Assassin's Apprentice",1178 * "Guards! Guards! (Discworld)"]</code></pre>1179 *1180 * @param maxLengthForSingleLineDescription the maximum length for an iterable/array to be displayed on one line1181 */1182 public static void setMaxLengthForSingleLineDescription(int maxLengthForSingleLineDescription) {1183 StandardRepresentation.setMaxLengthForSingleLineDescription(maxLengthForSingleLineDescription);1184 }1185 /**1186 * In error messages, sets the threshold for how many elements from one iterable/array/map will be included in the1187 * in the description.1188 *1189 * E.q. When this method is called with a value of {@code 3}.1190 * <p>1191 * The following array will be formatted entirely as it's length is &lt;= 3:1192 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice");1193 *1194 * // formatted as:1195 *1196 * ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"]</code></pre>1197 *1198 * whereas this array is formatted only with it's first 3 elements, followed by {@code ...}:1199 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards!");1200 *1201 * // formatted as:1202 *1203 * ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", ...]</code></pre>1204 *1205 * @param maxElementsForPrinting the maximum elements that would be printed from one iterable/array/map1206 * @since 2.6.0 / 3.6.01207 */1208 public static void setMaxElementsForPrinting(int maxElementsForPrinting) {1209 StandardRepresentation.setMaxElementsForPrinting(maxElementsForPrinting);1210 }1211 // ------------------------------------------------------------------------------------------------------1212 // properties methods : not assertions but here to have a single entry point to all AssertJ features.1213 // ------------------------------------------------------------------------------------------------------1214 /**1215 * Only delegate to {@link Properties#extractProperty(String)} so that Assertions offers a full feature entry point1216 * to1217 * all AssertJ features (but you can use {@link Properties} if you prefer).1218 * <p>1219 * Typical usage is to chain <code>extractProperty</code> with <code>from</code> method, see examples below :1220 *1221 * <pre><code class='java'> // extract simple property values having a java standard type (here String)1222 * assertThat(extractProperty(&quot;name&quot;, String.class).from(fellowshipOfTheRing))1223 * .contains(&quot;Boromir&quot;, &quot;Gandalf&quot;, &quot;Frodo&quot;, &quot;Legolas&quot;)1224 * .doesNotContain(&quot;Sauron&quot;, &quot;Elrond&quot;);1225 *1226 * // extracting property works also with user's types (here Race)1227 * assertThat(extractProperty(&quot;race&quot;, String.class).from(fellowshipOfTheRing))1228 * .contains(HOBBIT, ELF).doesNotContain(ORC);1229 *1230 * // extract nested property on Race1231 * assertThat(extractProperty(&quot;race.name&quot;, String.class).from(fellowshipOfTheRing))1232 * .contains(&quot;Hobbit&quot;, &quot;Elf&quot;)1233 * .doesNotContain(&quot;Orc&quot;);</code></pre>1234 * @param <T> the type of value to extract.1235 * @param propertyName the name of the property to be read from the elements of a {@code Iterable}. It may be a nested1236 * property (e.g. "address.street.number").1237 * @param propertyType the type of property to extract1238 * @return the created {@code Properties}.1239 * @throws NullPointerException if the given property name is {@code null}.1240 * @throws IllegalArgumentException if the given property name is empty.1241 */1242 public static <T> Properties<T> extractProperty(String propertyName, Class<T> propertyType) {1243 return Properties.extractProperty(propertyName, propertyType);1244 }1245 /**1246 * Only delegate to {@link Properties#extractProperty(String)} so that Assertions offers a full feature entry point1247 * to1248 * all AssertJ features (but you can use {@link Properties} if you prefer).1249 * <p>1250 * Typical usage is to chain <code>extractProperty</code> with <code>from</code> method, see examples below :1251 *1252 * <pre><code class='java'> // extract simple property values, as no type has been defined the extracted property will be considered as Object1253 * // to define the real property type (here String) use extractProperty(&quot;name&quot;, String.class) instead.1254 * assertThat(extractProperty(&quot;name&quot;).from(fellowshipOfTheRing))1255 * .contains(&quot;Boromir&quot;, &quot;Gandalf&quot;, &quot;Frodo&quot;, &quot;Legolas&quot;)1256 * .doesNotContain(&quot;Sauron&quot;, &quot;Elrond&quot;);1257 *1258 * // extracting property works also with user's types (here Race), even though it will be considered as Object1259 * // to define the real property type (here String) use extractProperty(&quot;name&quot;, Race.class) instead.1260 * assertThat(extractProperty(&quot;race&quot;).from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC);1261 *1262 * // extract nested property on Race1263 * assertThat(extractProperty(&quot;race.name&quot;).from(fellowshipOfTheRing)).contains(&quot;Hobbit&quot;, &quot;Elf&quot;).doesNotContain(&quot;Orc&quot;); </code></pre>1264 *1265 * @param propertyName the name of the property to be read from the elements of a {@code Iterable}. It may be a nested1266 * property (e.g. "address.street.number").1267 * @throws NullPointerException if the given property name is {@code null}.1268 * @throws IllegalArgumentException if the given property name is empty.1269 * @return the created {@code Properties}.1270 */1271 public static Properties<Object> extractProperty(String propertyName) {1272 return Properties.extractProperty(propertyName);1273 }1274 /**1275 * Utility method to build nicely a {@link Tuple} when working with {@link IterableAssert#extracting(String...)} or1276 * {@link ObjectArrayAssert#extracting(String...)}1277 *1278 * @param values the values stored in the {@link Tuple}1279 * @return the built {@link Tuple}1280 */1281 public static Tuple tuple(Object... values) {1282 return Tuple.tuple(values);1283 }1284 /**1285 * Globally sets whether1286 * <code>{@link org.assertj.core.api.AbstractIterableAssert#extracting(String) IterableAssert#extracting(String)}</code>1287 * and1288 * <code>{@link org.assertj.core.api.AbstractObjectArrayAssert#extracting(String) ObjectArrayAssert#extracting(String)}</code>1289 * should be allowed to extract private fields, if not and they try it fails with exception.1290 *1291 * @param allowExtractingPrivateFields allow private fields extraction. Default is {@value org.assertj.core.configuration.Configuration#ALLOW_EXTRACTING_PRIVATE_FIELDS}.1292 */1293 public static void setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields) {1294 FieldSupport.extraction().setAllowUsingPrivateFields(allowExtractingPrivateFields);1295 }1296 /**1297 * Globally sets whether the use of private fields is allowed for comparison.1298 * The following (incomplete) list of methods will be impacted by this change :1299 * <ul>1300 * <li>1301 * <code>{@link org.assertj.core.api.AbstractIterableAssert#usingElementComparatorOnFields(java.lang.String...)}</code>1302 * </li>1303 * <li><code>{@link org.assertj.core.api.AbstractObjectAssert#isEqualToComparingFieldByField(Object)}</code></li>1304 * </ul>1305 *1306 * If the value is <code>false</code> and these methods try to compare private fields, it will fail with an exception.1307 *1308 * @param allowComparingPrivateFields allow private fields comparison. Default is {@value org.assertj.core.configuration.Configuration#ALLOW_COMPARING_PRIVATE_FIELDS}.1309 */1310 public static void setAllowComparingPrivateFields(boolean allowComparingPrivateFields) {1311 FieldSupport.comparison().setAllowUsingPrivateFields(allowComparingPrivateFields);1312 }1313 /**1314 * Globally sets whether the extractor considers bare-named property methods like {@code String name()}.1315 * Defaults to enabled.1316 * @param barenamePropertyMethods whether bare-named property methods are found1317 */1318 public static void setExtractBareNamePropertyMethods(boolean barenamePropertyMethods) {1319 Introspection.setExtractBareNamePropertyMethods(barenamePropertyMethods);1320 }1321 // ------------------------------------------------------------------------------------------------------1322 // Data utility methods : not assertions but here to have a single entry point to all AssertJ features.1323 // ------------------------------------------------------------------------------------------------------1324 /**1325 * Only delegate to {@link MapEntry#entry(Object, Object)} so that Assertions offers a full feature entry point to1326 * all1327 * AssertJ features (but you can use {@link MapEntry} if you prefer).1328 * <p>1329 * Typical usage is to call <code>entry</code> in MapAssert <code>contains</code> assertion, see examples below :1330 *1331 * <pre><code class='java'> Map&lt;Ring, TolkienCharacter&gt; ringBearers = ... // init omitted1332 *1333 * assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));</code></pre>1334 * @param <K> the type of keys in the map.1335 * @param <V> the type of values in the map.1336 * @param key the key of the entry to create.1337 * @param value the value of the entry to create.1338 * @return the created {@code MapEntry}.1339 */1340 public static <K, V> MapEntry<K, V> entry(K key, V value) {1341 return MapEntry.entry(key, value);1342 }1343 /**1344 * Only delegate to {@link Index#atIndex(int)} so that Assertions offers a full feature entry point to all AssertJ1345 * features (but you can use {@link Index} if you prefer).1346 * <p>1347 * Typical usage :1348 * <pre><code class='java'> List&lt;Ring&gt; elvesRings = newArrayList(vilya, nenya, narya);1349 * assertThat(elvesRings).contains(vilya, atIndex(0)).contains(nenya, atIndex(1)).contains(narya, atIndex(2));</code></pre>1350 *1351 * @param index the value of the index.1352 * @return the created {@code Index}.1353 * @throws IllegalArgumentException if the given value is negative.1354 */1355 public static Index atIndex(int index) {1356 return Index.atIndex(index);1357 }1358 /**1359 * Assertions entry point for double {@link Offset}.1360 * <p>1361 * Typical usage :1362 * <pre><code class='java'> assertThat(0.1).isEqualTo(0.0, offset(0.1));</code></pre>1363 * @param value the allowed offset1364 * @return the created {@code Offset}.1365 * @throws NullPointerException if the given value is {@code null}.1366 * @throws IllegalArgumentException if the given value is negative.1367 */1368 public static Offset<Double> offset(Double value) {1369 return Offset.offset(value);1370 }1371 /**1372 * Assertions entry point for float {@link Offset}.1373 * <p>1374 * Typical usage :1375 * <pre><code class='java'> assertThat(0.2f).isCloseTo(0.0f, offset(0.2f));</code></pre>1376 * @param value the allowed offset1377 * @return the created {@code Offset}.1378 * @throws NullPointerException if the given value is {@code null}.1379 * @throws IllegalArgumentException if the given value is negative.1380 */1381 public static Offset<Float> offset(Float value) {1382 return Offset.offset(value);1383 }1384 /**1385 * Alias for {@link #offset(Double)} to use with isCloseTo assertions.1386 * <p>1387 * Typical usage :1388 * <pre><code class='java'> assertThat(0.1).isCloseTo(0.0, within(0.1));</code></pre>1389 * @param value the allowed offset1390 * @return the created {@code Offset}.1391 * @throws NullPointerException if the given value is {@code null}.1392 * @throws IllegalArgumentException if the given value is negative.1393 */1394 public static Offset<Double> within(Double value) {1395 return Offset.offset(value);1396 }1397 /**1398 * Alias for {@link #offset(Double)} to use with real number assertions.1399 * <p>1400 * Typical usage :1401 * <pre><code class='java'> assertThat(0.1).isEqualTo(0.0, withPrecision(0.1));</code></pre>1402 * @param value the required precision1403 * @return the created {@code Offset}.1404 * @throws NullPointerException if the given value is {@code null}.1405 * @throws IllegalArgumentException if the given value is negative.1406 */1407 public static Offset<Double> withPrecision(Double value) {1408 return Offset.offset(value);1409 }1410 /**1411 * Alias for {@link #offset(Float)} to use with isCloseTo assertions.1412 * <p>1413 * Typical usage :1414 * <pre><code class='java'> assertThat(8.2f).isCloseTo(8.0f, within(0.2f));</code></pre>1415 *1416 * @param value the allowed offset1417 * @return the created {@code Offset}.1418 * @throws NullPointerException if the given value is {@code null}.1419 * @throws IllegalArgumentException if the given value is negative.1420 */1421 public static Offset<Float> within(Float value) {1422 return Offset.offset(value);1423 }1424 /**1425 * Alias for {@link #offset(Float)} to use with real number assertions.1426 * <p>1427 * Typical usage :1428 * <pre><code class='java'> assertThat(0.2f).isEqualTo(0.0f, withPrecision(0.2f));</code></pre>1429 * @param value the required precision1430 * @return the created {@code Offset}.1431 * @throws NullPointerException if the given value is {@code null}.1432 * @throws IllegalArgumentException if the given value is negative.1433 */1434 public static Offset<Float> withPrecision(Float value) {1435 return Offset.offset(value);1436 }1437 /**1438 * Assertions entry point for BigDecimal {@link Offset} to use with isCloseTo assertions.1439 * <p>1440 * Typical usage :1441 * <pre><code class='java'> assertThat(BigDecimal.TEN).isCloseTo(new BigDecimal("10.5"), within(BigDecimal.ONE));</code></pre>1442 *1443 * @param value the allowed offset1444 * @return the created {@code Offset}.1445 * @throws NullPointerException if the given value is {@code null}.1446 * @throws IllegalArgumentException if the given value is negative.1447 */1448 public static Offset<BigDecimal> within(BigDecimal value) {1449 return Offset.offset(value);1450 }1451 /**1452 * Assertions entry point for BigInteger {@link Offset} to use with isCloseTo assertions.1453 * <p>1454 * Typical usage :1455 * <pre><code class='java'> assertThat(BigInteger.TEN).isCloseTo(new BigInteger("11"), within(new BigInteger("2")));</code></pre>1456 *1457 * @since 2.7.0 / 3.7.01458 * @param value the allowed offset1459 * @return the created {@code Offset}.1460 * @throws NullPointerException if the given value is {@code null}.1461 * @throws IllegalArgumentException if the given value is negative.1462 * @since 2.7.0 / 3.7.01463 */1464 public static Offset<BigInteger> within(BigInteger value) {1465 return Offset.offset(value);1466 }1467 /**1468 * Assertions entry point for Byte {@link Offset} to use with isCloseTo assertions.1469 * <p>1470 * Typical usage :1471 * <pre><code class='java'> assertThat((byte) 10).isCloseTo((byte) 11, within((byte) 1));</code></pre>1472 *1473 * @param value the value of the offset.1474 * @return the created {@code Offset}.1475 * @throws NullPointerException if the given value is {@code null}.1476 * @throws IllegalArgumentException if the given value is negative.1477 */1478 public static Offset<Byte> within(Byte value) {1479 return Offset.offset(value);1480 }1481 /**1482 * Assertions entry point for Integer {@link Offset} to use with isCloseTo assertions.1483 * <p>1484 * Typical usage :1485 * <pre><code class='java'> assertThat(10).isCloseTo(11, within(1));</code></pre>1486 *1487 * @param value the value of the offset.1488 * @return the created {@code Offset}.1489 * @throws NullPointerException if the given value is {@code null}.1490 * @throws IllegalArgumentException if the given value is negative.1491 */1492 public static Offset<Integer> within(Integer value) {1493 return Offset.offset(value);1494 }1495 /**1496 * Assertions entry point for Short {@link Offset} to use with isCloseTo assertions.1497 * <p>1498 * Typical usage :1499 * <pre><code class='java'> assertThat(10).isCloseTo(11, within(1));</code></pre>1500 *1501 * @param value the allowed offset1502 * @return the created {@code Offset}.1503 * @throws NullPointerException if the given value is {@code null}.1504 * @throws IllegalArgumentException if the given value is negative.1505 */1506 public static Offset<Short> within(Short value) {1507 return Offset.offset(value);1508 }1509 /**1510 * Assertions entry point for Long {@link Offset} to use with {@link AbstractLongAssert#isCloseTo(long, Offset) isCloseTo} assertions.1511 * <p>1512 * Typical usage :1513 * <pre><code class='java'> assertThat(5l).isCloseTo(7l, within(2l));</code></pre>1514 *1515 * @param value the allowed offset1516 * @return the created {@code Offset}.1517 * @throws NullPointerException if the given value is {@code null}.1518 * @throws IllegalArgumentException if the given value is negative.1519 */1520 public static Offset<Long> within(Long value) {1521 return Offset.offset(value);1522 }1523 /**1524 * Assertions entry point for {@link TemporalUnitOffset} with with less than or equal condition1525 * to use with isCloseTo temporal assertions.1526 * <p>1527 * Typical usage :1528 * <pre><code class='java'> LocalTime _07_10 = LocalTime.of(7, 10);1529 * LocalTime _07_12 = LocalTime.of(7, 12);1530 * assertThat(_07_10).isCloseTo(_07_12, within(5, ChronoUnit.MINUTES));</code></pre>1531 *1532 * @param value the allowed offset1533 * @param unit the {@link TemporalUnit} of the offset1534 * @return the created {@code Offset}.1535 * @since 3.7.01536 */1537 public static TemporalUnitOffset within(long value, TemporalUnit unit) {1538 return new TemporalUnitWithinOffset(value, unit);1539 }1540 /**1541 * Assertions entry point for Double {@link org.assertj.core.data.Percentage} to use with isCloseTo assertions for1542 * percentages.1543 * <p>1544 * Typical usage :1545 * <pre><code class='java'> assertThat(11.0).isCloseTo(10.0, withinPercentage(10.0));</code></pre>1546 *1547 * @param value the required precision percentage1548 * @return the created {@code Percentage}.1549 * @throws NullPointerException if the given value is {@code null}.1550 * @throws IllegalArgumentException if the given value is negative.1551 */1552 public static Percentage withinPercentage(Double value) {1553 return withPercentage(value);1554 }1555 /**1556 * Assertions entry point for Integer {@link org.assertj.core.data.Percentage} to use with isCloseTo assertions for1557 * percentages.1558 * <p>1559 * Typical usage :1560 * <pre><code class='java'> assertThat(11).isCloseTo(10, withinPercentage(10));</code></pre>1561 *1562 * @param value the required precision percentage1563 * @return the created {@code Percentage}.1564 * @throws NullPointerException if the given value is {@code null}.1565 * @throws IllegalArgumentException if the given value is negative.1566 */1567 public static Percentage withinPercentage(Integer value) {1568 return withPercentage(value);1569 }1570 /**1571 * Assertions entry point for Long {@link org.assertj.core.data.Percentage} to use with isCloseTo assertions for1572 * percentages.1573 * <p>1574 * Typical usage :1575 * <pre><code class='java'> assertThat(11L).isCloseTo(10L, withinPercentage(10L));</code></pre>1576 *1577 * @param value the required precision percentage1578 * @return the created {@code Percentage}.1579 * @throws NullPointerException if the given value is {@code null}.1580 * @throws IllegalArgumentException if the given value is negative.1581 */1582 public static Percentage withinPercentage(Long value) {1583 return withPercentage(value);1584 }1585 /**1586 * Build a {@link Offset#strictOffset(Number) <b>strict</b> Offset} to use with {@link AbstractDoubleAssert#isCloseTo(double, Offset)} and {@link AbstractDoubleAssert#isNotCloseTo(double, Offset)} assertions.1587 * <p>1588 * A strict offset implies a strict comparison which means that {@code isCloseTo} will fail when <i>abs(actual - expected) == offset</i>.1589 * <p>1590 * Examples:1591 * <pre><code class='java'> // assertion succeeds1592 * assertThat(8.1).isCloseTo(8.0, byLessThan(0.2));1593 *1594 * // assertions fail1595 * assertThat(8.1).isCloseTo(8.0, byLessThan(0.1)); // strict comparison!1596 * assertThat(8.1).isCloseTo(8.0, byLessThan(0.01));</code></pre>1597 *1598 * @param value the value of the offset.1599 * @return the created {@code Offset}.1600 * @throws NullPointerException if the given value is {@code null}.1601 * @throws IllegalArgumentException if the given value is negative.1602 */1603 public static Offset<Double> byLessThan(Double value) {1604 return Offset.strictOffset(value);1605 }1606 /**1607 * Alias for {@link #offset(Float)} to use with isCloseTo assertions.1608 * <p>1609 * Typical usage :1610 * <pre><code class='java'> assertThat(8.2f).isCloseTo(8.0f, byLessThan(0.5f));</code></pre>1611 *1612 * @param value the value of the offset.1613 * @return the created {@code Offset}.1614 * @throws NullPointerException if the given value is {@code null}.1615 * @throws IllegalArgumentException if the given value is negative.1616 */1617 public static Offset<Float> byLessThan(Float value) {1618 return Offset.strictOffset(value);1619 }1620 /**1621 * Assertions entry point for BigDecimal {@link Offset} to use with isCloseTo assertions.1622 * <p>1623 * Typical usage :1624 * <pre><code class='java'> assertThat(BigDecimal.TEN).isCloseTo(new BigDecimal("10.5"), byLessThan(BigDecimal.ONE));</code></pre>1625 *1626 * @param value the value of the offset.1627 * @return the created {@code Offset}.1628 * @throws NullPointerException if the given value is {@code null}.1629 * @throws IllegalArgumentException if the given value is negative.1630 */1631 public static Offset<BigDecimal> byLessThan(BigDecimal value) {1632 return Offset.strictOffset(value);1633 }1634 /**1635 * Assertions entry point for BigInteger {@link Offset} to use with isCloseTo assertions.1636 * <p>1637 * Typical usage :1638 * <pre><code class='java'> assertThat(BigInteger.TEN).isCloseTo(new BigInteger("11"), byLessThan(new BigInteger("2")));</code></pre>1639 *1640 * @param value the value of the offset.1641 * @return the created {@code Offset}.1642 * @throws NullPointerException if the given value is {@code null}.1643 * @throws IllegalArgumentException if the given value is negative.1644 * @since 2.7.0 / 3.7.01645 */1646 public static Offset<BigInteger> byLessThan(BigInteger value) {1647 return Offset.strictOffset(value);1648 }1649 /**1650 * Assertions entry point for Byte {@link Offset} to use with isCloseTo assertions.1651 * <p>1652 * Typical usage :1653 * <pre><code class='java'> assertThat((byte) 10).isCloseTo((byte) 11, byLessThan((byte) 2));</code></pre>1654 *1655 * @param value the value of the offset.1656 * @return the created {@code Offset}.1657 * @throws NullPointerException if the given value is {@code null}.1658 * @throws IllegalArgumentException if the given value is negative.1659 */1660 public static Offset<Byte> byLessThan(Byte value) {1661 return Offset.strictOffset(value);1662 }1663 /**1664 * Assertions entry point for Long {@link Offset} to use with strict {@link AbstractIntegerAssert#isCloseTo(int, Offset) isCloseTo} assertions.1665 * <p>1666 * Typical usage :1667 * <pre><code class='java'> assertThat(10).isCloseTo(12, byLessThan(1));</code></pre>1668 *1669 * @param value the value of the offset.1670 * @return the created {@code Offset}.1671 * @throws NullPointerException if the given value is {@code null}.1672 * @throws IllegalArgumentException if the given value is negative.1673 */1674 public static Offset<Integer> byLessThan(Integer value) {1675 return Offset.strictOffset(value);1676 }1677 /**1678 * Assertions entry point for Short {@link Offset} to use with isCloseTo assertions.1679 * <p>1680 * Typical usage :1681 * <pre><code class='java'> assertThat((short) 10).isCloseTo((short) 11, byLessThan((short) 2));</code></pre>1682 *1683 * @param value the value of the offset.1684 * @return the created {@code Offset}.1685 * @throws NullPointerException if the given value is {@code null}.1686 * @throws IllegalArgumentException if the given value is negative.1687 */1688 public static Offset<Short> byLessThan(Short value) {1689 return Offset.strictOffset(value);1690 }1691 /**1692 * Assertions entry point for Long {@link Offset} to use with strict {@link AbstractLongAssert#isCloseTo(long, Offset) isCloseTo} assertions.1693 * <p>1694 * Typical usage :1695 * <pre><code class='java'> assertThat(5l).isCloseTo(7l, byLessThan(3l));</code></pre>1696 *1697 * @param value the value of the offset.1698 * @return the created {@code Offset}.1699 * @throws NullPointerException if the given value is {@code null}.1700 * @throws IllegalArgumentException if the given value is negative.1701 */1702 public static Offset<Long> byLessThan(Long value) {1703 return Offset.strictOffset(value);1704 }1705 /**1706 * Assertions entry point for {@link TemporalUnitOffset} with strict less than condition1707 * to use with {@code isCloseTo} temporal assertions.1708 * <p>1709 * Typical usage :1710 * <pre><code class='java'> LocalTime _07_10 = LocalTime.of(7, 10);1711 * LocalTime _07_12 = LocalTime.of(7, 12);1712 * assertThat(_07_10).isCloseTo(_07_12, byLessThan(5, ChronoUnit.MINUTES));</code></pre>1713 *1714 * @param value the value of the offset.1715 * @param unit the {@link TemporalUnit} of the offset.1716 * @return the created {@code Offset}.1717 * @since 3.7.01718 */1719 public static TemporalUnitOffset byLessThan(long value, TemporalUnit unit) {1720 return new TemporalUnitLessThanOffset(value, unit);1721 }1722 /**1723 * A syntax sugar to write fluent assertion using {@link ObjectAssert#returns(Object, Function)}.1724 * <p>1725 * Example:1726 * <pre><code class="java"> Jedi yoda = new Jedi("Yoda", "Green");1727 * assertThat(yoda).returns("Yoda", from(Jedi::getName))1728 * .returns(2.4, from(Jedi::getHeight))1729 * .returns(150, from(Jedi::getWeight)); </code></pre>1730 *1731 * @param extractor A function to extract test subject's property1732 * @param <F> Type of test subject1733 * @param <T> Type of the property under the assertion1734 * @return same instance of {@code extractor}1735 */1736 public static <F, T> Function<F, T> from(Function<F, T> extractor) {1737 return extractor;1738 }1739 /**1740 * A syntax sugar to write fluent assertion with methods having an {@link InstanceOfAssertFactory} parameter.1741 * <p>1742 * Example:1743 * <pre><code class="java"> Jedi yoda = new Jedi("Yoda", "Green");1744 * assertThat(yoda).extracting(Jedi::getName, as(InstanceOfAssertFactories.STRING))1745 * .startsWith("Yo");</code></pre>1746 *1747 * @param assertFactory the factory which verifies the type and creates the new {@code Assert}1748 * @param <T> the type to use for the cast.1749 * @param <ASSERT> the type of the resulting {@code Assert}1750 * @return same instance of {@code assertFactory}1751 *1752 * @since 3.14.01753 * @see AbstractObjectAssert#extracting(String, InstanceOfAssertFactory)1754 * @see AbstractObjectAssert#extracting(Function, InstanceOfAssertFactory)1755 * @see AbstractMapAssert#extractingByKey(Object, InstanceOfAssertFactory)1756 * @see AbstractOptionalAssert#get(InstanceOfAssertFactory)1757 * @see AbstractIterableAssert#first(InstanceOfAssertFactory)1758 * @see AbstractIterableAssert#last(InstanceOfAssertFactory)1759 * @see AbstractIterableAssert#element(int, InstanceOfAssertFactory)1760 */1761 public static <T, ASSERT extends AbstractAssert<?, ?>> InstanceOfAssertFactory<T, ASSERT> as(InstanceOfAssertFactory<T, ASSERT> assertFactory) {1762 return assertFactory;1763 }1764 // ------------------------------------------------------------------------------------------------------1765 // Condition methods : not assertions but here to have a single entry point to all AssertJ features.1766 // ------------------------------------------------------------------------------------------------------1767 /**1768 * Creates a new <code>{@link AllOf}</code>1769 *1770 * @param <T> the type of object the given condition accept.1771 * @param conditions the conditions to evaluate.1772 * @return the created {@code AllOf}.1773 * @throws NullPointerException if the given array is {@code null}.1774 * @throws NullPointerException if any of the elements in the given array is {@code null}.1775 */1776 @SafeVarargs1777 public static <T> Condition<T> allOf(Condition<? super T>... conditions) {1778 return AllOf.allOf(conditions);1779 }1780 /**1781 * Creates a new <code>{@link AllOf}</code>1782 *1783 * @param <T> the type of object the given condition accept.1784 * @param conditions the conditions to evaluate.1785 * @return the created {@code AllOf}.1786 * @throws NullPointerException if the given iterable is {@code null}.1787 * @throws NullPointerException if any of the elements in the given iterable is {@code null}.1788 */1789 public static <T> Condition<T> allOf(Iterable<? extends Condition<? super T>> conditions) {1790 return AllOf.allOf(conditions);1791 }1792 /**1793 * Only delegate to {@link AnyOf#anyOf(Condition...)} so that Assertions offers a full feature entry point to all1794 * AssertJ features (but you can use {@link AnyOf} if you prefer).1795 * <p>1796 * Typical usage (<code>jedi</code> and <code>sith</code> are {@link Condition}) :1797 *1798 * <pre><code class='java'> assertThat(&quot;Vader&quot;).is(anyOf(jedi, sith));</code></pre>1799 *1800 * @param <T> the type of object the given condition accept.1801 * @param conditions the conditions to evaluate.1802 * @return the created {@code AnyOf}.1803 */1804 @SafeVarargs1805 public static <T> Condition<T> anyOf(Condition<? super T>... conditions) {1806 return AnyOf.anyOf(conditions);1807 }1808 /**1809 * Creates a new <code>{@link AnyOf}</code>1810 *1811 * @param <T> the type of object the given condition accept.1812 * @param conditions the conditions to evaluate.1813 * @return the created {@code AnyOf}.1814 * @throws NullPointerException if the given iterable is {@code null}.1815 * @throws NullPointerException if any of the elements in the given iterable is {@code null}.1816 */1817 public static <T> Condition<T> anyOf(Iterable<? extends Condition<? super T>> conditions) {1818 return AnyOf.anyOf(conditions);1819 }1820 /**1821 * Creates a new <code>{@link DoesNotHave}</code>.1822 *1823 * @param <T> the type of object the given condition accept.1824 * @param condition the condition to inverse.1825 * @return The DoesNotHave condition created.1826 */1827 public static <T> DoesNotHave<T> doesNotHave(Condition<? super T> condition) {1828 return DoesNotHave.doesNotHave(condition);1829 }1830 /**1831 * Creates a new <code>{@link Not}</code>.1832 *1833 * @param <T> the type of object the given condition accept.1834 * @param condition the condition to inverse.1835 * @return The Not condition created.1836 */1837 public static <T> Not<T> not(Condition<? super T> condition) {1838 return Not.not(condition);1839 }1840 // --------------------------------------------------------------------------------------------------1841 // Filter methods : not assertions but here to have a single entry point to all AssertJ features.1842 // --------------------------------------------------------------------------------------------------1843 /**1844 * Only delegate to {@link Filters#filter(Object[])} so that Assertions offers a full feature entry point to all1845 * AssertJ features (but you can use {@link Filters} if you prefer).1846 * <p>1847 * Note that the given array is not modified, the filters are performed on an {@link Iterable} copy of the array.1848 * <p>1849 * Typical usage with {@link Condition} :1850 *1851 * <pre><code class='java'> assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);</code></pre>1852 * <p>1853 * and with filter language based on java bean property :1854 *1855 * <pre><code class='java'> assertThat(filter(players).with(&quot;pointsPerGame&quot;).greaterThan(20).and(&quot;assistsPerGame&quot;).greaterThan(7).get())1856 * .containsOnly(james, rose);</code></pre>1857 *1858 * @param <E> the array elements type.1859 * @param array the array to filter.1860 * @return the created <code>{@link Filters}</code>.1861 */1862 public static <E> Filters<E> filter(E[] array) {1863 return Filters.filter(array);1864 }1865 /**1866 * Only delegate to {@link Filters#filter(Object[])} so that Assertions offers a full feature entry point to all1867 * AssertJ features (but you can use {@link Filters} if you prefer).1868 * <p>1869 * Note that the given {@link Iterable} is not modified, the filters are performed on a copy.1870 * <p>1871 * Typical usage with {@link Condition} :1872 *1873 * <pre><code class='java'> assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);</code></pre>1874 * <p>1875 * and with filter language based on java bean property :1876 *1877 * <pre><code class='java'> assertThat(filter(players).with(&quot;pointsPerGame&quot;).greaterThan(20)1878 * .and(&quot;assistsPerGame&quot;).greaterThan(7).get())1879 * .containsOnly(james, rose);</code></pre>1880 *1881 * @param <E> the {@link Iterable} elements type.1882 * @param iterableToFilter the {@code Iterable} to filter.1883 * @return the created <code>{@link Filters}</code>.1884 */1885 public static <E> Filters<E> filter(Iterable<E> iterableToFilter) {1886 return Filters.filter(iterableToFilter);1887 }1888 /**1889 * Create a {@link FilterOperator} to use in {@link AbstractIterableAssert#filteredOn(String, FilterOperator)1890 * filteredOn(String, FilterOperation)} to express a filter keeping all Iterable elements whose property/field1891 * value matches one of the given values.1892 * <p>1893 * As often, an example helps:1894 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);1895 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);1896 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);1897 * Employee noname = new Employee(4L, null, 50);1898 *1899 * List&lt;Employee&gt; employees = newArrayList(yoda, luke, obiwan, noname);1900 *1901 * assertThat(employees).filteredOn("age", in(800, 26))1902 * .containsOnly(yoda, obiwan, luke);</code></pre>1903 *1904 * @param values values to match (one match is sufficient)1905 * @return the created "in" filter1906 */1907 public static InFilter in(Object... values) {1908 return InFilter.in(values);1909 }1910 /**1911 * Create a {@link FilterOperator} to use in {@link AbstractIterableAssert#filteredOn(String, FilterOperator)1912 * filteredOn(String, FilterOperation)} to express a filter keeping all Iterable elements whose property/field1913 * value matches does not match any of the given values.1914 * <p>1915 * As often, an example helps:1916 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);1917 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);1918 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);1919 * Employee noname = new Employee(4L, null, 50);1920 *1921 * List&lt;Employee&gt; employees = newArrayList(yoda, luke, obiwan, noname);1922 *1923 * assertThat(employees).filteredOn("age", notIn(800, 50))1924 * .containsOnly(luke);</code></pre>1925 *1926 * @param valuesNotToMatch values not to match (none of the values must match)1927 * @return the created "not in" filter1928 */1929 public static NotInFilter notIn(Object... valuesNotToMatch) {1930 return NotInFilter.notIn(valuesNotToMatch);1931 }1932 /**1933 * Create a {@link FilterOperator} to use in {@link AbstractIterableAssert#filteredOn(String, FilterOperator)1934 * filteredOn(String, FilterOperation)} to express a filter keeping all Iterable elements whose property/field1935 * value matches does not match the given value.1936 * <p>1937 * As often, an example helps:1938 * <pre><code class='java'> Employee yoda = new Employee(1L, new Name("Yoda"), 800);1939 * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);1940 * Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);1941 * Employee noname = new Employee(4L, null, 50);1942 *1943 * List&lt;Employee&gt; employees = newArrayList(yoda, luke, obiwan, noname);1944 *1945 * assertThat(employees).filteredOn("age", not(800))1946 * .containsOnly(luke, noname);</code></pre>1947 *1948 * @param valueNotToMatch the value not to match1949 * @return the created "not" filter1950 */1951 public static NotFilter not(Object valueNotToMatch) {1952 return NotFilter.not(valueNotToMatch);1953 }1954 // --------------------------------------------------------------------------------------------------1955 // File methods : not assertions but here to have a single entry point to all AssertJ features.1956 // --------------------------------------------------------------------------------------------------1957 /**1958 * Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.1959 * <p>1960 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative1961 * with {@link #assertThat(File)}.1962 * </p>1963 *1964 * @param file the file.1965 * @param charset the character set to use.1966 * @return the content of the file.1967 * @throws NullPointerException if the given charset is {@code null}.1968 * @throws UncheckedIOException if an I/O exception occurs.1969 */1970 public static String contentOf(File file, Charset charset) {1971 return Files.contentOf(file, charset);1972 }1973 /**1974 * Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.1975 * <p>1976 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative1977 * with {@link #assertThat(File)}.1978 * </p>1979 *1980 * @param file the file.1981 * @param charsetName the name of the character set to use.1982 * @return the content of the file.1983 * @throws IllegalArgumentException if the given character set is not supported on this platform.1984 * @throws UncheckedIOException if an I/O exception occurs.1985 */1986 public static String contentOf(File file, String charsetName) {1987 return Files.contentOf(file, charsetName);1988 }1989 /**1990 * Loads the text content of a file with the default character set, so that it can be passed to1991 * {@link #assertThat(String)}.1992 * <p>1993 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative1994 * with {@link #assertThat(File)}.1995 * </p>1996 *1997 * @param file the file.1998 * @return the content of the file.1999 * @throws UncheckedIOException if an I/O exception occurs.2000 */2001 public static String contentOf(File file) {2002 return Files.contentOf(file, Charset.defaultCharset());2003 }2004 /**2005 * Loads the text content of a file into a list of strings with the default charset, each string corresponding to a2006 * line.2007 * The line endings are either \n, \r or \r\n.2008 *2009 * @param file the file.2010 * @return the content of the file.2011 * @throws NullPointerException if the given charset is {@code null}.2012 * @throws UncheckedIOException if an I/O exception occurs.2013 */2014 public static List<String> linesOf(File file) {2015 return Files.linesOf(file, Charset.defaultCharset());2016 }2017 /**2018 * Loads the text content of a file into a list of strings, each string corresponding to a line.2019 * The line endings are either \n, \r or \r\n.2020 *2021 * @param file the file.2022 * @param charset the character set to use.2023 * @return the content of the file.2024 * @throws NullPointerException if the given charset is {@code null}.2025 * @throws UncheckedIOException if an I/O exception occurs.2026 */2027 public static List<String> linesOf(File file, Charset charset) {2028 return Files.linesOf(file, charset);2029 }2030 /**2031 * Loads the text content of a file into a list of strings, each string corresponding to a line. The line endings are2032 * either \n, \r or \r\n.2033 *2034 * @param file the file.2035 * @param charsetName the name of the character set to use.2036 * @return the content of the file.2037 * @throws NullPointerException if the given charset is {@code null}.2038 * @throws UncheckedIOException if an I/O exception occurs.2039 */2040 public static List<String> linesOf(File file, String charsetName) {2041 return Files.linesOf(file, charsetName);2042 }2043 // --------------------------------------------------------------------------------------------------2044 // URL/Resource methods : not assertions but here to have a single entry point to all AssertJ features.2045 // --------------------------------------------------------------------------------------------------2046 /**2047 * Loads the text content of a URL, so that it can be passed to {@link #assertThat(String)}.2048 * <p>2049 * Note that this will load the entire contents in memory.2050 * </p>2051 *2052 * @param url the URL.2053 * @param charset the character set to use.2054 * @return the content of the URL.2055 * @throws NullPointerException if the given charset is {@code null}.2056 * @throws UncheckedIOException if an I/O exception occurs.2057 */2058 public static String contentOf(URL url, Charset charset) {2059 return URLs.contentOf(url, charset);2060 }2061 /**2062 * Loads the text content of a URL, so that it can be passed to {@link #assertThat(String)}.2063 * <p>2064 * Note that this will load the entire contents in memory.2065 * </p>2066 *2067 * @param url the URL.2068 * @param charsetName the name of the character set to use.2069 * @return the content of the URL.2070 * @throws IllegalArgumentException if the given character set is not supported on this platform.2071 * @throws UncheckedIOException if an I/O exception occurs.2072 */2073 public static String contentOf(URL url, String charsetName) {2074 return URLs.contentOf(url, charsetName);2075 }2076 /**2077 * Loads the text content of a URL with the default character set, so that it can be passed to2078 * {@link #assertThat(String)}.2079 * <p>2080 * Note that this will load the entire file in memory; for larger files.2081 * </p>2082 *2083 * @param url the URL.2084 * @return the content of the file.2085 * @throws UncheckedIOException if an I/O exception occurs.2086 */2087 public static String contentOf(URL url) {2088 return URLs.contentOf(url, Charset.defaultCharset());2089 }2090 /**2091 * Loads the text content of a URL into a list of strings with the default charset, each string corresponding to a2092 * line.2093 * The line endings are either \n, \r or \r\n.2094 *2095 * @param url the URL.2096 * @return the content of the file.2097 * @throws NullPointerException if the given charset is {@code null}.2098 * @throws UncheckedIOException if an I/O exception occurs.2099 */2100 public static List<String> linesOf(URL url) {2101 return URLs.linesOf(url, Charset.defaultCharset());2102 }2103 /**2104 * Loads the text content of a URL into a list of strings, each string corresponding to a line.2105 * The line endings are either \n, \r or \r\n.2106 *2107 * @param url the URL.2108 * @param charset the character set to use.2109 * @return the content of the file.2110 * @throws NullPointerException if the given charset is {@code null}.2111 * @throws UncheckedIOException if an I/O exception occurs.2112 */2113 public static List<String> linesOf(URL url, Charset charset) {2114 return URLs.linesOf(url, charset);2115 }2116 /**2117 * Loads the text content of a URL into a list of strings, each string corresponding to a line. The line endings are2118 * either \n, \r or \r\n.2119 *2120 * @param url the URL.2121 * @param charsetName the name of the character set to use.2122 * @return the content of the file.2123 * @throws NullPointerException if the given charset is {@code null}.2124 * @throws UncheckedIOException if an I/O exception occurs.2125 */2126 public static List<String> linesOf(URL url, String charsetName) {2127 return URLs.linesOf(url, charsetName);2128 }2129 // --------------------------------------------------------------------------------------------------2130 // Date formatting methods : not assertions but here to have a single entry point to all AssertJ features.2131 // --------------------------------------------------------------------------------------------------2132 /**2133 * Instead of using default strict date/time parsing, it is possible to use lenient parsing mode for default date2134 * formats parser to interpret inputs that do not precisely match supported date formats (lenient parsing).2135 * <p>2136 * With strict parsing, inputs must match exactly date/time format.2137 *2138 * <p>2139 * Example:2140 * <pre><code class='java'> final Date date = Dates.parse("2001-02-03");2141 * final Date dateTime = parseDatetime("2001-02-03T04:05:06");2142 * final Date dateTimeWithMs = parseDatetimeWithMs("2001-02-03T04:05:06.700");2143 *2144 * Assertions.setLenientDateParsing(true);...

Full Screen

Full Screen

Source:ProcessorTest.java Github

copy

Full Screen

...29 var aggregatedMeasurements = processor.process(loadedMeasurements);30 serializer.serialize(aggregatedMeasurements);31 //then32 AssertionsForClassTypes.assertThat(loadedMeasurements.size()).isEqualTo(9);33 AssertionsForClassTypes.assertThat(aggregatedMeasurements.entrySet().size()).isEqualTo(3);34 var serializedOutput = Files.readString(Paths.get(fullOutputFilePath));35 //обратите внимание: важен порядок ключей36 AssertionsForClassTypes.assertThat(serializedOutput).isEqualTo("{\"val1\":3.0,\"val2\":30.0,\"val3\":33.0}");37 }38}...

Full Screen

Full Screen

Source:ParsingFilesFromZipTest.java Github

copy

Full Screen

1package ru.yandex.mkruchkov.hw;2import com.codeborne.pdftest.PDF;3import com.codeborne.xlstest.XLS;4import com.opencsv.CSVReader;5import org.assertj.core.api.AssertionsForClassTypes;6import org.junit.jupiter.api.Test;7import java.io.InputStream;8import java.io.InputStreamReader;9import java.nio.charset.StandardCharsets;10import java.util.List;11import java.util.zip.ZipEntry;12import java.util.zip.ZipFile;13import static org.assertj.core.api.Assertions.assertThat;14public class ParsingFilesFromZipTest {15 @Test16 void parsingFilesFromZip() throws Exception {17 ZipFile zipFile = new ZipFile("src\\test\\resources\\files.zip");18 ZipEntry txt = zipFile.getEntry("Harry Potter.txt");19 try (InputStream stream = zipFile.getInputStream(txt)) {20 AssertionsForClassTypes.assertThat(new String(stream.readAllBytes(), StandardCharsets.UTF_8)).contains("1. THE BOY WHO LIVED");21 }22 ZipEntry csv = zipFile.getEntry("packs.csv");23 try (InputStream stream = zipFile.getInputStream(csv)) {24 CSVReader reader = new CSVReader(new InputStreamReader(stream));25 List<String[]> list = reader.readAll();26 assertThat(list).contains(27 new String[]{"pack_10_event_april1", "10"},28 new String[]{"pack_book8_offer_valentine", "book8"},29 new String[]{"pack_book4_ch11_paid", "book4"}30 );31 }32 ZipEntry pdf = zipFile.getEntry("sample.pdf");33 try (InputStream stream = zipFile.getInputStream(pdf)) {34 PDF parsed = new PDF(stream);35 assertThat(parsed.text).contains("Oh, how boring typing this stuff");36 }37 ZipEntry xls = zipFile.getEntry("testers.xlsx");38 try (InputStream stream = zipFile.getInputStream(xls)) {39 XLS parsed = new XLS(stream);40 assertThat(parsed.excel.getSheetAt(2).getRow(1).getCell(2).getStringCellValue())41 .isEqualTo("g04570552594797740025");42 }43 }44}...

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AssertionsForClassTypes;2public class Test {3 public static void main(String[] args) {4 AssertionsForClassTypes.assertThat(1).isEqualTo(1);5 }6}7import org.assertj.core.api.Assertions;8public class Test {9 public static void main(String[] args) {10 Assertions.assertThat(1).isEqualTo(1);11 }12}13import org.assertj.core.api.AbstractAssert;14public class Test {15 public static void main(String[] args) {16 AbstractAssert.assertThat(1).isEqualTo(1);17 }18}19import org.assertj.core.api.AbstractIntegerAssert;20public class Test {21 public static void main(String[] args) {22 AbstractIntegerAssert.assertThat(1).isEqualTo(1);23 }24}25import org.assertj.core.api.AbstractIntegerAssert;26public class Test {27 public static void main(String[] args) {28 AbstractIntegerAssert.assertThat(1).isEqualTo(1);29 }30}31import org.assertj.core.api.AbstractAssert;32public class Test {33 public static void main(String[] args) {34 AbstractAssert.assertThat(1).isEqualTo(1);35 }36}37import org.assertj.core.api.AbstractAssert;38public class Test {39 public static void main(String[] args) {40 AbstractAssert.assertThat(1).isEqualTo(1);41 }42}43import org.assertj.core.api.AbstractAssert;44public class Test {45 public static void main(String[] args) {46 AbstractAssert.assertThat(1).isEqualTo(1);47 }48}49import org.assertj.core.api.AbstractAssert;50public class Test {51 public static void main(String[] args) {52 AbstractAssert.assertThat(

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AssertionsForClassTypes;2public class Test {3 public static void main(String[] args) {4 AssertionsForClassTypes.assertThat(1).isEqualTo(1);5 }6}7import org.assertj.core.api.Assertions;8public class Test {9 public static void main(String[] args) {10 Assertions.assertThat(1).isEqualTo(1);11 }12}13import org.assertj.core.api.AssertionsForInterfaceTypes;14public class Test {15 public static void main(String[] args) {16 AssertionsForInterfaceTypes.assertThat(1).isEqualTo(1);17 }18}19import org.assertj.core.api.AssertionsForClassTypes;20public class Test {21 public static void main(String[] args) {22 AssertionsForClassTypes.assertThat(1).isEqualTo(1);23 }24}25import org.assertj.core.api.AssertionsForInterfaceTypes;26public class Test {27 public static void main(String[] args) {28 AssertionsForInterfaceTypes.assertThat(1).isEqualTo(1);29 }30}31import org.assertj.core.api.AssertionsForClassTypes;32public class Test {33 public static void main(String[] args) {34 AssertionsForClassTypes.assertThat(1).isEqualTo(1);35 }36}37import org.assertj.core.api.Assertions;38public class Test {39 public static void main(String[] args) {40 Assertions.assertThat(1).isEqualTo(1);41 }42}43import org.assertj.core.api.AssertionsForClassTypes;44public class Test {45 public static void main(String[] args) {46 AssertionsForClassTypes.assertThat(1).isEqualTo(1);47 }48}49import org.assertj.core

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.AssertionsForClassTypes.*;2public class AssertJ {3 public static void main(String[] args) {4 assertThat(1).isEqualTo(1);5 }6}7import static org.assertj.core.api.Assertions.*;8public class AssertJ {9 public static void main(String[] args) {10 assertThat(1).isEqualTo(1);11 }12}13import static org.assertj.core.api.Java6Assertions.*;14public class AssertJ {15 public static void main(String[] args) {16 assertThat(1).isEqualTo(1);17 }18}19import static org.assertj.core.api.Java6Assertions.*;20public class AssertJ {21 public static void main(String[] args) {22 assertThat(1).isEqualTo(1);23 }24}25import static org.assertj.core.api.Assertions.*;26public class AssertJ {27 public static void main(String[] args) {28 assertThat(1).isEqualTo(1);29 }30}31import static org.assertj.core.api.Assertions.*;32public class AssertJ {33 public static void main(String[] args) {34 assertThat(1).isEqualTo(1);35 }36}37import static org.assertj.core.api.Assertions.*;38public class AssertJ {39 public static void main(String[] args) {40 assertThat(1).isEqualTo(1);41 }42}43import static org.assertj.core.api.Assertions.*;44public class AssertJ {45 public static void main(String[] args) {46 assertThat(1).isEqualTo(1);47 }48}49import static org.assertj.core.api.Assertions.*;50public class AssertJ {51 public static void main(String[] args) {52 assertThat(1).isEqualTo(1);53 }54}

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AssertionsForClassTypes;2import org.testng.annotations.Test;3public class TestNGTest {4 public void test() {5 AssertionsForClassTypes.assertThat(1).isEqualTo(1);6 }7}8import org.assertj.core.api.Assertions;9import org.testng.annotations.Test;10public class TestNGTest {11 public void test() {12 Assertions.assertThat(1).isEqualTo(1);13 }14}

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1public class Test {2 public static void main(String[] args) {3 Assertions.assertThat("abc").isEqualTo("abc");4 }5}6import static org.assertj.core.api.Assertions.assertThat;7public class Test {8 public static void main(String[] args) {9 assertThat("abc").isEqualTo("abc");10 }11}12import static org.assertj.core.api.Assertions.*;13public class Test {14 public static void main(String[] args) {15 assertThat("abc").isEqualTo("abc");16 }17}18import static org.assertj.core.api.Assertions.assertThat;19public class Test {20 public static void main(String[] args) {21 assertThat("abc").isEqualTo("abc");22 }23}24import static org.assertj.core.api.AssertionsForClassTypes.assertThat;25public class Test {26 public static void main(String[] args) {27 assertThat("abc").isEqualTo("abc");28 }29}30import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;31public class Test {32 public static void main(String[] args) {33 assertThat("abc").isEqualTo("abc");34 }35}36import static org.assertj.core.api.AssertionsForClassTypes.assertThat;37public class Test {38 public static void main(String[] args) {39 assertThat("abc").isEqualTo("abc");40 }41}42import static org.assertj.core.api.AssertionsForClassTypes.assertThat;43public class Test {44 public static void main(String[] args) {45 assertThat("abc").isEqualTo("abc");46 }47}48import static org.assertj.core.api.AssertionsForClassTypes.assertThat;49public class Test {50 public static void main(String[]

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.AssertionsForClassTypes.*;2import org.junit.Test;3public class TestClass {4 public void test() {5 assertThat(true).isEqualTo(true);6 }7}

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.AssertionsForClassTypes.*;2import java.util.*;3import java.util.stream.*;4import java.util.stream.Collectors.*;5import java.util.function.*;6import java.util.concurrent.*;7import java.util.regex.*;8import java.util.concurrent.atomic.*;9import java.util.concurrent.locks.*;10import java.util.concurrent.atomic.AtomicInteger;11import java.util.concurrent.atomic.AtomicReference;12import java.util.concurrent.atomic.AtomicReferenceArray;13import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;14import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;15import java.util.concurrent.atomic.AtomicLong;16import java.util.concurrent.atomic.AtomicLongArray;17import java.util.concurrent.atomic.AtomicLongFieldUpdater;18import java.util.concurrent.atomic.AtomicMarkableReference;19import java.util.concurrent.atomic.AtomicStampedReference;20import java.util.concurrent.locks.ReentrantLock;21import java.util.concurrent.locks.ReentrantReadWriteLock;22import java.util.concurrent.locks.Condition;23import java.util.concurrent.locks.Lock;24import java.util.concurrent.locks.ReadWriteLock;25import java.util.concurrent.locks.StampedLock;26import java.util.concurrent.locks.LockSupport;27import java.util.concurrent.locks.AbstractQueuedSynchronizer;28import java.util.concurrent.locks.AbstractOwnableSynchronizer;29import java.util.concurrent.locks.ReentrantLock;30import java.util.concurrent.locks.ReentrantReadWriteLock;31import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;32import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;33import java.util.concurrent.locks.LockSupport;34import java.util.concurrent.locks.Condition;35import java.util.concurrent.locks.Lock;36import java.util.concurrent.locks.ReadWriteLock;37import java.util.concurrent.locks.StampedLock;38import java.util.concurrent.locks.LockSupport;39import java.util.concurrent.locks.AbstractQueuedSynchronizer;40import java.util.concurrent.locks.AbstractOwnableSynchronizer;41import java.util.concurrent.locks.ReentrantLock;42import java.util.concurrent.locks.ReentrantReadWriteLock;43import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;44import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;45import java.util.concurrent.locks.LockSupport;46import java.util.concurrent.locks.Condition;47import java.util.concurrent.locks.Lock;48import java.util.concurrent.locks.ReadWriteLock;49import java.util.concurrent.locks.StampedLock;50import java.util.concurrent.locks.LockSupport;51import java.util.concurrent.locks.AbstractQueuedSynchronizer;52import java.util.concurrent.locks.AbstractOwnableSynchronizer;53import java.util.concurrent.locks.Reentrant

Full Screen

Full Screen

entry

Using AI Code Generation

copy

Full Screen

1package org.example;2import org.assertj.core.api.AssertionsForClassTypes;3public class App {4 public static void main(String[] args) {5 AssertionsForClassTypes.assertThat("foo").isNotEmpty();6 }7}8package org.example;9import org.assertj.core.api.AssertionsForClassTypes;10public class App {11 public static void main(String[] args) {12 AssertionsForClassTypes.assertThat("foo").isNotEmpty();13 }14}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful