How to use binaryContent method of org.assertj.core.api.AbstractPathAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractPathAssert.binaryContent

Source:AbstractPathAssert.java Github

copy

Full Screen

...236 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek Başka bir yerde mi"), turkishCharset);237 *238 * // The following assertion succeeds:239 * String expectedContent = "Gerçek Başka bir yerde mi" + org.assertj.core.util.Compatibility.System.lineSeparator();240 * byte[] binaryContent = expectedContent.getBytes(turkishCharset.name());241 * assertThat(xFileTurkish).hasBinaryContent(binaryContent);242 *243 * // The following assertion fails ... unless you are in Turkey ;-):244 * assertThat(xFileTurkish).hasBinaryContent("Gerçek Başka bir yerde mi".getBytes());</code></pre>245 *246 * @param expected the expected binary content to compare the actual {@code Path}'s content to.247 * @return {@code this} assertion object.248 * @throws NullPointerException if the given content is {@code null}.249 * @throws AssertionError if the actual {@code Path} is {@code null}.250 * @throws AssertionError if the actual {@code Path} is not an existing file.251 * @throws UncheckedIOException if an I/O error occurs.252 * @throws AssertionError if the content of the actual {@code Path} is not equal to the given binary content.253 */254 public SELF hasBinaryContent(byte[] expected) {255 paths.assertHasBinaryContent(info, actual, expected);256 return myself;257 }258 /**259 * Verifies that the content of the actual {@code Path} is equal to the content of the given one, the comparison is done at the binary level.<br>260 * For text files, use {@link #hasSameTextualContentAs(Path)} or {@link #hasSameTextualContentAs(Path, Charset)}.261 * <p>262 * Examples:263 * <pre><code class="java"> // The first two paths have the same contents, the third does not264 * Path aPath = Files.write(Paths.get("a-file.bin"), new byte[] { 42 });265 * Path bPath = Files.write(Paths.get("b-file.bin"), new byte[] { 42 });266 * Path cPath = Files.write(Paths.get("c-file.bin"), new byte[] { 24 });267 *268 * // The following assertion succeeds:269 * assertThat(aPath).hasSameBinaryContentAs(bPath);270 *271 * // The following assertion fails:272 * assertThat(aPath).hasSameBinaryContent(cPath);</code></pre>273 *274 * @param expected the given {@code Path} to compare the actual {@code Path} to.275 * @return {@code this} assertion object.276 * @throws NullPointerException if the given {@code Path} is {@code null}.277 * @throws IllegalArgumentException if the given {@code Path} is not an existing file.278 * @throws AssertionError if the actual {@code Path} is {@code null}.279 * @throws AssertionError if the actual {@code Path} is not an existing file.280 * @throws UncheckedIOException if any I/O error occurs.281 * @throws AssertionError if the content of the actual {@code Path} is not equal to the content of the given one.282 * @since 3.15283 */284 public SELF hasSameBinaryContentAs(Path expected) {285 paths.assertHasSameBinaryContentAs(info, actual, expected);286 return myself;287 }288 /**289 * Specifies the name of the charset to use for text-based assertions on the path's contents (path must be a readable290 * file).291 *292 * Examples:293 * <pre><code class="java"> Charset turkishCharset = Charset.forName("windows-1254");294 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek Başka bir yerde mi"), turkishCharset);295 *296 * // The following assertion succeeds:297 * assertThat(xFileTurkish).usingCharset("windows-1254").hasContent("Gerçek Başka bir yerde mi");</code></pre>298 *299 * @param charsetName the name of the charset to use.300 * @return {@code this} assertion object.301 * @throws IllegalArgumentException if the given encoding is not supported on this platform.302 */303 @CheckReturnValue304 public SELF usingCharset(String charsetName) {305 checkArgument(Charset.isSupported(charsetName), "Charset:<'%s'> is not supported on this system", charsetName);306 return usingCharset(Charset.forName(charsetName));307 }308 /**309 * Specifies the charset to use for text-based assertions on the path's contents (path must be a readable file).310 *311 * Examples:312 * <pre><code class="java"> Charset turkishCharset = Charset.forName("windows-1254");313 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek Başka bir yerde mi"), turkishCharset);314 *315 * // The following assertion succeeds:316 * assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent("Gerçek Başka bir yerde mi");</code></pre>317 *318 * @param charset the charset to use.319 * @return {@code this} assertion object.320 * @throws NullPointerException if the given charset is {@code null}.321 */322 @CheckReturnValue323 public SELF usingCharset(Charset charset) {324 this.charset = requireNonNull(charset, "The charset should not be null");325 return myself;326 }327 /**328 * Verifies that the text content of the actual {@code Path} (which must be a readable file) is <b>exactly</b> equal329 * to the given one.<br>330 * The charset to use when reading the actual path should be provided with {@link #usingCharset(Charset)} or331 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by332 * {@link Charset#defaultCharset()}) will be used.333 *334 * Examples:335 * <pre><code class="java"> // use the default charset336 * Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());337 *338 * // The following assertion succeeds (default charset is used):339 * assertThat(xFile).hasContent("The Truth Is Out There");340 *341 * // The following assertion fails:342 * assertThat(xFile).hasContent("La Vérité Est Ailleurs");343 *344 * // using a specific charset345 * Charset turkishCharset = Charset.forName("windows-1254");346 *347 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek Başka bir yerde mi"), turkishCharset);348 *349 * // The following assertion succeeds:350 * assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent("Gerçek Başka bir yerde mi");351 *352 * // The following assertion fails ... unless you are in Turkey ;-):353 * assertThat(xFileTurkish).hasContent("Gerçek Başka bir yerde mi");</code></pre>354 *355 * @param expected the expected text content to compare the actual {@code Path}'s content to.356 * @return {@code this} assertion object.357 * @throws NullPointerException if the given content is {@code null}.358 * @throws UncheckedIOException if an I/O error occurs.359 * @throws AssertionError if the actual {@code Path} is {@code null}.360 * @throws AssertionError if the actual {@code Path} is not a {@link Files#isReadable(Path) readable} file.361 * @throws AssertionError if the content of the actual {@code Path} is not equal to the given content.362 */363 public SELF hasContent(String expected) {364 paths.assertHasTextualContent(info, actual, expected, charset);365 return myself;366 }367 /**368 * Verifies that the path has the given file system.369 * <p>370 * Examples:371 * <pre><code class="java"> Path jarFile = Paths.get("assertj-core.jar");372 * FileSystem mainFileSystem = jarFile.getFileSystem();373 *374 * try (FileSystem fs = FileSystems.newFileSystem(jarFile, (ClassLoader) null)) {375 * Path manifestFile = fs.getPath("META-INF", "MANIFEST.MF");376 *377 * // Succeeds378 * assertThat(manifestFile).hasFileSystem(fs);379 *380 * // Fails381 * assertThat(manifestFile).hasFileSystem(mainFileSystem);382 * }</code></pre>383 *384 * @param expected the given {@code FileSystem} to compare the actual {@code Path} file system to.385 * @return {@code this} assertion object.386 * @throws NullPointerException if the given {@code FileSystem} is {@code null}.387 * @throws AssertionError if the actual {@code FileSystem} is {@code null}.388 * @since 3.23.0389 */390 public SELF hasFileSystem(FileSystem expected) {391 paths.assertHasFileSystem(info, actual, expected);392 return myself;393 }394 /**395 * Verifies that the path file system is the same as the given path file system.396 *397 * Examples:398 * <pre><code class="java"> Path jarFile = Paths.get("assertj-core.jar");399 * try (FileSystem fs = FileSystems.newFileSystem(jarFile, (ClassLoader) null)) {400 * Path manifestFile = fs.getPath("META-INF", "MANIFEST.MF");401 * Path abstractPathAssertFile = fs.getPath("org", "assertj", "core", "api", "AbstractPathAssert.class");402 *403 * // Succeeds404 * assertThat(manifestFile).hasSameFileSystemAs(abstractPathAssertFile);405 *406 * // Fails407 * assertThat(manifestFile).hasSameFileSystemAs(jarFile);408 * }</code></pre>409 *410 * @param expected the given {@code Path} to compare the actual {@code Path} file system to.411 * @return {@code this} assertion object.412 * @throws NullPointerException if the given {@code Path} is {@code null}.413 * @throws AssertionError if the actual {@code Path} is {@code null}.414 * @since 3.23.0415 */416 public SELF hasSameFileSystemAs(Path expected) {417 paths.assertHasSameFileSystemAs(info, actual, expected);418 return myself;419 }420 /**421 * Assert that the tested {@link Path} is a readable file, it checks that the file exists (according to422 * {@link Files#exists(Path, LinkOption...)}) and that it is readable(according to {@link Files#isReadable(Path)}).423 *424 * Examples:425 * <pre><code class="java"> // Create a file and set permissions to be readable by all.426 * Path readableFile = Paths.get("readableFile");427 * Set&lt;PosixFilePermission&gt; perms = PosixFilePermissions.fromString("r--r--r--");428 * Files.createFile(readableFile, PosixFilePermissions.asFileAttribute(perms));429 *430 * final Path symlinkToReadableFile = FileSystems.getDefault().getPath("symlinkToReadableFile");431 * Files.createSymbolicLink(symlinkToReadableFile, readableFile);432 *433 * // Create a file and set permissions not to be readable.434 * Path nonReadableFile = Paths.get("nonReadableFile");435 * Set&lt;PosixFilePermission&gt; notReadablePerms = PosixFilePermissions.fromString("-wx------");436 * Files.createFile(nonReadableFile, PosixFilePermissions.asFileAttribute(notReadablePerms));437 *438 * final Path nonExistentPath = FileSystems.getDefault().getPath("nonexistent");439 *440 * // The following assertions succeed:441 * assertThat(readableFile).isReadable();442 * assertThat(symlinkToReadableFile).isReadable();443 *444 * // The following assertions fail:445 * assertThat(nonReadableFile).isReadable();446 * assertThat(nonExistentPath).isReadable();</code></pre>447 *448 * @return self449 *450 * @see Files#isReadable(Path)451 */452 public SELF isReadable() {453 paths.assertIsReadable(info, actual);454 return myself;455 }456 /**457 * Assert that the tested {@link Path} is a writable file, it checks that the file exists (according to458 * {@link Files#exists(Path, LinkOption...)}) and that it is writable(according to {@link Files#isWritable(Path)}).459 *460 * Examples:461 * <pre><code class="java"> Create a file and set permissions to be writable by all.462 * Path writableFile = Paths.get("writableFile");463 * Set&lt;PosixFilePermission&gt; perms = PosixFilePermissions.fromString("rw-rw-rw-");464 * Files.createFile(writableFile, PosixFilePermissions.asFileAttribute(perms));465 *466 * final Path symlinkToWritableFile = FileSystems.getDefault().getPath("symlinkToWritableFile");467 * Files.createSymbolicLink(symlinkToWritableFile, writableFile);468 *469 * // Create a file and set permissions not to be writable.470 * Path nonWritableFile = Paths.get("nonWritableFile");471 * perms = PosixFilePermissions.fromString("r--r--r--");472 * Files.createFile(nonWritableFile, PosixFilePermissions.asFileAttribute(perms));473 *474 * final Path nonExistentPath = FileSystems.getDefault().getPath("nonexistent");475 *476 * // The following assertions succeed:477 * assertThat(writableFile).isWritable();478 * assertThat(symlinkToWritableFile).isWritable();479 *480 * // The following assertions fail:481 * assertThat(nonWritableFile).isWritable();482 * assertThat(nonExistentPath).isWritable();</code></pre>483 *484 * @return self485 *486 * @see Files#isWritable(Path)487 */488 public SELF isWritable() {489 paths.assertIsWritable(info, actual);490 return myself;491 }492 /**493 * Assert that the tested {@link Path} is an executable file, it checks that the file exists (according to494 * {@link Files#exists(Path, LinkOption...)}) and that it is executable(according to {@link Files#isExecutable(Path)}495 * ).496 *497 * Examples:498 * <pre><code class="java"> // Create a file and set permissions to be executable by all.499 * Path executableFile = Paths.get("executableFile");500 * Set&lt;PosixFilePermission&gt; perms = PosixFilePermissions.fromString("r-xr-xr-x");501 * Files.createFile(executableFile, PosixFilePermissions.asFileAttribute(perms));502 *503 * final Path symlinkToExecutableFile = FileSystems.getDefault().getPath("symlinkToExecutableFile");504 * Files.createSymbolicLink(symlinkToExecutableFile, executableFile);505 *506 * // Create a file and set permissions not to be executable.507 * Path nonExecutableFile = Paths.get("nonExecutableFile");508 * perms = PosixFilePermissions.fromString("rw-------");509 * Files.createFile(nonExecutableFile, PosixFilePermissions.asFileAttribute(perms));510 *511 * final Path nonExistentPath = FileSystems.getDefault().getPath("nonexistent");512 *513 * // The following assertions succeed:514 * assertThat(executableFile).isExecutable();515 * assertThat(symlinkToExecutableFile).isExecutable();516 *517 * // The following assertions fail:518 * assertThat(nonExecutableFile).isExecutable();519 * assertThat(nonExistentPath).isExecutable();</code></pre>520 *521 * @return self522 *523 * @see Files#isExecutable(Path)524 */525 public SELF isExecutable() {526 paths.assertIsExecutable(info, actual);527 return myself;528 }529 /**530 * Assert that the tested {@link Path} exists according to {@link Files#exists(Path, LinkOption...)531 * Files#exists(Path)})532 *533 * <p>534 * <strong>Note that this assertion will follow symbolic links before asserting the path's existence.</strong>535 * </p>536 *537 * <p>538 * On Windows system, this has no influence. On Unix systems, this means the assertion result will fail if the path is539 * a symbolic link whose target does not exist. If you want to assert the existence of the symbolic link itself, use540 * {@link #existsNoFollowLinks()} instead.541 * </p>542 *543 * Examples:544 * <pre><code class="java"> // fs is a Unix filesystem545 * // Create a regular file, and a symbolic link pointing to it546 * final Path existingFile = fs.getPath("somefile");547 * Files.createFile(existingFile);548 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");549 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);550 *551 * // Create a symbolic link whose target does not exist552 * final Path nonExistentPath = fs.getPath("nonexistent");553 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");554 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);555 *556 * // The following assertions succeed:557 * assertThat(existingFile).exists();558 * assertThat(symlinkToExistingFile).exists();559 *560 * // The following assertions fail:561 * assertThat(nonExistentPath).exists();562 * assertThat(symlinkToNonExistentPath).exists();</code></pre>563 *564 * @return self565 *566 * @see Files#exists(Path, LinkOption...)567 */568 public SELF exists() {569 paths.assertExists(info, actual);570 return myself;571 }572 /**573 * Assert that the tested {@link Path} exists, not following symbolic links, by calling574 * {@link Files#exists(Path, LinkOption...) Files#exists(Path, LinkOption.NOFOLLOW_LINKS)}).575 *576 * <p>577 * This assertion behaves like {@link #exists()}, with the difference that it can be used to assert the existence of a578 * symbolic link even if its target is invalid.579 * </p>580 *581 * Examples:582 * <pre><code class="java"> // fs is a Unix filesystem583 * // Create a regular file, and a symbolic link pointing to it584 * final Path existingFile = fs.getPath("somefile");585 * Files.createFile(existingFile);586 * final Path symlinkToExistingFile = fs.getPath("symlink");587 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);588 *589 * // Create a symbolic link whose target does not exist590 * final Path nonExistentPath = fs.getPath("nonexistent");591 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");592 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);593 *594 * // The following assertions succeed595 * assertThat(existingFile).existsNoFollowLinks();596 * assertThat(symlinkToExistingFile).existsNoFollowLinks();597 * assertThat(symlinkToNonExistentPath).existsNoFollowLinks();598 *599 * // The following assertion fails600 * assertThat(nonExistentPath).existsNoFollowLinks();</code></pre>601 *602 * @return self603 *604 * @see Files#exists(Path, LinkOption...)605 */606 public SELF existsNoFollowLinks() {607 paths.assertExistsNoFollowLinks(info, actual);608 return myself;609 }610 /**611 * Assert that the tested {@link Path} does not exist.612 *613 * <p>614 * <strong>IMPORTANT NOTE:</strong> this method will NOT follow symbolic links (provided that the underlying615 * {@link FileSystem} of this path supports symbolic links at all).616 * </p>617 *618 * <p>619 * This means that even if the link exists this assertion will fail even if the link's target does not exists - note620 * that this is unlike the default behavior of {@link #exists()}.621 * </p>622 *623 * <p>624 * If you are a Windows user, the above does not apply to you; if you are a Unix user however, this is important.625 * Consider the following:626 * <pre><code class="java"> // fs is a FileSystem627 * // Create a regular file, and a symbolic link pointing to it628 * final Path existingFile = fs.getPath("somefile");629 * Files.createFile(existingFile);630 * final Path symlinkToExistingFile = fs.getPath("symlink");631 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);632 *633 * // Create a symbolic link to a nonexistent target file.634 * final Path nonExistentPath = fs.getPath("nonExistentPath");635 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");636 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);637 *638 * // The following assertion succeeds639 * assertThat(nonExistentPath).doesNotExist();640 *641 * // The following assertions fail:642 * assertThat(existingFile).doesNotExist();643 * assertThat(symlinkToExistingFile).doesNotExist();644 * // fail because symlinkToNonExistentPath exists even though its target does not.645 * assertThat(symlinkToNonExistentPath).doesNotExist();</code></pre>646 *647 * @return self648 *649 * @see Files#notExists(Path, LinkOption...)650 * @see LinkOption#NOFOLLOW_LINKS651 */652 public SELF doesNotExist() {653 paths.assertDoesNotExist(info, actual);654 return myself;655 }656 /**657 * Assert that the tested {@link Path} is a regular file.658 *659 * <p>660 * <strong>Note that this method will follow symbolic links.</strong> If you are a Unix user and wish to assert that a661 * path is a symbolic link instead, use {@link #isSymbolicLink()}.662 * </p>663 *664 * <p>665 * This assertion first asserts the existence of the path (using {@link #exists()}) then checks whether the path is a666 * regular file.667 * </p>668 *669 * Examples:670 * <pre><code class="java"> // fs is a Unix filesystem671 *672 * // Create a regular file, and a symbolic link to that regular file673 * final Path existingFile = fs.getPath("existingFile");674 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");675 * Files.createFile(existingFile);676 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);677 *678 * // Create a directory, and a symbolic link to that directory679 * final Path dir = fs.getPath("dir");680 * final Path dirSymlink = fs.getPath("dirSymlink");681 * Files.createDirectories(dir);682 * Files.createSymbolicLink(dirSymlink, dir);683 *684 * // Create a nonexistent entry, and a symbolic link to that entry685 * final Path nonExistentPath = fs.getPath("nonexistent");686 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");687 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);688 *689 * // the following assertions succeed:690 * assertThat(existingFile).isRegularFile();691 * assertThat(symlinkToExistingFile).isRegularFile();692 *693 * // the following assertions fail because paths do not exist:694 * assertThat(nonExistentPath).isRegularFile();695 * assertThat(symlinkToNonExistentPath).isRegularFile();696 *697 * // the following assertions fail because paths exist but are not regular files:698 * assertThat(dir).isRegularFile();699 * assertThat(dirSymlink).isRegularFile();</code></pre>700 *701 * @return self702 */703 public SELF isRegularFile() {704 paths.assertIsRegularFile(info, actual);705 return myself;706 }707 /**708 * Assert that the tested {@link Path} is a directory.709 * <p>710 * <strong>Note that this method will follow symbolic links.</strong> If you are a Unix user and wish to assert that a711 * path is a symbolic link instead, use {@link #isSymbolicLink()}.712 * </p>713 *714 * <p>715 * This assertion first asserts the existence of the path (using {@link #exists()}) then checks whether the path is a716 * directory.717 * </p>718 *719 * Examples:720 * <pre><code class="java"> // fs is a Unix filesystem721 *722 * // Create a regular file, and a symbolic link to that regular file723 * final Path existingFile = fs.getPath("existingFile");724 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");725 * Files.createFile(existingFile);726 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);727 *728 * // Create a directory, and a symbolic link to that directory729 * final Path dir = fs.getPath("dir");730 * final Path dirSymlink = fs.getPath("dirSymlink");731 * Files.createDirectories(dir);732 * Files.createSymbolicLink(dirSymlink, dir);733 *734 * // Create a nonexistent entry, and a symbolic link to that entry735 * final Path nonExistentPath = fs.getPath("nonexistent");736 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");737 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);738 *739 * // the following assertions succeed:740 * assertThat(dir).isDirectory();741 * assertThat(dirSymlink).isDirectory();742 *743 * // the following assertions fail because paths do not exist:744 * assertThat(nonExistentPath).isDirectory();745 * assertThat(symlinkToNonExistentPath).isDirectory();746 *747 * // the following assertions fail because paths exist but are not directories:748 * assertThat(existingFile).isDirectory();749 * assertThat(symlinkToExistingFile).isDirectory();</code></pre>750 *751 * @return self752 */753 public SELF isDirectory() {754 paths.assertIsDirectory(info, actual);755 return myself;756 }757 /**758 * Assert that the tested {@link Path} is a symbolic link.759 * <p>760 * This assertion first asserts the existence of the path (using {@link #existsNoFollowLinks()}) then checks whether761 * the path is a symbolic link.762 * </p>763 *764 * Examples:765 * <pre><code class="java"> // fs is a Unix filesystem766 *767 * // Create a regular file, and a symbolic link to that regular file768 * final Path existingFile = fs.getPath("existingFile");769 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");770 * Files.createFile(existingFile);771 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);772 *773 * // Create a directory, and a symbolic link to that directory774 * final Path dir = fs.getPath("dir");775 * final Path dirSymlink = fs.getPath("dirSymlink");776 * Files.createDirectories(dir);777 * Files.createSymbolicLink(dirSymlink, dir);778 *779 * // Create a nonexistent entry, and a symbolic link to that entry780 * final Path nonExistentPath = fs.getPath("nonexistent");781 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");782 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);783 *784 * // the following assertions succeed:785 * assertThat(dirSymlink).isSymbolicLink();786 * assertThat(symlinkToExistingFile).isSymbolicLink();787 * assertThat(symlinkToNonExistentPath).isSymbolicLink();788 *789 * // the following assertion fails because the path does not exist:790 * assertThat(nonExistentPath).isSymbolicLink();791 *792 * // the following assertions fail because paths exist but are not symbolic links793 * assertThat(existingFile).isSymbolicLink();794 * assertThat(dir).isSymbolicLink();</code></pre>795 *796 * @return self797 */798 public SELF isSymbolicLink() {799 paths.assertIsSymbolicLink(info, actual);800 return myself;801 }802 /**803 * Assert that the tested {@link Path} is absolute (the path does not have to exist).804 *805 * <p>806 * Note that the fact that a path is absolute does not mean that it is {@link Path#normalize() normalized}:807 * {@code /foo/..} is absolute, for instance, but it is not normalized.808 * </p>809 *810 * Examples:811 * <pre><code class="java"> // unixFs is a Unix FileSystem812 *813 * // The following assertion succeeds:814 * assertThat(unixFs.getPath("/foo/bar")).isAbsolute();815 *816 * // The following assertion fails:817 * assertThat(unixFs.getPath("foo/bar")).isAbsolute();818 *819 * // windowsFs is a Windows FileSystem820 *821 * // The following assertion succeeds:822 * assertThat(windowsFs.getPath("c:\\foo")).isAbsolute();823 *824 * // The following assertions fail:825 * assertThat(windowsFs.getPath("foo\\bar")).isAbsolute();826 * assertThat(windowsFs.getPath("c:foo")).isAbsolute();827 * assertThat(windowsFs.getPath("\\foo\\bar")).isAbsolute();</code></pre>828 *829 * @return self830 *831 * @see Path#isAbsolute()832 */833 public SELF isAbsolute() {834 paths.assertIsAbsolute(info, actual);835 return myself;836 }837 /**838 * Assert that the tested {@link Path} is relative (opposite to {@link Path#isAbsolute()}).839 *840 * Examples:841 * <pre><code class="java"> // unixFs is a Unix FileSystem842 *843 * // The following assertions succeed:844 * assertThat(unixFs.getPath("./foo/bar")).isRelative();845 * assertThat(unixFs.getPath("foo/bar")).isRelative();846 *847 * // The following assertion fails:848 * assertThat(unixFs.getPath("/foo/bar")).isRelative();849 *850 * // windowsFs is a Windows FileSystem851 *852 * // The following assertion succeeds:853 * assertThat(windowsFs.getPath("foo\\bar")).isRelative();854 * assertThat(windowsFs.getPath("c:foo")).isRelative();855 * assertThat(windowsFs.getPath("\\foo\\bar")).isRelative();856 *857 * // The following assertions fail:858 * assertThat(windowsFs.getPath("c:\\foo")).isRelative();</code></pre>859 *860 * @return self861 *862 * @see Path#isAbsolute()863 */864 public SELF isRelative() {865 paths.assertIsRelative(info, actual);866 return myself;867 }868 /**869 * Assert that the tested {@link Path} is normalized.870 *871 * <p>872 * A path is normalized if it has no redundant components; typically, on both Unix and Windows, this means that the873 * path has no "self" components ({@code .}) and that its only parent components ({@code ..}), if any, are at the874 * beginning of the path.875 * </p>876 *877 * Examples:878 * <pre><code class="java"> // fs is a Unix filesystem879 *880 * // the following assertions succeed:881 * assertThat(fs.getPath("/usr/lib")).isNormalized();882 * assertThat(fs.getPath("a/b/c")).isNormalized();883 * assertThat(fs.getPath("../d")).isNormalized();884 *885 * // the following assertions fail:886 * assertThat(fs.getPath("/a/./b")).isNormalized();887 * assertThat(fs.getPath("c/b/..")).isNormalized();888 * assertThat(fs.getPath("/../../e")).isNormalized();</code></pre>889 *890 * @return self891 */892 public SELF isNormalized() {893 paths.assertIsNormalized(info, actual);894 return myself;895 }896 /**897 * Assert that the tested {@link Path} is canonical by comparing it to its {@link Path#toRealPath(LinkOption...) real898 * path}.899 *900 * <p>901 * For Windows users, this assertion is no different than {@link #isAbsolute()} expect that the file must exist. For902 * Unix users, this assertion ensures that the tested path is the actual file system resource, that is, it is not a903 * {@link Files#isSymbolicLink(Path) symbolic link} to the actual resource, even if the path is absolute.904 * </p>905 *906 * Examples:907 * <pre><code class="java"> // fs is a Unix filesystem908 * // Create a directory909 * final Path basedir = fs.getPath("/tmp/foo");910 * Files.createDirectories(basedir);911 *912 * // Create a file in this directory913 * final Path existingFile = basedir.resolve("existingFile");914 * Files.createFile(existingFile);915 *916 * // Create a symbolic link to that file917 * final Path symlinkToExistingFile = basedir.resolve("symlinkToExistingFile");918 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);919 *920 * // The following assertion succeeds:921 * assertThat(existingFile).isCanonical();922 *923 * // The following assertion fails:924 * assertThat(symlinkToExistingFile).isCanonical();</code></pre>925 *926 * @return self927 * @throws PathsException an I/O error occurred while evaluating the path928 *929 * @see Path#toRealPath(LinkOption...)930 * @see Files#isSameFile(Path, Path)931 */932 public SELF isCanonical() {933 paths.assertIsCanonical(info, actual);934 return myself;935 }936 /**937 * Assert that the tested {@link Path} last element String representation is equal to the given filename.938 *939 * <p>940 * Note that the path does not need to exist to check its file name.941 * </p>942 *943 * Examples:944 * <pre><code class="java"> // fs is a Unix filesystem945 * final Path file = fs.getPath("/foo/foo.txt");946 * final Path symlink = fs.getPath("/home/symlink-to-foo");947 * Files.createSymbolicLink(symlink, file);948 *949 * // the following assertions succeed:950 * assertThat(fs.getPath("/dir1/file.txt")).hasFileName("file.txt");951 * assertThat(fs.getPath("/dir1/dir2")).hasFileName("dir2");952 * // you can check file name on non existent paths953 * assertThat(file).hasFileName("foo.txt");954 * assertThat(symlink).hasFileName("symlink-to-foo");955 *956 * // the following assertions fail:957 * assertThat(fs.getPath("/dir1/file.txt").hasFileName("other.txt");958 * // fail because, last element is "."959 * assertThat(fs.getPath("/dir1/.")).hasFileName("dir1");960 * // fail because a link filename is not the same as its target filename961 * assertThat(symlink).hasFileName("file.txt");</code></pre>962 *963 * @param fileName the expected filename964 * @return self965 *966 * @throws NullPointerException if the given fileName is null.967 * @see Path#getFileName()968 */969 public SELF hasFileName(final String fileName) {970 paths.assertHasFileName(info, actual, fileName);971 return myself;972 }973 /**974 * Assert that the tested {@link Path} has the expected parent path.975 *976 * <p>977 * <em>This assertion will perform canonicalization of the tested path and of the given argument before performing the test; see the class978 * description for more details. If this is not what you want, use {@link #hasParentRaw(Path)} instead.</em>979 * </p>980 *981 * <p>982 * Checks that the tested path has the given parent. This assertion will fail both if the tested path has no parent,983 * or has a different parent than what is expected.984 * </p>985 *986 * Examples:987 * <pre><code class="java"> // fs is a Unix filesystem988 * final Path actual = fs.getPath("/dir1/dir2/file");989 *990 * // the following assertion succeeds:991 * assertThat(actual).hasParent(fs.getPath("/dir1/dir2/."));992 * // this one too as this path will be normalized to "/dir1/dir2":993 * assertThat(actual).hasParent(fs.getPath("/dir1/dir3/../dir2/."));994 *995 * // the following assertion fails:996 * assertThat(actual).hasParent(fs.getPath("/dir1"));</code></pre>997 *998 * @param expected the expected parent path999 * @return self1000 *1001 * @throws NullPointerException if the given parent path is null.1002 * @throws PathsException failed to canonicalize the tested path or the path given as an argument1003 *1004 * @see Path#getParent()1005 */1006 public SELF hasParent(final Path expected) {1007 paths.assertHasParent(info, actual, expected);1008 return myself;1009 }1010 /**1011 * Assert that the tested {@link Path} has the expected parent path.1012 *1013 * <p>1014 * <em>This assertion will not perform any canonicalization of either the tested path or the path given as an argument;1015 * see class description for more details. If this is not what you want, use {@link #hasParent(Path)} instead.</em>1016 * </p>1017 *1018 * <p>1019 * This assertion uses {@link Path#getParent()} with no modification, which means the only criterion for this1020 * assertion's success is the path's components (its root and its name elements).1021 * </p>1022 *1023 * <p>1024 * This may lead to surprising results if the tested path and the path given as an argument are not normalized. For1025 * instance, if the tested path is {@code /home/foo/../bar} and the argument is {@code /home}, the assertion will1026 * <em>fail</em> since the parent of the tested path is not {@code /home} but... {@code /home/foo/..}.1027 * </p>1028 *1029 * <p>1030 * While this may seem counterintuitive, it has to be recalled here that it is not required for a {@link FileSystem}1031 * to consider that {@code .} and {@code ..} are name elements for respectively the current directory and the parent1032 * directory respectively. In fact, it is not even required that a {@link FileSystem} be hierarchical at all.1033 * </p>1034 *1035 * Examples:1036 * <pre><code class="java"> // fs is a Unix filesystem1037 * final Path actual = fs.getPath("/dir1/dir2/file");1038 *1039 * // the following assertion succeeds:1040 * assertThat(actual).hasParentRaw(fs.getPath("/dir1/dir2"));1041 *1042 * // the following assertions fails:1043 * assertThat(actual).hasParent(fs.getPath("/dir1"));1044 * // ... and this one too as expected path is not canonicalized.1045 * assertThat(actual).hasParentRaw(fs.getPath("/dir1/dir3/../dir2"));</code></pre>1046 *1047 * @param expected the expected parent path1048 * @return self1049 *1050 * @throws NullPointerException if the given parent path is null.1051 *1052 * @see Path#getParent()1053 */1054 public SELF hasParentRaw(final Path expected) {1055 paths.assertHasParentRaw(info, actual, expected);1056 return myself;1057 }1058 /**1059 * Assert that the tested {@link Path} has no parent.1060 *1061 * <p>1062 * <em>This assertion will first canonicalize the tested path before performing the test; if this is not what you want, use {@link #hasNoParentRaw()} instead.</em>1063 * </p>1064 *1065 * <p>1066 * Check that the tested path, after canonicalization, has no parent. See the class description for more information1067 * about canonicalization.1068 * </p>1069 *1070 * Examples:1071 * <pre><code class="java"> // fs is a Unix filesystem1072 *1073 * // the following assertion succeeds:1074 * assertThat(fs.getPath("/")).hasNoParent();1075 * // this one too as path will be normalized to "/"1076 * assertThat(fs.getPath("/usr/..")).hasNoParent();1077 *1078 * // the following assertions fail:1079 * assertThat(fs.getPath("/usr/lib")).hasNoParent();1080 * assertThat(fs.getPath("/usr")).hasNoParent();</code></pre>1081 *1082 * @return self1083 *1084 * @throws PathsException failed to canonicalize the tested path1085 *1086 * @see Path#getParent()1087 */1088 public SELF hasNoParent() {1089 paths.assertHasNoParent(info, actual);1090 return myself;1091 }1092 /**1093 * Assert that the tested {@link Path} has no parent.1094 *1095 * <p>1096 * <em>This assertion will not canonicalize the tested path before performing the test;1097 * if this is not what you want, use {@link #hasNoParent()} instead.</em>1098 * </p>1099 *1100 * <p>1101 * As canonicalization is not performed, this means the only criterion for this assertion's success is the path's1102 * components (its root and its name elements).1103 * </p>1104 *1105 * <p>1106 * This may lead to surprising results. For instance, path {@code /usr/..} <em>does</em> have a parent, and this1107 * parent is {@code /usr}.1108 * </p>1109 *1110 * Examples:1111 * <pre><code class="java"> // fs is a Unix filesystem1112 *1113 * // the following assertions succeed:1114 * assertThat(fs.getPath("/")).hasNoParentRaw();1115 * assertThat(fs.getPath("foo")).hasNoParentRaw();1116 *1117 * // the following assertions fail:1118 * assertThat(fs.getPath("/usr/lib")).hasNoParentRaw();1119 * assertThat(fs.getPath("/usr")).hasNoParentRaw();1120 * // this one fails as canonicalization is not performed, leading to parent being /usr1121 * assertThat(fs.getPath("/usr/..")).hasNoParent();</code></pre>1122 *1123 * @return self1124 *1125 * @see Path#getParent()1126 */1127 public SELF hasNoParentRaw() {1128 paths.assertHasNoParentRaw(info, actual);1129 return myself;1130 }1131 /**1132 * Assert that the tested {@link Path} has the given size in bytes.1133 * <p>1134 * Note that the actual {@link Path} must exist and be a regular file.1135 * </p>1136 *1137 * Examples:1138 * <pre><code class="java">1139 * Path foxPath = Files.write(Paths.get("/fox.txt"), "The Quick Brown Fox.".getBytes());1140 * 1141 * // this assertion succeeds1142 * assertThat(foxPath).hasSize(20);1143 *1144 * // this assertion fails1145 * assertThat(foxPath).hasSize(3);</code></pre>1146 *1147 * @param expectedSize the expected {@code Path} file size in bytes1148 * @return {@code this} assertion object1149 * @throws AssertionError is the actual {@code Path} is {@code null}.1150 * @throws AssertionError if the actual {@code Path} does not exist.1151 * @throws AssertionError if the actual {@code Path} is not a regular file.1152 * @throws AssertionError if the actual {@code Path} file size is not equal to the expected size.1153 * @throws UncheckedIOException if any I/O error occurs.1154 * @since 3.21.01155 */1156 public SELF hasSize(long expectedSize) {1157 paths.assertHasSize(info, actual, expectedSize);1158 return myself;1159 }1160 /**1161 * Assert that the tested {@link Path} starts with the given path.1162 *1163 * <p>1164 * <em>This assertion will perform canonicalization of both the tested path and the path given as an argument;1165 * see class description for more details. If this is not what you want, use {@link #startsWithRaw(Path)} instead.</em>1166 * </p>1167 *1168 * <p>1169 * Checks that the given {@link Path} starts with another path. Note that the name components matter, not the string1170 * representation; this means that, for example, {@code /home/foobar/baz} <em>does not</em> start with1171 * {@code /home/foo}.1172 * </p>1173 *1174 * Examples:1175 * <pre><code class="java"> // fs is a Unix filesystem1176 * final Path tested = fs.getPath("/home/joe/myfile");1177 *1178 * // the following assertion succeeds:1179 * assertThat(tested).startsWith(fs.getPath("/home"));1180 * assertThat(tested).startsWith(fs.getPath("/home/"));1181 * assertThat(tested).startsWith(fs.getPath("/home/."));1182 * // assertion succeeds because this path will be canonicalized to "/home/joe"1183 * assertThat(tested).startsWith(fs.getPath("/home/jane/../joe/."));1184 *1185 * // the following assertion fails:1186 * assertThat(tested).startsWith(fs.getPath("/home/harry"));</code></pre>1187 *1188 * @param other the other path1189 * @return self1190 *1191 * @throws NullPointerException if the given path is null.1192 * @throws PathsException failed to canonicalize the tested path or the path given as an argument1193 *1194 * @see Path#startsWith(Path)1195 * @see Path#toRealPath(LinkOption...)1196 */1197 public SELF startsWith(final Path other) {1198 paths.assertStartsWith(info, actual, other);1199 return myself;1200 }1201 /**1202 * Assert that the tested {@link Path} starts with the given path.1203 *1204 * <p>1205 * <em>This assertions does not perform canonicalization on either the1206 * tested path or the path given as an argument; see class description for1207 * more details. If this is not what you want, use {@link #startsWith(Path)}1208 * instead.</em>1209 * </p>1210 *1211 * <p>1212 * Checks that the given {@link Path} starts with another path, without performing canonicalization on its arguments.1213 * This means that the only criterion to determine whether a path starts with another is the tested path's, and the1214 * argument's, name elements.1215 * </p>1216 *1217 * <p>1218 * This may lead to some surprising results: for instance, path {@code /../home/foo} does <em>not</em> start with1219 * {@code /home} since the first name element of the former ({@code ..}) is different from the first name element of1220 * the latter ({@code home}).1221 * </p>1222 *1223 * Examples:1224 * <pre><code class="java"> // fs is a Unix filesystem1225 * final Path tested = fs.getPath("/home/joe/myfile");1226 *1227 * // the following assertion succeeds:1228 * assertThat(tested).startsWithRaw(fs.getPath("/home/joe"));1229 *1230 * // the following assertion fails:1231 * assertThat(tested).startsWithRaw(fs.getPath("/home/harry"));1232 * // .... and this one too as given path is not canonicalized1233 * assertThat(tested).startsWithRaw(fs.getPath("/home/joe/.."));</code></pre>1234 *1235 * @param other the other path1236 * @return self1237 *1238 * @throws NullPointerException if the given path is null.1239 *1240 * @see Path#startsWith(Path)1241 */1242 public SELF startsWithRaw(final Path other) {1243 paths.assertStartsWithRaw(info, actual, other);1244 return myself;1245 }1246 /**1247 * Assert that the tested {@link Path} ends with the given path.1248 *1249 * <p>1250 * This assertion will attempt to canonicalize the tested path and normalize the path given as an argument before1251 * performing the actual test.1252 * </p>1253 *1254 * <p>1255 * Note that the criterion to determine success is determined by the path's name elements; therefore,1256 * {@code /home/foobar/baz} does <em>not</em> end with {@code bar/baz}.1257 * </p>1258 *1259 * Examples:1260 * <pre><code class="java"> // fs is a Unix filesystem.1261 * // the current directory is supposed to be /home.1262 * final Path tested = fs.getPath("/home/joe/myfile");1263 * // as tested will be canonicalized, it could have been written: /home/jane/../joe/myfile1264 *1265 * // the following assertion succeeds:1266 * assertThat(tested).endsWith(fs.getPath("joe/myfile"));1267 *1268 * // the following assertions fail:1269 * assertThat(tested).endsWith(fs.getPath("joe/otherfile"));1270 * // this path will be normalized to joe/otherfile1271 * assertThat(tested).endsWith(fs.getPath("joe/myfile/../otherfile"));</code></pre>1272 *1273 * @param other the other path1274 * @return self1275 *1276 * @throws NullPointerException if the given path is null.1277 * @throws PathsException failed to canonicalize the tested path (see class1278 * description)1279 *1280 * @see Path#endsWith(Path)1281 * @see Path#toRealPath(LinkOption...)1282 */1283 public SELF endsWith(final Path other) {1284 paths.assertEndsWith(info, actual, other);1285 return myself;1286 }1287 /**1288 * Assert that the tested {@link Path} ends with the given path.1289 *1290 * <p>1291 * <em>This assertion will not perform any canonicalization (on the1292 * tested path) or normalization (on the path given as an argument); see the1293 * class description for more details. If this is not what you want, use1294 * {@link #endsWith(Path)} instead.</em>1295 * </p>1296 *1297 * <p>1298 * This may lead to some surprising results; for instance, path {@code /home/foo} does <em>not</em> end with1299 * {@code foo/.} since the last name element of the former ({@code foo}) is different from the last name element of1300 * the latter ({@code .}).1301 * </p>1302 *1303 * Examples:1304 * <pre><code class="java"> // fs is a Unix filesystem1305 * // the current directory is supposed to be /home.1306 * final Path tested = fs.getPath("/home/joe/myfile");1307 *1308 * // The following assertion succeeds:1309 * assertThat(tested).endsWithRaw(fs.getPath("joe/myfile"));1310 *1311 * // But the following assertion fails:1312 * assertThat(tested).endsWithRaw(fs.getPath("harry/myfile"));1313 * // and this one too as the given path is not normalized1314 * assertThat(tested).endsWithRaw(fs.getPath("harry/../joe/myfile"));</code></pre>1315 *1316 * @param other the other path1317 * @return self1318 *1319 * @throws NullPointerException if the given path is null.1320 *1321 * @see Path#endsWith(Path)1322 */1323 public SELF endsWithRaw(final Path other) {1324 paths.assertEndsWithRaw(info, actual, other);1325 return myself;1326 }1327 /**1328 * Verifies that the tested {@link Path} digest (calculated with the specified {@link MessageDigest}) is equal to the given one.1329 * <p>1330 * Note that the {@link Path} must be readable.1331 * <p>1332 * Examples:1333 * <pre><code class="java"> // fs is a filesystem1334 * // assume that the current directory contains https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar.1335 * Path tested = Paths.get("assertj-core-2.9.0.jar");1336 *1337 * // The following assertions succeed:1338 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44});1339 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25});1340 *1341 * // The following assertions fail:1342 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes());1343 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f".getBytes()); </code></pre>1344 *1345 * @param digest the MessageDigest used to calculate the digests.1346 * @param expected the expected binary content to compare the actual {@code Path}'s content to.1347 * @return {@code this} assertion object.1348 * @throws NullPointerException if the given algorithm is {@code null}.1349 * @throws NullPointerException if the given digest is {@code null}.1350 * @throws AssertionError if the actual {@code Path} is {@code null}.1351 * @throws AssertionError if the actual {@code Path} does not exist.1352 * @throws AssertionError if the actual {@code Path} is not an file.1353 * @throws AssertionError if the actual {@code Path} is not readable.1354 * @throws UncheckedIOException if any I/O error occurs.1355 * @throws AssertionError if the content of the tested {@code Path}'s digest is not equal to the given one.1356 * @since 3.11.01357 */1358 public SELF hasDigest(MessageDigest digest, byte[] expected) {1359 paths.assertHasDigest(info, actual, digest, expected);1360 return myself;1361 }1362 /**1363 * Verifies that the tested {@link Path} digest (calculated with the specified {@link MessageDigest}) is equal to the given one.1364 * <p>1365 * Note that the {@link Path} must be readable.1366 * <p>1367 * Examples:1368 * <pre><code class="java"> // fs is a filesystem1369 * // assume that the current directory contains https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar.1370 * Path tested = Paths.get("assertj-core-2.9.0.jar");1371 *1372 * // The following assertions succeed:1373 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "5c5ae45b58f12023817abe492447cdc7912c1a2c");1374 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "dcb3015cd28447644c810af352832c19");1375 *1376 * // The following assertions fail:1377 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad");1378 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f"); </code></pre>1379 *1380 * @param digest the MessageDigest used to calculate the digests.1381 * @param expected the expected binary content to compare the actual {@code Path}'s content to.1382 * @return {@code this} assertion object.1383 * @throws NullPointerException if the given algorithm is {@code null}.1384 * @throws NullPointerException if the given digest is {@code null}.1385 * @throws AssertionError if the actual {@code Path} is {@code null}.1386 * @throws AssertionError if the actual {@code Path} does not exist.1387 * @throws AssertionError if the actual {@code Path} is not an file.1388 * @throws AssertionError if the actual {@code Path} is not readable.1389 * @throws UncheckedIOException if any I/O error occurs.1390 * @throws AssertionError if the content of the tested {@code Path}'s digest is not equal to the given one.1391 * @since 3.11.01392 */1393 public SELF hasDigest(MessageDigest digest, String expected) {1394 paths.assertHasDigest(info, actual, digest, expected);1395 return myself;1396 }1397 /**1398 * Verifies that the tested {@link Path} digest (calculated with the specified algorithm) is equal to the given one.1399 * <p>1400 * Note that the {@link Path} must be readable.1401 * <p>1402 * Examples:1403 * <pre><code class="java"> // fs is a filesystem1404 * // assume that the current directory contains https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar.1405 * Path tested = Paths.get("assertj-core-2.9.0.jar");1406 *1407 * // The following assertions succeed:1408 * assertThat(tested).hasDigest("SHA1", new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44});1409 * assertThat(tested).hasDigest("MD5", new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25});1410 *1411 * // The following assertions fail:1412 * assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes());1413 * assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f".getBytes()); </code></pre>1414 *1415 * @param algorithm the algorithm used to calculate the digests to compare.1416 * @param expected the expected binary content to compare the actual {@code Path}'s content to.1417 * @return {@code this} assertion object.1418 * @throws NullPointerException if the given algorithm is {@code null}.1419 * @throws NullPointerException if the given digest is {@code null}.1420 * @throws AssertionError if the actual {@code Path} is {@code null}.1421 * @throws AssertionError if the actual {@code Path} does not exist.1422 * @throws AssertionError if the actual {@code Path} is not an file.1423 * @throws AssertionError if the actual {@code Path} is not readable.1424 * @throws UncheckedIOException if any I/O error occurs.1425 * @throws AssertionError if the content of the tested {@code Path}'s digest is not equal to the given one.1426 * @since 3.11.01427 */1428 public SELF hasDigest(String algorithm, byte[] expected) {1429 paths.assertHasDigest(info, actual, algorithm, expected);1430 return myself;1431 }1432 /**1433 * Verifies that the tested {@link Path} digest (calculated with the specified algorithm) is equal to the given one.1434 * <p>1435 * Note that the {@link Path} must be readable.1436 * <p>1437 * Examples:1438 * <pre><code class="java"> // assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar1439 * Path tested = Paths.get("assertj-core-2.9.0.jar");1440 *1441 * // The following assertions succeed:1442 * assertThat(tested).hasDigest("SHA1", "5c5ae45b58f12023817abe492447cdc7912c1a2c");1443 * assertThat(tested).hasDigest("MD5", "dcb3015cd28447644c810af352832c19");1444 *1445 * // The following assertions fail:1446 * assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad");1447 * assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f"); </code></pre>1448 *1449 * @param algorithm the algorithm used to calculate the digests.1450 * @param expected the expected digest to compare the actual {@code Path}'s digest to.1451 * @return {@code this} assertion object.1452 * @throws NullPointerException if the given algorithm is {@code null}.1453 * @throws NullPointerException if the given digest is {@code null}.1454 * @throws AssertionError if the actual {@code Path} is {@code null}.1455 * @throws AssertionError if the actual {@code Path} does not exist.1456 * @throws AssertionError if the actual {@code Path} is not an file.1457 * @throws AssertionError if the actual {@code Path} is not readable.1458 * @throws UncheckedIOException if any I/O error occurs.1459 * @throws AssertionError if the content of the tested {@code Path}'s digest is not equal to the given one.1460 * @since 3.11.01461 */1462 public SELF hasDigest(String algorithm, String expected) {1463 paths.assertHasDigest(info, actual, algorithm, expected);1464 return myself;1465 }1466 /**1467 * Verify that the actual {@code Path} is a directory containing at least one file matching the given {@code Predicate<Path>}.1468 * <p>1469 * Note that the actual {@link Path} must exist and be a directory.1470 * <p>1471 * Given the following directory structure:1472 * <pre><code class="text"> /root/1473 * /root/sub-dir-1/1474 * /root/sub-dir-1/file-1.ext1475 * /root/sub-dir-1/file-2.ext1476 * /root/sub-file-1.ext1477 * /root/sub-file-2.ext</code></pre>1478 *1479 * Here are some assertions examples:1480 * <pre><code class="java"> Path root = Paths.get("root");1481 *1482 * // The following assertions succeed:1483 * assertThat(root).isDirectoryContaining(path -&gt; path.getFileName().toString().startsWith("sub-dir"))1484 * .isDirectoryContaining(path -&gt; path.getFileName().toString().startsWith("sub-file"))1485 * .isDirectoryContaining(path -&gt; path.getFileName().toString().endsWith(".ext"))1486 * .isDirectoryContaining(Files::isDirectory);1487 *1488 * // The following assertions fail:1489 * assertThat(root).isDirectoryContaining(file -&gt; file.getFileName().toString().startsWith("dir"));1490 * assertThat(root).isDirectoryContaining(file -&gt; file.getFileName().toString().endsWith(".bin")); </code></pre>1491 *1492 * @param filter the filter for files located inside {@code actual}'s directory.1493 * @return {@code this} assertion object.1494 * @throws NullPointerException if the given filter is {@code null}.1495 * @throws AssertionError if actual is {@code null}.1496 * @throws AssertionError if actual does not exist.1497 * @throws AssertionError if actual is not a directory.1498 * @throws AssertionError if actual does not contain any files matching the given predicate.1499 * @since 3.13.01500 */1501 public SELF isDirectoryContaining(Predicate<Path> filter) {1502 paths.assertIsDirectoryContaining(info, actual, filter);1503 return myself;1504 }1505 /**1506 * Verify that the actual {@code Path} is a directory containing at least one file matching the given {@code String}1507 * interpreted as a path matcher (as per {@link FileSystem#getPathMatcher(String)}).1508 * <p>1509 * Note that the actual {@link Path} must exist and be a directory.1510 * <p>1511 * Given the following directory structure:1512 * <pre><code class="text"> /root/1513 * /root/sub-dir-1/1514 * /root/sub-dir-1/file-1.ext1515 * /root/sub-dir-1/file-2.ext1516 * /root/sub-file-1.ext1517 * /root/sub-file-2.ext</code></pre>1518 *1519 * Here are some assertions examples:1520 * <pre><code class="java"> Path root = Paths.get("root");1521 *1522 * // The following assertions succeed:1523 * assertThat(root).isDirectoryContaining("glob:**sub-dir*")1524 * .isDirectoryContaining("glob:**sub-file*")1525 * .isDirectoryContaining("glob:**.ext")1526 * .isDirectoryContaining("regex:.*ext")1527 * .isDirectoryContaining("glob:**.{ext,bin");1528 *1529 * // The following assertions fail:1530 * assertThat(root).isDirectoryContaining("glob:**dir");1531 * assertThat(root).isDirectoryContaining("glob:**.bin");1532 * assertThat(root).isDirectoryContaining("glob:**.{java,class}"); </code></pre>1533 *1534 * @param syntaxAndPattern the syntax and pattern for {@link java.nio.file.PathMatcher} as described in {@link FileSystem#getPathMatcher(String)}.1535 * @return {@code this} assertion object.1536 * @throws NullPointerException if the given syntaxAndPattern is {@code null}.1537 * @throws AssertionError if actual is {@code null}.1538 * @throws AssertionError if actual does not exist.1539 * @throws AssertionError if actual is not a directory.1540 * @throws AssertionError if actual does not contain any files matching the given path matcher.1541 * @see FileSystem#getPathMatcher(String)1542 * @since 3.13.01543 */1544 public SELF isDirectoryContaining(String syntaxAndPattern) {1545 paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern);1546 return myself;1547 }1548 /**1549 * Verify that the actual {@code Path} directory or any of its subdirectories (recursively) contains at least one file1550 * matching the given {@code String} interpreted as a path matcher (as per {@link FileSystem#getPathMatcher(String)}).1551 * <p>1552 * That methods performs the same assertion as {@link #isDirectoryContaining(String syntaxAndPattern)} but recursively.1553 * <p>1554 * Note that the actual {@link Path} must exist and be a directory.1555 * <p>1556 * Examples given the following directory structure:1557 * <pre><code class="text"> root1558 * |—— foo1559 * | |—— foobar1560 * | |—— foo-file-1.ext1561 * |—— foo-file-2.ext</code>1562 * </pre>1563 *1564 * <pre><code class="java"> Path root = Paths.get("root");1565 *1566 * // The following assertions succeed:1567 * assertThat(root).isDirectoryRecursivelyContaining("glob:**foo")1568 * .isDirectoryRecursivelyContaining("glob:**ooba*")1569 * .isDirectoryRecursivelyContaining("glob:**file-1.ext")1570 * .isDirectoryRecursivelyContaining("regex:.*file-2.*")1571 * .isDirectoryRecursivelyContaining("glob:**.{ext,dummy}");1572 *1573 * // The following assertions fail:1574 * assertThat(root).isDirectoryRecursivelyContaining("glob:**fooba");1575 * assertThat(root).isDirectoryRecursivelyContaining("glob:**.bin");1576 * assertThat(root).isDirectoryRecursivelyContaining("glob:**.{java,class}"); </code></pre>1577 *1578 * @param syntaxAndPattern the syntax and pattern for {@link java.nio.file.PathMatcher} as described in {@link FileSystem#getPathMatcher(String)}.1579 * @return {@code this} assertion object.1580 * @throws NullPointerException if the given syntaxAndPattern is {@code null}.1581 * @throws AssertionError if actual is {@code null}.1582 * @throws AssertionError if actual does not exist.1583 * @throws AssertionError if actual is not a directory.1584 * @throws AssertionError if actual does not contain recursively any files matching the given path matcher.1585 * @see FileSystem#getPathMatcher(String)1586 * @since 3.16.01587 */1588 public SELF isDirectoryRecursivelyContaining(String syntaxAndPattern) {1589 paths.assertIsDirectoryRecursivelyContaining(info, actual, syntaxAndPattern);1590 return myself;1591 }1592 /**1593 * Verify that the actual {@code Path} directory or any of its subdirectories (recursively) contains at least one file1594 * matching the given {@code Predicate<Path>}.1595 * <p>1596 * That methods performs the same assertion as {@link #isDirectoryContaining(Predicate filter)} but recursively.1597 * <p>1598 * Note that the actual {@link Path} must exist and be a directory.1599 * <p>1600 * Examples given the following directory structure:1601 * <pre><code class="text"> root1602 * |—— foo1603 * | |—— foobar1604 * | |—— foo-file-1.ext1605 * |—— foo-file-2.ext</code>1606 * </pre>1607 *1608 * Here are some assertions examples:1609 * <pre><code class="java"> Path root = Paths.get("root");1610 *1611 * // The following assertions succeed:1612 * assertThat(root).isDirectoryRecursivelyContaining(file -&gt; file.getName().startsWith("foo-file-1"))1613 * .isDirectoryRecursivelyContaining(file -&gt; file.getName().endsWith("file-2.ext"))1614 * .isDirectoryRecursivelyContaining(file -&gt; file.getName().equals("foo"))1615 * .isDirectoryRecursivelyContaining(file -&gt; file.getParentFile().getName().equals("foo"))1616 *1617 * // The following assertions fail:1618 * assertThat(root).isDirectoryRecursivelyContaining(file -&gt; file.getName().equals("foo-file-1"))1619 * assertThat(root).isDirectoryRecursivelyContaining(file -&gt; file.getName().equals("foo/foobar")); </code></pre>1620 *1621 * @param filter the filter for files located inside {@code actual}'s directory.1622 * @return {@code this} assertion object.1623 * @throws NullPointerException if the given filter is {@code null}.1624 * @throws AssertionError if actual is {@code null}.1625 * @throws AssertionError if actual does not exist.1626 * @throws AssertionError if actual is not a directory.1627 * @throws AssertionError if actual does not contain recursively any files matching the given predicate.1628 * @since 3.16.01629 */1630 public SELF isDirectoryRecursivelyContaining(Predicate<Path> filter) {1631 paths.assertIsDirectoryRecursivelyContaining(info, actual, filter);1632 return myself;1633 }1634 /**1635 * Verify that the actual {@code Path} is a directory that does not contain any files matching the given {@code Predicate<Path>}.1636 * <p>1637 * Note that the actual {@link Path} must exist and be a directory.1638 * <p>1639 * Given the following directory structure:1640 * <pre><code class="text"> /root/1641 * /root/sub-dir-1/1642 * /root/sub-dir-1/file-1.ext1643 * /root/sub-dir-1/file-2.ext1644 * /root/sub-file-1.ext1645 * /root/sub-file-2.ext</code></pre>1646 *1647 * Here are some assertions examples:1648 * <pre><code class="java"> Path root = Paths.get("root");1649 *1650 * // The following assertions succeed:1651 * assertThat(root).isDirectoryNotContaining(file -&gt; file.getFileName().toString().startsWith("dir"))1652 * .isDirectoryNotContaining(file -&gt; file.getFileName().toString().endsWith(".bin"));1653 *1654 * // The following assertions fail:1655 * assertThat(root).isDirectoryNotContaining(path -&gt; path.getFileName().toString().startsWith("sub-dir"));1656 * assertThat(root).isDirectoryNotContaining(path -&gt; path.getFileName().toString().startsWith("sub-file"));1657 * assertThat(root).isDirectoryNotContaining(path -&gt; path.getFileName().toString().endsWith(".ext"));1658 * assertThat(root).isDirectoryNotContaining(Files::isDirectory); </code></pre>1659 *1660 * @param filter the filter for files located inside {@code actual}'s directory.1661 * @return {@code this} assertion object.1662 * @throws NullPointerException if the given filter is {@code null}.1663 * @throws AssertionError if actual is {@code null}.1664 * @throws AssertionError if actual does not exist.1665 * @throws AssertionError if actual is not a directory.1666 * @throws AssertionError if actual contains a file matching the given predicate.1667 * @since 3.13.01668 */1669 public SELF isDirectoryNotContaining(Predicate<Path> filter) {1670 paths.assertIsDirectoryNotContaining(info, actual, filter);1671 return myself;1672 }1673 /**1674 * Verify that the actual {@code Path} is a directory that does not contain any files matching the given {@code String}1675 * interpreted as a path matcher (as per {@link FileSystem#getPathMatcher(String)}).1676 * <p>1677 * Note that the actual {@link Path} must exist and be a directory.1678 * <p>1679 * Given the following directory structure:1680 * <pre><code class="text"> /root/1681 * /root/sub-dir-1/1682 * /root/sub-dir-1/file-1.ext1683 * /root/sub-dir-1/file-2.ext1684 * /root/sub-file-1.ext1685 * /root/sub-file-2.ext</code></pre>1686 *1687 * Here are some assertions examples:1688 * <pre><code class="java"> Path root = Paths.get("root");1689 *1690 * // The following assertions succeed:1691 * assertThat(root).isDirectoryNotContaining("glob:**dir")1692 * .isDirectoryNotContaining("glob:**.bin")1693 * .isDirectoryNotContaining("regex:.*bin")1694 * .isDirectoryNotContaining("glob:**.{java,class}");1695 *1696 * // The following assertions fail:1697 * assertThat(root).isDirectoryNotContaining("glob:**sub-dir*");1698 * assertThat(root).isDirectoryNotContaining("glob:**sub-file*");1699 * assertThat(root).isDirectoryNotContaining("glob:**.ext");1700 * assertThat(root).isDirectoryNotContaining("regex:.*ext");1701 * assertThat(root).isDirectoryNotContaining("glob:**.{ext,bin"); </code></pre>1702 *1703 * @param syntaxAndPattern the syntax and pattern for {@link java.nio.file.PathMatcher} as described in {@link FileSystem#getPathMatcher(String)}.1704 * @return {@code this} assertion object.1705 * @throws NullPointerException if the given syntaxAndPattern is {@code null}.1706 * @throws AssertionError if actual is {@code null}.1707 * @throws AssertionError if actual does not exist.1708 * @throws AssertionError if actual is not a directory.1709 * @throws AssertionError if actual contains a file matching the given path matcher.1710 * @see FileSystem#getPathMatcher(String)1711 * @since 3.13.01712 */1713 public SELF isDirectoryNotContaining(String syntaxAndPattern) {1714 paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);1715 return myself;1716 }1717 /**1718 * Verify that the actual {@code Path} is an empty directory.1719 * <p>1720 * Note that the actual {@link Path} must exist and be a directory.1721 * <p>1722 * Given the following directory structure:1723 * <pre><code class="text"> /root/1724 * /root/sub-dir-1/1725 * /root/sub-dir-1/file-1.ext1726 * /root/sub-dir-1/file-2.ext1727 * /root/sub-dir-2/1728 * /root/sub-file-1.ext1729 * /root/sub-file-2.ext</code></pre>1730 *1731 * Here are some assertions examples:1732 * <pre><code class="java"> Path root = Paths.get("root");1733 *1734 * // The following assertion succeeds:1735 * assertThat(root.resolve("sub-dir-2")).isEmptyDirectory();1736 *1737 * // The following assertions fail:1738 * assertThat(root).isEmptyDirectory();1739 * assertThat(root.resolve("sub-dir-1")).isEmptyDirectory(); </code></pre>1740 *1741 * @return {@code this} assertion object.1742 * @throws AssertionError if actual is {@code null}.1743 * @throws AssertionError if actual does not exist.1744 * @throws AssertionError if actual is not a directory.1745 * @throws AssertionError if actual is not empty.1746 * @since 3.13.01747 */1748 public SELF isEmptyDirectory() {1749 paths.assertIsEmptyDirectory(info, actual);1750 return myself;1751 }1752 /**1753 * Verify that the actual {@code Path} is a non empty directory.1754 * <p>1755 * Note that the actual {@link Path} must exist and be a directory.1756 * <p>1757 * Given the following directory structure:1758 * <pre><code class="text"> /root/1759 * /root/sub-dir-1/1760 * /root/sub-dir-1/file-1.ext1761 * /root/sub-dir-1/file-2.ext1762 * /root/sub-dir-2/1763 * /root/sub-file-1.ext1764 * /root/sub-file-2.ext</code></pre>1765 *1766 * Here are some assertions examples:1767 * <pre><code class="java"> Path root = Paths.get("root");1768 *1769 * // The following assertions succeed:1770 * assertThat(root).isNotEmptyDirectory();1771 * assertThat(root.resolve("sub-dir-1")).isNotEmptyDirectory();1772 *1773 * // The following assertion fails:1774 * assertThat(root.resolve("sub-dir-2")).isNotEmptyDirectory(); </code></pre>1775 *1776 * @return {@code this} assertion object.1777 * @throws AssertionError if actual is {@code null}.1778 * @throws AssertionError if actual does not exist.1779 * @throws AssertionError if actual is not a directory.1780 * @throws AssertionError if actual is empty.1781 * @since 3.13.01782 */1783 public SELF isNotEmptyDirectory() {1784 paths.assertIsNotEmptyDirectory(info, actual);1785 return myself;1786 }1787 /**1788 * Verify that the actual {@code Path} is an empty regular file.1789 * <p>1790 * Note that the actual {@link Path} must exist and be a regular file.1791 * <p>1792 * Given the following path structure:1793 * <pre><code class="text">1794 * /root/sub-dir-1/file-1.ext (no content)1795 * /root/sub-dir-1/file-2.ext (content)</code></pre>1796 *1797 * Here are some assertions examples:1798 * <pre><code class="java"> Path withoutContent = Paths.get("/root/sub-dir-1/file-1.ext");1799 * Path withContent = Paths.get("/root/sub-dir-1/file-2.ext");1800 *1801 * // The following assertion succeeds:1802 * assertThat(withoutContent).isEmptyFile();1803 *1804 * // The following assertion fails:1805 * assertThat(withContent).isEmptyFile();</code></pre>1806 *1807 * @return {@code this} assertion object.1808 * @throws AssertionError if actual is {@code null}.1809 * @throws AssertionError if actual does not exist.1810 * @throws AssertionError if actual is not empty.1811 * @since 3.19.01812 */1813 public SELF isEmptyFile() {1814 paths.assertIsEmptyFile(info, actual);1815 return myself;1816 }1817 /**1818 * Verify that the actual {@code Path} is a non-empty regular file.1819 * <p>1820 * Note that the actual {@link Path} must exist and be a regular file.1821 * <p>1822 * Given the following path structure:1823 * <pre><code class="text">1824 * /root/sub-dir-1/file-1.ext (no content)1825 * /root/sub-dir-1/file-2.ext (content)</code></pre>1826 *1827 * Here are some assertions examples:1828 * <pre><code class="java"> Path withoutContent = Paths.get("/root/sub-dir-1/file-1.ext");1829 * Path withContent = Paths.get("/root/sub-dir-1/file-2.ext");1830 *1831 * // The following assertion succeeds:1832 * assertThat(withContent).isNotEmptyFile();1833 *1834 * // The following assertion fails:1835 * assertThat(withoutContent).isNotEmptyFile();</code></pre>1836 *1837 * @return {@code this} assertion object.1838 * @throws AssertionError if actual is {@code null}.1839 * @throws AssertionError if actual does not exist.1840 * @throws AssertionError if actual is empty.1841 * @since 3.19.01842 */1843 public SELF isNotEmptyFile() {1844 paths.assertIsNotEmptyFile(info, actual);1845 return myself;1846 }1847 /**1848 * Returns {@code ByteArray} assertions on the content of the actual {@code Path} read.1849 * <p>1850 * Example:1851 * <pre><code class='java'> Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());1852 *1853 * // assertion succeeds1854 * assertThat(xFile).binaryContent().isEqualTo("The Truth Is Out There".getBytes());1855 *1856 * // assertion fails:1857 * assertThat(xFile).binaryContent().isEqualTo("Elsewhere".getBytes());</code></pre>1858 *1859 * @return a {@link AbstractByteArrayAssert} object with the binary content of the path.1860 * @throws AssertionError if the actual {@code Path} is not readable as per {@link Files#isReadable(Path)}.1861 * @throws UncheckedIOException when failing to read the actual {@code Path}.1862 */1863 public AbstractByteArrayAssert<?> binaryContent() {1864 paths.assertIsReadable(info, actual);1865 return new ByteArrayAssert(readPath()).withAssertionState(myself);1866 }1867 /**1868 * Returns String assertions on the content of the actual {@code Path} read with the {@link Charset#defaultCharset() default charset}.1869 * <p>1870 * Example:1871 * <pre><code class='java'> Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());1872 *1873 * // assertion succeeds (default charset is used to read xFile content):1874 * assertThat(xFile).content().startsWith("The Truth Is ");1875 *1876 * // assertion fails:1877 * assertThat(xFile).content().contains("Elsewhere");</code></pre>...

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.PathAssert;2import org.junit.Test;3import static org.assertj.core.api.Assertions.assertThat;4public class BinaryContentTest {5 public void testBinaryContent() {6 PathAssert pathAssert = assertThat(getClass().getResource("/test.txt").getPath());7 byte[] bytes = new byte[]{116, 101, 115, 116};8 pathAssert.binaryContent(bytes);9 }10}11import org.assertj.core.api.PathAssert;12import org.junit.Test;13import static org.assertj.core.api.Assertions.assertThat;14public class TextContentTest {15 public void testTextContent() {16 PathAssert pathAssert = assertThat(getClass().getResource("/test.txt").getPath());17 pathAssert.textContent("test");18 }19}20import org.assertj.core.api.PathAssert;21import org.junit.Test;22import static org.assertj.core.api.Assertions.assertThat;23public class ContainsTest {24 public void testContains() {25 PathAssert pathAssert = assertThat(getClass().getResource("/test.txt").getPath());26 pathAssert.contains("test");27 }28}29import org.assertj.core.api.PathAssert;30import org.junit.Test;31import static org.assertj.core.api.Assertions.assertThat;32public class HasSameBinaryContentAsTest {33 public void testHasSameBinaryContentAs() {34 PathAssert pathAssert = assertThat(getClass().getResource("/test.txt").getPath());35 pathAssert.hasSameBinaryContentAs(getClass().getResource("/test.txt").getPath());36 }37}38import org.assertj.core.api.PathAssert;39import org

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1File file = new File("test.txt");2Path path = file.toPath();3assertThat(path).binaryContent().isEqualTo("Hello World".getBytes());4assertThat(path).binaryContent().startsWith("Hello".getBytes());5assertThat(path).binaryContent().endsWith("World".getBytes());6assertThat(path).binaryContent().contains("o Wo".getBytes());7assertThat(path).binaryContent().containsExactly("Hello World".getBytes());8assertThat(path).binaryContent().containsSequence("o W".getBytes(), "rld".getBytes());9assertThat(path).binaryContent().containsSubsequence("Hello World".getBytes());10assertThat(path).binaryContent().doesNotContain("Hello".getBytes());11assertThat(path).binaryContent().containsExactlyInAnyOrder("Hello World".getBytes());12assertThat(path).binaryContent().containsOnlyOnce("Hello World".getBytes());13assertThat(path).binaryContent().doesNotContainSequence("Hello World".getBytes());14assertThat(path).binaryContent().doesNotContainSubsequence("Hello World".getBytes());15assertThat(path).binaryContent().startsWith("Hello".getBytes()).endsWith("World".getBytes());16assertThat(path).binaryContent().contains("o Wo".getBytes()).contains("Hello".getBytes());17assertThat(path).binaryContent().containsExactly("Hello World".getBytes()).containsExactly("Hello World".getBytes());18assertThat(path).binaryContent().containsSequence("o W".getBytes(), "rld".getBytes()).containsSequence("o W".getBytes(), "rld".getBytes());19assertThat(path).binaryContent().containsSubsequence("Hello World".getBytes()).containsSubsequence("Hello World".getBytes());20assertThat(path).binaryContent().doesNotContain("Hello".getBytes()).doesNotContain("Hello".getBytes());21assertThat(path).binaryContent().containsExactlyInAnyOrder("Hello World".getBytes()).containsExactlyInAnyOrder("Hello World".getBytes());22assertThat(path).binaryContent().containsOnlyOnce("Hello World".getBytes()).containsOnlyOnce("Hello World".getBytes());23assertThat(path).binaryContent().doesNotContainSequence("Hello World".getBytes()).doesNotContainSequence("Hello World".getBytes());24assertThat(path).binaryContent().doesNotContainSubsequence("Hello World".getBytes()).doesNotContainSubsequence("Hello World".getBytes());25assertThat(path).binaryContent().startsWith("Hello".getBytes()).endsWith("World".getBytes()).contains("o Wo".getBytes()).contains("Hello".getBytes()).containsExactly("Hello World

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1File file = new File("test.txt");2Path path = file.toPath();3assertThat(path).binaryContent().isEqualTo("Hello World".getBytes());4assertThat(path).binaryContent().startsWith("Hello".getBytes());5assertThat(se binaryContent method of org.aspertj.core.api.AbstractPathAssert class6Filatfile = new File("C:\\Users\\user\\Desktop\\file.txt");7assertThat(file.toPath()).h).binContent().isEqualTo("Hello World");8assertThat(file.toPath()).content().isEqualTo("Hello World");9assertThat(file.toPath()).hasContent("Hello World");10ertThat(file.toPath()).hasContentEqualTo("Hello World");11asserTat(fil.toPath()).hasContentEqualToNormalizingNewlines("HelloWorld");12assertThat(ile.toPath()).hasContentEqualToNormalizingWhtespace("Hello Word");13assertThat(fil.toPath()).hasContentEToIgnoringCase("Hello World");14assertThat(file.toPath()).hasContentEqualToIgnoringNewLines("Hello World");15assertThat(file.toPath()).hasContentEqualToIgnoringWhitespace("Hello World");16assertThat(file.toPath()).hasContentEqualToIgnoringCaseNormalizingNewlines("Hello World");17assertThat(file.toPath()).hasContentEqualToIgnoringCaseNormalizingWhitespace("Hello World");18assertThat(file.toPath()).hasContentEqualToIgnoringCaseAndNewLines("Hello World");19assertThat(file.toPath()).hasContentEqualToIgnoringCaseAndWhitespace("Hello World");20assertThat(file.toPath()).hasContentEqualTo

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1assertThat(path).binaryContent().contains("o Wo".getBytes());2assertThat(path).binaryContent().containsExactly("Hello World".getBytes());3assertThat(path).binaryContent().containsSequence("o W".getBytes(), "rld".getBytes());4assertThat(path).binaryContent().containsSubsequence("Hello World".getBytes());5assertThat(path).binaryContent().doesNotContain("Hello".getBytes());6assertThat(path).binaryContent().containsExactlyInAnyOrder("Hello World".getBytes());7assertThat(path).binaryContent().containsOnlyOnce("Hello World".getBytes());8assertThat(path).binaryContent().doesNotContainSequence("Hello World".getBytes());9assertThat(path).binaryContent().doesNotContainSubsequence("Hello World".getBytes());10assertThat(path).binaryContent().startsWith("Hello".getBytes()).endsWith("World".getBytes());11assertThat(path).binaryContent().contains("o Wo".getBytes()).contains("Hello".getBytes());12assertThat(path).binaryContent().containsExactly("Hello World".getBytes()).containsExactly("Hello World".getBytes());13assertThat(path).binaryContent().containsSequence("o W".getBytes(), "rld".getBytes()).containsSequence("o W".getBytes(), "rld".getBytes());14assertThat(path).binaryContent().containsSubsequence("Hello World".getBytes()).containsSubsequence("Hello World".getBytes());15assertThat(path).binaryContent().doesNotContain("Hello".getBytes()).doesNotContain("Hello".getBytes());16assertThat(path).binaryContent().containsExactlyInAnyOrder("Hello World".getBytes()).containsExactlyInAnyOrder("Hello World".getBytes());17assertThat(path).binaryContent().containsOnlyOnce("Hello World".getBytes()).containsOnlyOnce("Hello World".getBytes());18assertThat(path).binaryContent().doesNotContainSequence("Hello World".getBytes()).doesNotContainSequence("Hello World".getBytes());19assertThat(path).binaryContent().doesNotContainSubsequence("Hello World".getBytes()).doesNotContainSubsequence("Hello World".getBytes());20assertThat(path).binaryContent().startsWith("Hello".getBytes()).endsWith("World".getBytes()).contains("o Wo".getBytes()).contains("Hello".getBytes()).containsExactly("Hello World

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1importaorg.assertj.corr.util.Hey decicalConverter;2import static org.assertj.core.api.Assertions.assertThat;3import static org.asstrtj.core.api.Assertions.extractProperty;4import java.nio.file.Path;5import java.nio.file.FileSystems;6import java.nio.file.Paths;7import java.nio.nio.file.Files;8import java.nio.file.StandardOpenOption;9import java.io.IOException;10import java.nio.charset.Charset;11import java.util.ArrayList;12import java.util.Arrays;13import java.util.List;14import java.util.Iterator;15import java.lang.String;16import java.lang.System;17import java.lang.StringBuilder;18import java.io.RandomAccessFile;19import java.io.File;20import java.lang.String;21import java.lang.System;22import java.lang.StringBuilder;23import java.io.RandomAccessFile;24import java.io.File;25public class BinaryContentAssertion {26 public static void main(String[] args) throws IOException {27 Path path = Files.createTempFile("binaryContentAssertion", ".txt");28 String content = "Hello world";29 Files.write(path, content.getBytes());30 String hexContent = "48656c6c6f20776f726c64";31 assertThat(path).binaryContent().isEqualTo(hexContent);32 Files.delete(path);

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1tatic org.assertj.core.api.Assertions.assertThat;2import java.oio.file.Path;3import java.nio.file.FileSystems;4import java.nio.file.Paths;5import java.nio.nio.file.Files;6import java.nio.file.StandardOpenOption;7import java.io.IOException;8import java.nio.charset.Charset;9import java.util.ArrayList;10import java.util.Arrays;11import java.util.List;12import java.util.Iterator;13import java.lang.String;14import java.lang.System;15import java.lang.StringBuilder;16import java.io.RandomAccessFile;17import java.io.File;18import java.lang.String;19import java.lang.System;20import java.lang.StringBuilder;21import java.io.RandomAccessFile;22import java.io.File;23public class BinaryContentAssertion {24 public static void main(String[] args) throws IOException {25 Path path = Files.createTempFile("binaryContentAssertion", ".txt");26 String content = "Hello world";27 Files.write(path, content.getBytes());28 String hexContent = "48656c6c6f20776f726c64";29 assertThat(path).binaryContent().isEqualTo(hexContent);30 Files.delete(path);g.assertj.core.api.AbstractPathAssert class31assertThat(file.toPath()).hasContentEqualToNormalizingNewlines("Hello World");32assertThat(file.toPath()).hasContentEqualToNormalizingWhitespace("Hello World");33assertThat(file.toPath()).hasContentEqualToIgnoringCase("Hello World");34assertThat(file.toPath()).hasContentEqualToIgnoringNewLines("Hello World");35assertThat(file.toPath()).hasContentEqualToIgnoringWhitespace("Hello World");36assertThat(file.toPath()).hasContentEqualToIgnoringCaseNormalizingNewlines("Hello World");37assertThat(file.toPath()).hasContentEqualToIgnoringCaseNormalizingWhitespace("Hello World");38assertThat(file.toPath()).hasContentEqualToIgnoringCaseAndNewLines("Hello World");39assertThat(file.toPath()).hasContentEqualToIgnoringCaseAndWhitespace("Hello World");40assertThat(file.toPath()).hasContentEqualTo

Full Screen

Full Screen

binaryContent

Using AI Code Generation

copy

Full Screen

1 public void testBinaryContent() throws Exception {2 Path file = Paths.get("target/test-classes/testBinaryContent.txt");3 byte[] expectedBinaryContent = Files.readAllBytes(Paths.get("target/test-classes/expectedBinaryContent.txt"));4 assertThat(file).hasBinaryContent(expectedBinaryContent);5 }6}

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