How to use isReadable method of org.assertj.core.api.AbstractFileAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractFileAssert.isReadable

Source:AssertJAssertions.java Github

copy

Full Screen

...1886 public AbstractPathAssert hasSameBinaryContentAs(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }1887 public AbstractPathAssert usingCharset(String p0) { return (AbstractPathAssert) (Object) null; }1888 public AbstractPathAssert usingCharset(java.nio.charset.Charset p0) { return (AbstractPathAssert) (Object) null; }1889 public AbstractPathAssert hasContent(String p0) { return (AbstractPathAssert) (Object) null; }1890 public AbstractPathAssert isReadable() { return (AbstractPathAssert) (Object) null; }1891 public AbstractPathAssert isWritable() { return (AbstractPathAssert) (Object) null; }1892 public AbstractPathAssert isExecutable() { return (AbstractPathAssert) (Object) null; }1893 public AbstractPathAssert exists() { return (AbstractPathAssert) (Object) null; }1894 public AbstractPathAssert existsNoFollowLinks() { return (AbstractPathAssert) (Object) null; }1895 public AbstractPathAssert doesNotExist() { return (AbstractPathAssert) (Object) null; }1896 public AbstractPathAssert isRegularFile() { return (AbstractPathAssert) (Object) null; }1897 public AbstractPathAssert isDirectory() { return (AbstractPathAssert) (Object) null; }1898 public AbstractPathAssert isSymbolicLink() { return (AbstractPathAssert) (Object) null; }1899 public AbstractPathAssert isAbsolute() { return (AbstractPathAssert) (Object) null; }1900 public AbstractPathAssert isRelative() { return (AbstractPathAssert) (Object) null; }1901 public AbstractPathAssert isNormalized() { return (AbstractPathAssert) (Object) null; }1902 public AbstractPathAssert isCanonical() { return (AbstractPathAssert) (Object) null; }1903 public AbstractPathAssert hasFileName(String p0) { return (AbstractPathAssert) (Object) null; }1904 public AbstractPathAssert hasParent(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }...

Full Screen

Full Screen

Source:AbstractFileAssert.java Github

copy

Full Screen

...203 * <pre><code class='java'> File tmpFile = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);204 * File tmpDir = Files.createTempDirectory(&quot;tmp&quot;).toFile();205 *206 * // assertions will pass207 * assertThat(tmpFile).isReadable();208 * assertThat(tmpDir).isReadable();209 *210 * tmpFile.setReadable(false);211 * tmpDir.setReadable(false);212 *213 * // assertions will fail214 * assertThat(tmpFile).isReadable();215 * assertThat(tmpDir).isReadable();</code></pre>216 *217 * @return {@code this} assertion object.218 * @throws AssertionError if the actual {@code File} is {@code null}.219 * @throws AssertionError if the actual {@code File} can not be read by the application.220 *221 * @see #canRead()222 * @since 3.21.0223 */224 public SELF isReadable() {225 return canRead();226 }227 /**228 * Verifies that the content of the actual {@code File} is equal to the content of the given one.229 * The charset to use when reading the actual file can be provided with {@link #usingCharset(Charset)} or230 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by231 * {@link Charset#defaultCharset()}) will be used.232 *233 * Examples:234 * <pre><code class="java"> // use the default charset235 * File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();236 * File xFileClone = Files.write(Paths.get("xfile-clone.txt"), "The Truth Is Out There".getBytes()).toFile();237 * File xFileFrench = Files.write(Paths.get("xfile-french.txt"), "La Vérité Est Ailleurs".getBytes()).toFile();238 * // use UTF-8 charset239 * File xFileUTF8 = Files.write(Paths.get("xfile-clone.txt"), Arrays.asList("The Truth Is Out There"), StandardCharsets.UTF_8).toFile();240 *241 * // The following assertion succeeds (default charset is used):242 * assertThat(xFile).hasSameContentAs(xFileClone);243 * // The following assertion succeeds (UTF-8 charset is used to read xFile):244 * assertThat(xFileUTF8).usingCharset("UTF-8").hasContent(xFileClone);245 *246 * // The following assertion fails:247 * assertThat(xFile).hasSameContentAs(xFileFrench);</code></pre>248 *249 * @param expected the given {@code File} to compare the actual {@code File} to.250 * @return {@code this} assertion object.251 * @throws NullPointerException if the given {@code File} is {@code null}.252 * @throws IllegalArgumentException if the given {@code File} is not an existing file.253 * @throws AssertionError if the actual {@code File} is {@code null}.254 * @throws AssertionError if the actual {@code File} is not an existing file.255 * @throws UncheckedIOException if an I/O error occurs.256 * @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.257 *258 * @deprecated use {@link #hasSameTextualContentAs(File)} instead259 */260 @Deprecated261 public SELF hasContentEqualTo(File expected) {262 return hasSameContentAs(expected);263 }264 /**265 * @deprecated use {@link #hasSameTextualContentAs(File)} instead.266 * <p>267 * Verifies that the content of the actual {@code File} is equal to the content of the given one.268 * The charset to use when reading the actual file can be provided with {@link #usingCharset(Charset)} or269 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by270 * {@link Charset#defaultCharset()}) will be used.271 *272 * Examples:273 * <pre><code class="java"> // use the default charset274 * File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();275 * File xFileClone = Files.write(Paths.get("xfile-clone.txt"), "The Truth Is Out There".getBytes()).toFile();276 * File xFileFrench = Files.write(Paths.get("xfile-french.txt"), "La Vérité Est Ailleurs".getBytes()).toFile();277 * // use UTF-8 charset278 * File xFileUTF8 = Files.write(Paths.get("xfile-clone.txt"), Arrays.asList("The Truth Is Out There"), StandardCharsets.UTF_8).toFile();279 *280 * // The following assertion succeeds (default charset is used):281 * assertThat(xFile).hasSameContentAs(xFileClone);282 * // The following assertion succeeds (UTF-8 charset is used to read xFile):283 * assertThat(xFileUTF8).usingCharset("UTF-8").hasSameContentAs(xFileClone);284 *285 * // The following assertion fails:286 * assertThat(xFile).hasSameContentAs(xFileFrench);</code></pre>287 *288 * @param expected the given {@code File} to compare the actual {@code File} to.289 * @return {@code this} assertion object.290 * @throws NullPointerException if the given {@code File} is {@code null}.291 * @throws IllegalArgumentException if the given {@code File} is not an existing file.292 * @throws AssertionError if the actual {@code File} is {@code null}.293 * @throws AssertionError if the actual {@code File} is not an existing file.294 * @throws UncheckedIOException if an I/O error occurs.295 * @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.296 */297 @Deprecated298 public SELF hasSameContentAs(File expected) {299 return hasSameTextualContentAs(expected);300 }301 /**302 * Verifies that the content of the actual {@code File} is equal to the content of the given one.303 * The charset to use when reading the actual file can be provided with {@link #usingCharset(Charset)} or304 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by305 * {@link Charset#defaultCharset()}) will be used.306 *307 * Examples:308 * <pre><code class="java"> // use the default charset309 * File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();310 * File xFileClone = Files.write(Paths.get("xfile-clone.txt"), "The Truth Is Out There".getBytes()).toFile();311 * File xFileFrench = Files.write(Paths.get("xfile-french.txt"), "La Vérité Est Ailleurs".getBytes()).toFile();312 * // use UTF-8 charset313 * File xFileUTF8 = Files.write(Paths.get("xfile-clone.txt"), Arrays.asList("The Truth Is Out There"), StandardCharsets.UTF_8).toFile();314 *315 * // The following assertion succeeds (default charset is used):316 * assertThat(xFile).hasSameTextualContentAs(xFileClone);317 * // The following assertion succeeds (UTF-8 charset is used to read xFile):318 * assertThat(xFileUTF8).usingCharset("UTF-8").hasSameTextualContentAs(xFileClone);319 *320 * // The following assertion fails:321 * assertThat(xFile).hasSameTextualContentAs(xFileFrench);</code></pre>322 *323 * @param expected the given {@code File} to compare the actual {@code File} to.324 * @return {@code this} assertion object.325 * @throws NullPointerException if the given {@code File} is {@code null}.326 * @throws IllegalArgumentException if the given {@code File} is not an existing file.327 * @throws AssertionError if the actual {@code File} is {@code null}.328 * @throws AssertionError if the actual {@code File} is not an existing file.329 * @throws UncheckedIOException if an I/O error occurs.330 * @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.331 * @since 3.15332 */333 public SELF hasSameTextualContentAs(File expected) {334 files.assertSameContentAs(info, actual, charset, expected, Charset.defaultCharset());335 return myself;336 }337 /**338 * Verifies that the content of the actual {@code File} is equal to the content of the given one, the comparison is done at the binary level.<br>339 * For text files, use {@link #hasSameTextualContentAs(File)}.340 * <p>341 * Examples:342 * <pre><code class="java"> // The first two files have the same contents, the third does not343 * File aFile = Files.write(Paths.get("a-file.bin"), new byte[] { 42 }).toFile();344 * File bFile = Files.write(Paths.get("b-file.bin"), new byte[] { 42 }).toFile();345 * File cFile = Files.write(Paths.get("c-file.bin"), new byte[] { 24 }).toFile();346 *347 * // The following assertion succeeds:348 * assertThat(aFile).hasSameBinaryContentAs(bFile);349 *350 * // The following assertion fails:351 * assertThat(aFile).hasSameBinaryContent(cFile);</code></pre>352 *353 * @param expected the given {@code File} to compare the actual {@code File} to.354 * @return {@code this} assertion object.355 * @throws NullPointerException if the given {@code File} is {@code null}.356 * @throws IllegalArgumentException if the given {@code File} is not an existing file.357 * @throws AssertionError if the actual {@code File} is {@code null}.358 * @throws AssertionError if the actual {@code File} is not an existing file.359 * @throws UncheckedIOException if an I/O error occurs.360 * @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.361 * @since 3.15362 */363 public SELF hasSameBinaryContentAs(File expected) {364 files.assertSameBinaryContentAs(info, actual, expected);365 return myself;366 }367 /**368 * Verifies that the content of the actual {@code File} is the same as the expected one, the expected {@code File} being read with the given charset while369 * the charset used to read the actual path can be provided with {@link #usingCharset(Charset)} or370 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by371 * {@link Charset#defaultCharset()}) will be used.372 * <p>373 * Examples:374 * <pre><code class="java"> File fileUTF8 = Files.write(Paths.get("actual"), Collections.singleton("Gerçek"), StandardCharsets.UTF_8).toFile();375 * Charset turkishCharset = Charset.forName("windows-1254");376 * File fileTurkishCharset = Files.write(Paths.get("expected"), Collections.singleton("Gerçek"), turkishCharset).toFile();377 *378 * // The following assertion succeeds:379 * assertThat(fileUTF8).usingCharset(StandardCharsets.UTF_8).hasSameContentAs(fileTurkishCharset, turkishCharset);380 *381 * // The following assertion fails:382 * assertThat(fileUTF8).usingCharset(StandardCharsets.UTF_8).hasSameContentAs(fileTurkishCharset, StandardCharsets.UTF_8);</code></pre>383 *384 * @param expected the given {@code File} to compare the actual {@code File} to.385 * @param expectedCharset the {@link Charset} used to read the content of the expected file.386 * @return {@code this} assertion object.387 * @throws NullPointerException if the given {@code File} is {@code null}.388 * @throws IllegalArgumentException if the given {@code File} is not an existing file.389 * @throws AssertionError if the actual {@code File} is {@code null}.390 * @throws AssertionError if the actual {@code File} is not an existing file.391 * @throws UncheckedIOException if an I/O error occurs.392 * @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.393 * @deprecated use {@link #hasSameTextualContentAs(File, Charset)} instead394 */395 @Deprecated396 public SELF hasSameContentAs(File expected, Charset expectedCharset) {397 return hasSameTextualContentAs(expected, expectedCharset);398 }399 /**400 * Verifies that the content of the actual {@code File} is the same as the expected one, the expected {@code File} being read with the given charset while401 * the charset used to read the actual path can be provided with {@link #usingCharset(Charset)} or {@link #usingCharset(String)} prior to calling this method;402 * if not, the platform's default charset (as returned by {@link Charset#defaultCharset()}) will be used.403 * <p>404 * Examples:405 * <pre><code class="java"> File fileUTF8 = Files.write(Paths.get("actual"), Collections.singleton("Gerçek"), StandardCharsets.UTF_8).toFile();406 * Charset turkishCharset = Charset.forName("windows-1254");407 * File fileTurkishCharset = Files.write(Paths.get("expected"), Collections.singleton("Gerçek"), turkishCharset).toFile();408 *409 * // The following assertion succeeds:410 * assertThat(fileUTF8).usingCharset(StandardCharsets.UTF_8).hasSameTextualContentAs(fileTurkishCharset, turkishCharset);411 *412 * // The following assertion fails:413 * assertThat(fileUTF8).usingCharset(StandardCharsets.UTF_8).hasSameTextualContentAs(fileTurkishCharset, StandardCharsets.UTF_8);</code></pre>414 *415 * @param expected the given {@code File} to compare the actual {@code File} to.416 * @param expectedCharset the {@link Charset} used to read the content of the expected file.417 * @return {@code this} assertion object.418 * @throws NullPointerException if the given {@code File} is {@code null}.419 * @throws IllegalArgumentException if the given {@code File} is not an existing file.420 * @throws AssertionError if the actual {@code File} is {@code null}.421 * @throws AssertionError if the actual {@code File} is not an existing file.422 * @throws UncheckedIOException if an I/O error occurs.423 * @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.424 * @since 3.13425 */426 public SELF hasSameTextualContentAs(File expected, Charset expectedCharset) {427 files.assertSameContentAs(info, actual, charset, expected, expectedCharset);428 return myself;429 }430 /**431 * Verifies that the binary content of the actual {@code File} is <b>exactly</b> equal to the given one.432 * <p>433 * Example:434 * <pre><code class='java'> File bin = File.createTempFile(&quot;tmp&quot;, &quot;bin&quot;);435 * Files.write(bin.toPath(), new byte[] {1, 1});436 *437 * // assertion will pass438 * assertThat(bin).hasBinaryContent(new byte[] {1, 1});439 *440 * // assertion will fail441 * assertThat(bin).hasBinaryContent(new byte[] { });442 * assertThat(bin).hasBinaryContent(new byte[] {0, 0});</code></pre>443 *444 * @param expected the expected binary content to compare the actual {@code File}'s content to.445 * @return {@code this} assertion object.446 * @throws NullPointerException if the given content is {@code null}.447 * @throws AssertionError if the actual {@code File} is {@code null}.448 * @throws AssertionError if the actual {@code File} is not an existing file.449 * @throws UncheckedIOException if an I/O error occurs.450 * @throws AssertionError if the content of the actual {@code File} is not equal to the given binary content.451 */452 public SELF hasBinaryContent(byte[] expected) {453 files.assertHasBinaryContent(info, actual, expected);454 return myself;455 }456 /**457 * Verifies that the size of the {@code File} under test is <b>exactly</b> equal to the given size <b>in bytes</b>.458 * <p>459 * Example:460 * <pre><code class='java'> File file = File.createTempFile(&quot;tmp&quot;, &quot;bin&quot;);461 * Files.write(file.toPath(), new byte[] {1, 1});462 *463 * // assertion will pass464 * assertThat(file).hasSize(2);465 *466 * // assertions will fail467 * assertThat(file).hasSize(1);</code></pre>468 *469 * @param expectedSizeInBytes the expected {@code File}'s size in bytes.470 * @return {@code this} assertion object.471 * @throws AssertionError if the actual {@code File} is {@code null}.472 * @throws AssertionError if the actual {@code File} is not an existing file.473 * @throws AssertionError if the size of the actual {@code File} is not equal to the given size.474 * @since 3.14.0475 */476 public SELF hasSize(long expectedSizeInBytes) {477 files.assertHasSizeInBytes(info, actual, expectedSizeInBytes);478 return myself;479 }480 /**481 * Specifies the name of the charset to use for text-based assertions on the file's contents.482 *483 * @param charsetName the name of the charset to use.484 * @return {@code this} assertion object.485 * @throws IllegalArgumentException if the given encoding is not supported on this platform.486 */487 @CheckReturnValue488 public SELF usingCharset(String charsetName) {489 checkArgument(Charset.isSupported(charsetName), "Charset:<'%s'> is not supported on this system", charsetName);490 return usingCharset(Charset.forName(charsetName));491 }492 /**493 * Specifies the charset to use for text-based assertions on the file's contents.494 *495 * @param charset the charset to use.496 * @return {@code this} assertion object.497 * @throws NullPointerException if the given charset is {@code null}.498 */499 @CheckReturnValue500 public SELF usingCharset(Charset charset) {501 this.charset = requireNonNull(charset, "The charset should not be null");502 return myself;503 }504 /**505 * Verifies that the text content of the actual {@code File} is <b>exactly</b> equal to the given one.<br>506 * The charset to use when reading the file should be provided with {@link #usingCharset(Charset)} or507 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by508 * {@link Charset#defaultCharset()}) will be used.509 * <p>510 * Example:511 * <pre><code class='java'> // use the default charset512 * File xFile = Files.write(Paths.get(&quot;xfile.txt&quot;), &quot;The Truth Is Out There&quot;.getBytes()).toFile();513 *514 * // The following assertion succeeds (default charset is used):515 * assertThat(xFile).hasContent(&quot;The Truth Is Out There&quot;);516 *517 * // The following assertion fails:518 * assertThat(xFile).hasContent(&quot;La Vérité Est Ailleurs&quot;);519 *520 * // using a specific charset521 * Charset turkishCharset = Charset.forName(&quot;windows-1254&quot;);522 *523 * File xFileTurkish = Files.write(Paths.get(&quot;xfile.turk&quot;), Collections.singleton(&quot;Gerçek&quot;), turkishCharset).toFile();524 *525 * // The following assertion succeeds:526 * assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent(&quot;Gerçek&quot;);527 *528 * // The following assertion fails :529 * assertThat(xFileTurkish).usingCharset(StandardCharsets.UTF_8).hasContent(&quot;Gerçek&quot;);</code></pre>530 *531 * @param expected the expected text content to compare the actual {@code File}'s content to.532 * @return {@code this} assertion object.533 * @throws NullPointerException if the given content is {@code null}.534 * @throws AssertionError if the actual {@code File} is {@code null}.535 * @throws AssertionError if the actual {@code File} is not an existing file.536 * @throws UncheckedIOException if an I/O error occurs.537 * @throws AssertionError if the content of the actual {@code File} is not equal to the given content.538 */539 public SELF hasContent(String expected) {540 files.assertHasContent(info, actual, expected, charset);541 return myself;542 }543 /**544 * Verifies that the actual {@code File} can be modified by the application.545 * <p>546 * Example:547 * <pre><code class='java'> File tmpFile = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);548 * File tmpDir = Files.createTempDirectory(&quot;tmp&quot;).toFile();549 *550 * // assertions will pass551 * assertThat(tmpFile).canWrite();552 * assertThat(tmpDir).canWrite();553 *554 * tmpFile.setReadOnly();555 * tmpDir.setReadOnly();556 *557 * // assertions will fail558 * assertThat(tmpFile).canWrite();559 * assertThat(tmpDir).canWrite();</code></pre>560 *561 * @return {@code this} assertion object.562 * @throws AssertionError if the actual {@code File} is {@code null}.563 * @throws AssertionError if the actual {@code File} can not be modified by the application.564 * @see #isWritable()565 */566 public SELF canWrite() {567 files.assertCanWrite(info, actual);568 return myself;569 }570 /**571 * Verifies that the actual {@code File} can be modified by the application (alias of {@link #canWrite()}.572 * <p>573 * Example:574 * <pre><code class='java'> File tmpFile = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);575 * File tmpDir = Files.createTempDirectory(&quot;tmp&quot;).toFile();576 *577 * // assertions will pass578 * assertThat(tmpFile).isWritable();579 * assertThat(tmpDir).isWritable();580 *581 * tmpFile.setReadOnly();582 * tmpDir.setReadOnly();583 *584 * // assertions will fail585 * assertThat(tmpFile).isWritable();586 * assertThat(tmpDir).isWritable();</code></pre>587 *588 * @return {@code this} assertion object.589 * @throws AssertionError if the actual {@code File} is {@code null}.590 * @throws AssertionError if the actual {@code File} can not be modified by the application.591 * @see #canWrite()592 * @since 3.21.0593 */594 public SELF isWritable() {595 return canWrite();596 }597 /**598 * Verifies that the actual {@code File} can be read by the application.599 * <p>600 * Example:601 * <pre><code class='java'> File tmpFile = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);602 * File tmpDir = Files.createTempDirectory(&quot;tmp&quot;).toFile();603 *604 * // assertions will pass605 * assertThat(tmpFile).canRead();606 * assertThat(tmpDir).canRead();607 *608 * tmpFile.setReadable(false);609 * tmpDir.setReadable(false);610 *611 * // assertions will fail612 * assertThat(tmpFile).canRead();613 * assertThat(tmpDir).canRead();</code></pre>614 *615 * @return {@code this} assertion object.616 * @throws AssertionError if the actual {@code File} is {@code null}.617 * @throws AssertionError if the actual {@code File} can not be read by the application.618 */619 public SELF canRead() {620 files.assertCanRead(info, actual);621 return myself;622 }623 /**624 * Verifies that the actual {@code File} has given parent.625 *626 * <p>627 * Example:628 * <pre><code class='java'> File xFile = new File(&quot;mulder/xFile&quot;);629 *630 * // assertion will pass631 * assertThat(xFile).hasParent(new File(&quot;mulder&quot;));632 *633 * // assertion will fail634 * assertThat(xFile).hasParent(new File(&quot;scully&quot;));</code></pre>635 *636 * @param expected the expected parent {@code File}.637 * @return {@code this} assertion object.638 * @throws NullPointerException if the expected parent {@code File} is {@code null}.639 * @throws UncheckedIOException if an I/O error occurs.640 * @throws AssertionError if the actual {@code File} is {@code null}.641 * @throws AssertionError if the actual {@code File} parent is not equal to the expected one.642 *643 * @see java.io.File#getParentFile() parent definition.644 */645 public SELF hasParent(File expected) {646 files.assertHasParent(info, actual, expected);647 return myself;648 }649 /**650 * Same as {@link #hasParent(java.io.File)} but takes care of converting given {@code String} as {@code File} for you651 *652 * <p>653 * Example:654 * <pre><code class='java'> File xFile = new File(&quot;mulder/xFile&quot;);655 *656 * // assertion will pass657 * assertThat(xFile).hasParent(&quot;mulder&quot;);658 *659 * // assertion will fail660 * assertThat(xFile).hasParent(&quot;scully&quot;);</code></pre>661 *662 * @param expected the expected parent file path.663 * @return {@code this} assertion object.664 */665 public SELF hasParent(String expected) {666 files.assertHasParent(info, actual, expected != null ? new File(expected) : null);667 return myself;668 }669 /**670 * Verifies that the actual {@code File} has given extension.671 *672 * <p>673 * Example:674 * <pre><code class='java'> File xFile = new File(&quot;xFile.java&quot;);675 *676 * // assertion will pass677 * assertThat(xFile).hasExtension(&quot;java&quot;);678 *679 * // assertion will fail680 * assertThat(xFile).hasExtension(&quot;png&quot;);</code></pre>681 *682 * @param expected the expected extension, it does not contains the {@code '.'}683 * @return {@code this} assertion object.684 * @throws NullPointerException if the expected extension is {@code null}.685 * @throws AssertionError if the actual {@code File} is {@code null}.686 * @throws AssertionError if the actual {@code File} is not a file (ie a directory).687 * @throws AssertionError if the actual {@code File} does not have the expected extension.688 *689 * @see <a href="http://en.wikipedia.org/wiki/Filename_extension">Filename extension</a>690 */691 public SELF hasExtension(String expected) {692 files.assertHasExtension(info, actual, expected);693 return myself;694 }695 /**696 * Verifies that the actual {@code File} has given name.697 *698 * <p>699 * Example:700 * <pre><code class='java'> File xFile = new File(&quot;somewhere/xFile.java&quot;);701 * File xDirectory = new File(&quot;somewhere/xDirectory&quot;);702 *703 * // assertion will pass704 * assertThat(xFile).hasName(&quot;xFile.java&quot;);705 * assertThat(xDirectory).hasName(&quot;xDirectory&quot;);706 *707 * // assertion will fail708 * assertThat(xFile).hasName(&quot;xFile&quot;);709 * assertThat(xDirectory).hasName(&quot;somewhere&quot;);</code></pre>710 *711 * @param expected the expected {@code File} name.712 * @return {@code this} assertion object.713 * @throws NullPointerException if the expected name is {@code null}.714 * @throws AssertionError if the actual {@code File} is {@code null}.715 * @throws AssertionError if the actual {@code File} does not have the expected name.716 *717 * @see java.io.File#getName() name definition.718 * @see #hasFileName(String)719 */720 public SELF hasName(String expected) {721 files.assertHasName(info, actual, expected);722 return myself;723 }724 /**725 * Verifies that the actual {@code File} has given name (alias of {@link #hasName(String)}).726 *727 * <p>728 * Example:729 * <pre><code class='java'> File xFile = new File(&quot;somewhere/xFile.java&quot;);730 * File xDirectory = new File(&quot;somewhere/xDirectory&quot;);731 *732 * // assertion will pass733 * assertThat(xFile).hasFileName(&quot;xFile.java&quot;);734 * assertThat(xDirectory).hasFileName(&quot;xDirectory&quot;);735 *736 * // assertion will fail737 * assertThat(xFile).hasFileName(&quot;xFile&quot;);738 * assertThat(xDirectory).hasFileName(&quot;somewhere&quot;);</code></pre>739 *740 * @param expected the expected {@code File} name.741 * @return {@code this} assertion object.742 * @throws NullPointerException if the expected name is {@code null}.743 * @throws AssertionError if the actual {@code File} is {@code null}.744 * @throws AssertionError if the actual {@code File} does not have the expected name.745 *746 * @see java.io.File#getName() name definition.747 * @see #hasName(String)748 * @since 3.21.0749 */750 public SELF hasFileName(String expected) {751 return hasName(expected);752 }753 /**754 * Verifies that the actual {@code File} does not have a parent.755 *756 * <p>757 * Example:758 * <pre><code class='java'> File xFile = new File(&quot;somewhere/xFile.java&quot;);759 * File xDirectory = new File(&quot;xDirectory&quot;);760 *761 * // assertion will pass762 * assertThat(xDirectory).hasNoParent();763 *764 * // assertion will fail765 * assertThat(xFile).hasNoParent();</code></pre>766 *767 * @return {@code this} assertion object.768 *769 * @throws AssertionError if the actual {@code File} is {@code null}.770 * @throws AssertionError if the actual {@code File} has a parent.771 */772 public SELF hasNoParent() {773 files.assertHasNoParent(info, actual);774 return myself;775 }776 /**777 * Verifies that the tested {@link File} digest (calculated with the specified {@link MessageDigest}) is equal to the given one.778 * <p>779 * Note that the {@link File} must be readable.780 * <p>781 * Examples:782 * <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.jar783 * File tested = new File("assertj-core-2.9.0.jar");784 *785 * // The following assertions succeed:786 * 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});787 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25});788 *789 * // The following assertions fail:790 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes());791 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f".getBytes()); </code></pre>792 *793 * @param digest the MessageDigest used to calculate the digests.794 * @param expected the expected binary content to compare the actual {@code File}'s content to.795 * @return {@code this} assertion object.796 * @throws NullPointerException if the given algorithm is {@code null}.797 * @throws NullPointerException if the given digest is {@code null}.798 * @throws AssertionError if the actual {@code File} is {@code null}.799 * @throws AssertionError if the actual {@code File} does not exist.800 * @throws AssertionError if the actual {@code File} is not an file.801 * @throws AssertionError if the actual {@code File} is not readable.802 * @throws UncheckedIOException if an I/O error occurs.803 * @throws AssertionError if the content of the tested {@code File}'s digest is not equal to the given one.804 * @since 3.11.0805 */806 public SELF hasDigest(MessageDigest digest, byte[] expected) {807 files.assertHasDigest(info, actual, digest, expected);808 return myself;809 }810 /**811 * Verifies that the tested {@link File} digest (calculated with the specified {@link MessageDigest}) is equal to the given one.812 * <p>813 * Note that the {@link File} must be readable.814 * <p>815 * Examples:816 * <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.jar817 * File tested = new File("assertj-core-2.9.0.jar");818 *819 * // The following assertions succeed:820 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "5c5ae45b58f12023817abe492447cdc7912c1a2c");821 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "dcb3015cd28447644c810af352832c19");822 *823 * // The following assertions fail:824 * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad");825 * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f"); </code></pre>826 *827 * @param digest the MessageDigest used to calculate the digests.828 * @param expected the expected binary content to compare the actual {@code File}'s content to.829 * @return {@code this} assertion object.830 * @throws NullPointerException if the given algorithm is {@code null}.831 * @throws NullPointerException if the given digest is {@code null}.832 * @throws AssertionError if the actual {@code File} is {@code null}.833 * @throws AssertionError if the actual {@code File} does not exist.834 * @throws AssertionError if the actual {@code File} is not an file.835 * @throws AssertionError if the actual {@code File} is not readable.836 * @throws UncheckedIOException if an I/O error occurs.837 * @throws AssertionError if the content of the tested {@code File}'s digest is not equal to the given one.838 * @since 3.11.0839 */840 public SELF hasDigest(MessageDigest digest, String expected) {841 files.assertHasDigest(info, actual, digest, expected);842 return myself;843 }844 /**845 * Verifies that the tested {@link File} digest (calculated with the specified algorithm) is equal to the given one.846 * <p>847 * Note that the {@link File} must be readable.848 * <p>849 * Examples:850 * <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.jar851 * File tested = new File("assertj-core-2.9.0.jar");852 *853 * // The following assertions succeed:854 * 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});855 * assertThat(tested).hasDigest("MD5", new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25});856 *857 * // The following assertions fail:858 * assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes());859 * assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f".getBytes()); </code></pre>860 *861 * @param algorithm the algorithm used to calculate the digests.862 * @param expected the expected digest to compare the actual {@code File}'s digest to.863 * @return {@code this} assertion object.864 * @throws NullPointerException if the given algorithm is {@code null}.865 * @throws NullPointerException if the given digest is {@code null}.866 * @throws AssertionError if the actual {@code File} is {@code null}.867 * @throws AssertionError if the actual {@code File} does not exist.868 * @throws AssertionError if the actual {@code File} is not an file.869 * @throws AssertionError if the actual {@code File} is not readable.870 * @throws UncheckedIOException if any I/O error occurs.871 * @throws AssertionError if the content of the tested {@code File}'s digest is not equal to the given one.872 * @since 3.11.0873 */874 public SELF hasDigest(String algorithm, byte[] expected) {875 files.assertHasDigest(info, actual, algorithm, expected);876 return myself;877 }878 /**879 * Verifies that the tested {@link File} digest (calculated with the specified algorithm) is equal to the given one.880 * <p>881 * Note that the {@link File} must be readable.882 * <p>883 * Examples:884 * <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.jar885 * File tested = new File("assertj-core-2.9.0.jar");886 *887 * // The following assertions succeed:888 * assertThat(tested).hasDigest("SHA1", "5c5ae45b58f12023817abe492447cdc7912c1a2c");889 * assertThat(tested).hasDigest("MD5", "dcb3015cd28447644c810af352832c19");890 *891 * // The following assertions fail:892 * assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad");893 * assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f"); </code></pre>894 *895 * @param algorithm the algorithm used to calculate the digests.896 * @param expected the expected digest to compare the actual {@code File}'s digest to.897 * @return {@code this} assertion object.898 * @throws NullPointerException if the given algorithm is {@code null}.899 * @throws NullPointerException if the given digest is {@code null}.900 * @throws AssertionError if the actual {@code File} is {@code null}.901 * @throws AssertionError if the actual {@code File} does not exist.902 * @throws AssertionError if the actual {@code File} is not an file.903 * @throws AssertionError if the actual {@code File} is not readable.904 * @throws UncheckedIOException if any I/O error occurs.905 * @throws AssertionError if the content of the tested {@code File}'s digest is not equal to the given one.906 * @since 3.11.0907 */908 public SELF hasDigest(String algorithm, String expected) {909 files.assertHasDigest(info, actual, algorithm, expected);910 return myself;911 }912 /**913 * Verify that the actual {@code File} is a directory containing at least one file matching the given {@code Predicate<File>}.914 * <p>915 * Note that the actual {@link File} must exist and be a directory.916 * <p>917 * Given the following directory structure:918 * <pre><code class="text"> /root/919 * /root/sub-dir-1/920 * /root/sub-dir-1/file-1.ext921 * /root/sub-dir-1/file-2.ext922 * /root/sub-file-1.ext923 * /root/sub-file-2.ext</code></pre>924 *925 * Here are some assertions examples:926 * <pre><code class="java"> File root = new File("root");927 *928 * // The following assertions succeed:929 * assertThat(root).isDirectoryContaining(file -&gt; file.getName().startsWith("sub-dir"))930 * .isDirectoryContaining(file -&gt; file.getName().startsWith("sub-file"))931 * .isDirectoryContaining(file -&gt; file.getName().endsWith(".ext"))932 * .isDirectoryContaining(File::isDirectory);933 *934 * // The following assertions fail:935 * assertThat(root).isDirectoryContaining(file -&gt; file.getName().startsWith("dir"));936 * assertThat(root).isDirectoryContaining(file -&gt; file.getName().endsWith(".bin")); </code></pre>937 *938 * @param filter the filter for files located inside {@code actual}'s directory.939 * @return {@code this} assertion object.940 * @throws NullPointerException if the given filter is {@code null}.941 * @throws AssertionError if actual is {@code null}.942 * @throws AssertionError if actual does not exist.943 * @throws AssertionError if actual is not a directory.944 * @throws AssertionError if actual does not contain any files matching the given predicate.945 * @since 3.13.0946 */947 public SELF isDirectoryContaining(Predicate<File> filter) {948 files.assertIsDirectoryContaining(info, actual, filter);949 return myself;950 }951 /**952 * Verify that the actual {@code File} is a directory containing at least one file matching the given {@code String}953 * interpreted as a path matcher (as per {@link FileSystem#getPathMatcher(String)}).954 * <p>955 * Note that the actual {@link File} must exist and be a directory.956 * <p>957 * Given the following directory structure:958 * <pre><code class="text"> /root/959 * /root/sub-dir-1/960 * /root/sub-dir-1/file-1.ext961 * /root/sub-dir-1/file-2.ext962 * /root/sub-file-1.ext963 * /root/sub-file-2.ext</code></pre>964 *965 * Here are some assertions examples:966 * <pre><code class="java"> File root = new File("root");967 *968 * // The following assertions succeed:969 * assertThat(root).isDirectoryContaining("glob:**sub-dir*")970 * .isDirectoryContaining("glob:**sub-file*")971 * .isDirectoryContaining("glob:**.ext")972 * .isDirectoryContaining("regex:.*ext")973 * .isDirectoryContaining("glob:**.{ext,bin");974 *975 * // The following assertions fail:976 * assertThat(root).isDirectoryContaining("glob:**dir");977 * assertThat(root).isDirectoryContaining("glob:**.bin");978 * assertThat(root).isDirectoryContaining("glob:**.{java,class}"); </code></pre>979 *980 * @param syntaxAndPattern the syntax and pattern for {@link java.nio.file.PathMatcher} as described in {@link FileSystem#getPathMatcher(String)}.981 * @return {@code this} assertion object.982 * @throws NullPointerException if the given syntaxAndPattern is {@code null}.983 * @throws AssertionError if actual is {@code null}.984 * @throws AssertionError if actual does not exist.985 * @throws AssertionError if actual is not a directory.986 * @throws AssertionError if actual does not contain any files matching the given path matcher.987 * @see FileSystem#getPathMatcher(String)988 * @since 3.13.0989 */990 public SELF isDirectoryContaining(String syntaxAndPattern) {991 files.assertIsDirectoryContaining(info, actual, syntaxAndPattern);992 return myself;993 }994 /**995 * Verify that the actual {@code File} directory or any of its subdirectories (recursively) contains at least one file996 * matching the given {@code String} interpreted as a path matcher (as per {@link FileSystem#getPathMatcher(String)}).997 * <p>998 * That methods performs the same assertion as {@link #isDirectoryContaining(String syntaxAndPattern)} but recursively.999 * <p>1000 * Note that the actual {@link File} must exist and be a directory.1001 * <p>1002 * Examples given the following directory structure:1003 * <pre><code class="text"> root1004 * |—— foo1005 * | |—— foobar1006 * | |—— foo-file-1.ext1007 * |—— foo-file-2.ext</code>1008 * </pre>1009 *1010 * <pre><code class="java"> File root = new File("root");1011 *1012 * // The following assertions succeed:1013 * assertThat(root).isDirectoryRecursivelyContaining("glob:**foo")1014 * .isDirectoryRecursivelyContaining("glob:**ooba*")1015 * .isDirectoryRecursivelyContaining("glob:**file-1.ext")1016 * .isDirectoryRecursivelyContaining("regex:.*file-2.*")1017 * .isDirectoryRecursivelyContaining("glob:**.{ext,dummy}");1018 *1019 * // The following assertions fail:1020 * assertThat(root).isDirectoryRecursivelyContaining("glob:**fooba");1021 * assertThat(root).isDirectoryRecursivelyContaining("glob:**.bin");1022 * assertThat(root).isDirectoryRecursivelyContaining("glob:**.{java,class}"); </code></pre>1023 *1024 * @param syntaxAndPattern the syntax and pattern for {@link java.nio.file.PathMatcher} as described in {@link FileSystem#getPathMatcher(String)}.1025 * @return {@code this} assertion object.1026 * @throws NullPointerException if the given syntaxAndPattern is {@code null}.1027 * @throws AssertionError if actual is {@code null}.1028 * @throws AssertionError if actual does not exist.1029 * @throws AssertionError if actual is not a directory.1030 * @throws AssertionError if actual does not contain recursively any files matching the given path matcher.1031 * @see FileSystem#getPathMatcher(String)1032 * @since 3.16.01033 */1034 public SELF isDirectoryRecursivelyContaining(String syntaxAndPattern) {1035 files.assertIsDirectoryRecursivelyContaining(info, actual, syntaxAndPattern);1036 return myself;1037 }1038 /**1039 * Verify that the actual {@code File} directory or any of its subdirectories (recursively) contains at least one file1040 * matching the given {@code Predicate<File>}.1041 * <p>1042 * That methods performs the same assertion as {@link #isDirectoryContaining(Predicate filter)} but recursively.1043 * <p>1044 * Note that the actual {@link File} must exist and be a directory.1045 * <p>1046 * Examples given the following directory structure:1047 * <pre><code class="text"> root1048 * |—— foo1049 * | |—— foobar1050 * | |—— foo-file-1.ext1051 * |—— foo-file-2.ext</code>1052 * </pre>1053 *1054 * Here are some assertions examples:1055 * <pre><code class="java"> File root = new File("root");1056 *1057 * // The following assertions succeed:1058 * assertThat(root).isDirectoryRecursivelyContaining(file -&gt; file.getName().startsWith("foo-file-1"))1059 * .isDirectoryRecursivelyContaining(file -&gt; file.getName().endsWith("file-2.ext"))1060 * .isDirectoryRecursivelyContaining(file -&gt; file.getName().equals("foo"))1061 * .isDirectoryRecursivelyContaining(file -&gt; file.getParentFile().getName().equals("foo"))1062 *1063 * // The following assertions fail:1064 * assertThat(root).isDirectoryRecursivelyContaining(file -&gt; file.getName().equals("foo-file-1"))1065 * assertThat(root).isDirectoryRecursivelyContaining(file -&gt; file.getName().equals("foo/foobar")); </code></pre>1066 *1067 * @param filter the filter for files located inside {@code actual}'s directory.1068 * @return {@code this} assertion object.1069 * @throws NullPointerException if the given filter is {@code null}.1070 * @throws AssertionError if actual is {@code null}.1071 * @throws AssertionError if actual does not exist.1072 * @throws AssertionError if actual is not a directory.1073 * @throws AssertionError if actual does not contain recursively any files matching the given predicate.1074 * @since 3.16.01075 */1076 public SELF isDirectoryRecursivelyContaining(Predicate<File> filter) {1077 files.assertIsDirectoryRecursivelyContaining(info, actual, filter);1078 return myself;1079 }1080 /**1081 * Verify that the actual {@code File} is a directory that does not contain any files matching the given {@code Predicate<File>}.1082 * <p>1083 * Note that the actual {@link File} must exist and be a directory.1084 * <p>1085 * Given the following directory structure:1086 * <pre><code class="text"> /root/1087 * /root/sub-dir-1/1088 * /root/sub-dir-1/file-1.ext1089 * /root/sub-dir-1/file-2.ext1090 * /root/sub-file-1.ext1091 * /root/sub-file-2.ext</code></pre>1092 *1093 * Here are some assertions examples:1094 * <pre><code class="java"> File root = new File("root");1095 *1096 * // The following assertions succeed:1097 * assertThat(root).isDirectoryNotContaining(file -&gt; file.getName().startsWith("dir"))1098 * .isDirectoryNotContaining(file -&gt; file.getName().endsWith(".bin"));1099 *1100 * // The following assertions fail:1101 * assertThat(root).isDirectoryNotContaining(file -&gt; file.getName().startsWith("sub-dir"));1102 * assertThat(root).isDirectoryNotContaining(file -&gt; file.getName().startsWith("sub-file"));1103 * assertThat(root).isDirectoryNotContaining(file -&gt; file.getName().endsWith(".ext"));1104 * assertThat(root).isDirectoryNotContaining(File::isDirectory); </code></pre>1105 *1106 * @param filter the filter for files located inside {@code actual}'s directory.1107 * @return {@code this} assertion object.1108 * @throws NullPointerException if the given filter is {@code null}.1109 * @throws AssertionError if actual is {@code null}.1110 * @throws AssertionError if actual does not exist.1111 * @throws AssertionError if actual is not a directory.1112 * @throws AssertionError if actual contains a file matching the given predicate.1113 * @since 3.13.01114 */1115 public SELF isDirectoryNotContaining(Predicate<File> filter) {1116 files.assertIsDirectoryNotContaining(info, actual, filter);1117 return myself;1118 }1119 /**1120 * Verify that the actual {@code File} is a directory that does not contain any files matching the given {@code String}1121 * interpreted as a path matcher (as per {@link FileSystem#getPathMatcher(String)}).1122 * <p>1123 * Note that the actual {@link File} must exist and be a directory.1124 * <p>1125 * Given the following directory structure:1126 * <pre><code class="text"> /root/1127 * /root/sub-dir-1/1128 * /root/sub-dir-1/file-1.ext1129 * /root/sub-dir-1/file-2.ext1130 * /root/sub-file-1.ext1131 * /root/sub-file-2.ext</code></pre>1132 *1133 * Here are some assertions examples:1134 * <pre><code class="java"> File root = new File("root");1135 *1136 * // The following assertions succeed:1137 * assertThat(root).isDirectoryNotContaining("glob:**dir")1138 * .isDirectoryNotContaining("glob:**.bin")1139 * .isDirectoryNotContaining("regex:.*bin")1140 * .isDirectoryNotContaining("glob:**.{java,class}");1141 *1142 * // The following assertions fail:1143 * assertThat(root).isDirectoryNotContaining("glob:**sub-dir*");1144 * assertThat(root).isDirectoryNotContaining("glob:**sub-file*");1145 * assertThat(root).isDirectoryNotContaining("glob:**.ext");1146 * assertThat(root).isDirectoryNotContaining("regex:.*ext");1147 * assertThat(root).isDirectoryNotContaining("glob:**.{ext,bin"); </code></pre>1148 *1149 * @param syntaxAndPattern the syntax and pattern for {@link java.nio.file.PathMatcher} as described in {@link FileSystem#getPathMatcher(String)}.1150 * @return {@code this} assertion object.1151 * @throws NullPointerException if the given syntaxAndPattern is {@code null}.1152 * @throws AssertionError if actual is {@code null}.1153 * @throws AssertionError if actual does not exist.1154 * @throws AssertionError if actual is not a directory.1155 * @throws AssertionError if actual contains a file matching the given path matcher.1156 * @see FileSystem#getPathMatcher(String)1157 * @since 3.13.01158 */1159 public SELF isDirectoryNotContaining(String syntaxAndPattern) {1160 files.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);1161 return myself;1162 }1163 /**1164 * Verify that the actual {@code File} is an empty directory.1165 * <p>1166 * Note that the actual {@link File} must exist and be a directory.1167 * <p>1168 * Given the following directory structure:1169 * <pre><code class="text"> /root/1170 * /root/sub-dir-1/1171 * /root/sub-dir-1/file-1.ext1172 * /root/sub-dir-1/file-2.ext1173 * /root/sub-dir-2/1174 * /root/sub-file-1.ext1175 * /root/sub-file-2.ext</code></pre>1176 *1177 * Here are some assertions examples:1178 * <pre><code class="java"> File root = new File("root");1179 *1180 * // The following assertion succeeds:1181 * assertThat(new File(root, "sub-dir-2")).isEmptyDirectory();1182 *1183 * // The following assertions fail:1184 * assertThat(root).isEmptyDirectory();1185 * assertThat(new File(root, "sub-dir-1")).isEmptyDirectory(); </code></pre>1186 *1187 * @return {@code this} assertion object.1188 * @throws AssertionError if actual is {@code null}.1189 * @throws AssertionError if actual does not exist.1190 * @throws AssertionError if actual is not a directory.1191 * @throws AssertionError if actual is not empty.1192 * @since 3.13.01193 */1194 public SELF isEmptyDirectory() {1195 files.assertIsEmptyDirectory(info, actual);1196 return myself;1197 }1198 /**1199 * Verify that the actual {@code File} is a non empty directory.1200 * <p>1201 * Note that the actual {@link File} must exist and be a directory.1202 * <p>1203 * Given the following directory structure:1204 * <pre><code class="text"> /root/1205 * /root/sub-dir-1/1206 * /root/sub-dir-1/file-1.ext1207 * /root/sub-dir-1/file-2.ext1208 * /root/sub-dir-2/1209 * /root/sub-file-1.ext1210 * /root/sub-file-2.ext</code></pre>1211 *1212 * Here are some assertions examples:1213 * <pre><code class="java"> File root = new File("root");1214 *1215 * // The following assertions succeed:1216 * assertThat(root).isNotEmptyDirectory();1217 * assertThat(new File(root, "sub-dir-1")).isNotEmptyDirectory();1218 *1219 * // The following assertions fail:1220 * assertThat(new File(root, "sub-dir-2")).isNotEmptyDirectory(); </code></pre>1221 *1222 * @return {@code this} assertion object.1223 * @throws AssertionError if actual is {@code null}.1224 * @throws AssertionError if actual does not exist.1225 * @throws AssertionError if actual is not a directory.1226 * @throws AssertionError if actual is empty.1227 * @since 3.13.01228 */1229 public SELF isNotEmptyDirectory() {1230 files.assertIsNotEmptyDirectory(info, actual);1231 return myself;1232 }1233 /**1234 * Verify that the actual {@code File} is empty (i.e. the file size = 0).1235 * <p>1236 * Example:1237 * <pre><code class='java'> File file = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);1238 *1239 * // assertion will pass1240 * assertThat(file).isEmpty();1241 *1242 * Files.write(file.toPath(), new byte[]{1, 1});1243 *1244 * // assertion will fail1245 * assertThat(file).isEmpty();</code></pre>1246 *1247 * @return {@code this} assertion object.1248 * @throws AssertionError if the actual {@code File} is {@code null}.1249 * @throws AssertionError if the actual {@code File} does not exist.1250 * @throws AssertionError if the actual {@code File} is not empty.1251 * @since 3.14.01252 */1253 public SELF isEmpty() {1254 files.assertIsEmptyFile(info, actual);1255 return myself;1256 }1257 /**1258 * Verify that the actual {@code File} is not empty (i.e. the file size &gt; 0).1259 * <p>1260 * Example:1261 * <pre><code class='java'> File file = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);1262 * Files.write(file.toPath(), new byte[]{1, 1});1263 *1264 * // assertion will pass1265 * assertThat(file).isNotEmpty();1266 *1267 * file = File.createTempFile(&quot;tmp&quot;, &quot;txt&quot;);1268 *1269 * // assertion will fail1270 * assertThat(file).isNotEmpty();</code></pre>1271 *1272 * @return {@code this} assertion object.1273 * @throws AssertionError if the actual {@code File} is {@code null}.1274 * @throws AssertionError if the actual {@code File} does not exist.1275 * @throws AssertionError if the actual {@code File} is empty.1276 * @since 3.14.01277 */1278 public SELF isNotEmpty() {1279 files.assertIsNotEmptyFile(info, actual);1280 return myself;1281 }1282 /**1283 * Returns {@code ByteArray} assertions on the content of the actual {@code File} read.1284 * <p>1285 * Example:1286 * <pre><code class='java'> File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();1287 *1288 * // assertion succeeds1289 * assertThat(xFile).binaryContent().isEqualTo("The Truth Is Out There".getBytes());1290 *1291 * // assertion fails:1292 * assertThat(xFile).binaryContent().isEqualTo("Elsewhere".getBytes());</code></pre>1293 *1294 * @return a {@link AbstractByteArrayAssert} object with the binary content of the file.1295 * @throws AssertionError if the actual {@code File} is not readable as per {@link java.nio.file.Files#isReadable(java.nio.file.Path)}.1296 * @throws UncheckedIOException when failing to read the actual {@code File}.1297 */1298 public AbstractByteArrayAssert<?> binaryContent() {1299 files.assertCanRead(info, actual);1300 return new ByteArrayAssert(readFile()).withAssertionState(myself);1301 }1302 /**1303 * Returns String assertions on the content of the actual {@code File} read with the {@link Charset#defaultCharset() default charset}.1304 * <p>1305 * Example:1306 * <pre><code class='java'> File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();1307 *1308 * // assertion succeeds (default charset is used to read xFile content):1309 * assertThat(xFile).content().startsWith("The Truth Is ");...

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1File file = new File("test.txt");2assertThat(file).isReadable();3File file = new File("test.txt");4assertThat(file).isReadable();5package org.journaldev.junit;6import static org.assertj.core.api.Assertions.assertThat;7import java.io.File;8import org.junit.Test;9public class AssertJFileAssertTest {10 public void testIsReadable() {11 File file = new File("test.txt");12 assertThat(file).isReadable();13 }14}15package org.journaldev.junit;16import static org.assertj.core.api.Assertions.assertThat;17import java.io.File;18import org.junit.Test;19public class AssertJFileAssertTest {20 public void testIsReadable() {21 File file = new File("test.txt");22 assertThat(file).isReadable();23 }24}25 at org.journaldev.junit.AssertJFileAssertTest.testIsReadable(AssertJFileAssertTest.java:12)

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.junit5;2import static org.assertj.core.api.Assertions.assertThat;3import java.io.File;4import org.junit.jupiter.api.Test;5public class ReadableFileTest {6 public void testIsReadableFile() {7 File readableFile = new File("src/test/resources/readableFile.txt");8 assertThat(readableFile).isReadable();9 }10}11package com.automationrhapsody.junit5;12import static org.assertj.core.api.Assertions.assertThat;13import java.io.File;14import org.junit.jupiter.api.Test;15public class NotReadableFileTest {16 public void testIsNotReadableFile() {17 File notReadableFile = new File("src/test/resources/notReadableFile.txt");18 assertThat(notReadableFile).isNotReadable();19 }20}21package com.automationrhapsody.junit5;22import static org.assertj.core.api.Assertions.assertThat;23import java.io.File;24import org.junit.jupiter.api.Test;25public class WritableFileTest {26 public void testIsWritableFile() {27 File writableFile = new File("src/test/resources/writableFile.txt");28 assertThat(writableFile).isWritable();29 }30}31package com.automationrhapsody.junit5;32import static org.assertj.core.api.Assertions.assertThat;33import java.io.File;34import org.junit.jupiter.api.Test;35public class NotWritableFileTest {36 public void testIsNotWritableFile() {37 File notWritableFile = new File("src/test/resources/notWritableFile.txt");38 assertThat(notWritableFile).isNotWritable();39 }40}41package com.automationrhapsody.junit5;42import static org.assertj.core.api.Assertions.assertThat;43import java.io.File;44import org.junit.jupiter.api.Test;45public class ExecutableFileTest {46 public void testIsExecutableFile() {47 File executableFile = new File("src/test/resources/executableFile.txt");48 assertThat(executableFile).isExecutable();49 }

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.api.AbstractFileAssert;3import java.io.File;4public class Test {5 public static void main(String[] args) {6 File file = new File("Test.java");7 AbstractFileAssert<?> abc = Assertions.assertThat(file);8 abc.isReadable();9 }10}11at org.assertj.core.api.AbstractFileAssert.isReadable(AbstractFileAssert.java:124)12at Test.main(Test.java:10)13import org.assertj.core.api.Assertions;14import org.assertj.core.api.AbstractFileAssert;15import java.io.File;16public class Test {17 public static void main(String[] args) {18 File file = new File("Test.java");19 AbstractFileAssert<?> abc = Assertions.assertThat(file);20 abc.isReadable();21 }22}23at org.assertj.core.api.AbstractFileAssert.isReadable(AbstractFileAssert.java:124)24at Test.main(Test.java:10)25import org.assertj.core.api.Assertions;26import org.assertj.core.api.AbstractFileAssert;27import java.io.File;28public class Test {29 public static void main(String[] args) {30 File file = new File("Test.java");31 AbstractFileAssert<?> abc = Assertions.assertThat(file);32 abc.isReadable();33 }34}35at org.assertj.core.api.AbstractFileAssert.isReadable(AbstractFileAssert.java:124)36at Test.main(Test.java:10)

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.api.AbstractFileAssert;3import java.io.File;4public class Test {5 public static void main(String[] args) {6 File file = new File("Test.java");7 AbstractFileAssert<?> abc = Assertions.assertThat(file);8 abc.isReadable();9 }10}11at org.assertj.core.api.AbstractFileAssert.isReadable(AbstractFileAssert.java:124)12at Test.main(Test.java:10)13import org.assertj.core.api.Assertions;14import org.assertj.core.api.AbstractFileAssert;15import java.io.File;16public class Test {17 public static void main(String[] args) {18 File file = new File("Test.java");19 AbstractFileAssert<?> abc = Assertions.assertThat(file);20 abc.isReadable();21 }22}23at org.assertj.core.api.AbstractFileAssert.isReadable(AbstractFileAssert.java:124)24at Test.main(Test.java:10)25import org.assertj.core.api.Assertions;26import org.assertj.core.api.AbstractFileAssert;27import java.io.File;28public class Test {29 public static void main(String[] args) {30 File file = new File("Test.java");31 AbstractFileAssert<?> abc = Assertions.assertThat(file);32 abc.isReadable();33 }34}35at org.assertj.core.api.AbstractFileAssert.isReadable(AbstractFileAssert.java:124)36at Test.main(Test.java:10)

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import java.io.File;3public class JavaFileAssertDemo {4 public static void main(String[] args) {5 File file = new File("C:\\Users\\Public\\Desktop\\1.txt");6 assertThat(file).isReadable();7 }8}9assertThat(File file).isWritable();10import static org.assertj.core.api.Assertions.*;11import java.io.File;12public class JavaFileAssertDemo {13 public static void main(String[] args) {14 File file = new File("C:\\Users\\Public\\Desktop\\1.txt");15 assertThat(file).isWritable();16 }17}18assertThat(File file).hasName(String name);19import static org.assertj.core.api.Assertions.*;20import java.io.File;21public class JavaFileAssertDemo {22 public static void main(String[] args) {23 File file = new File("C:\\Users\\Public\\Desktop\\1.txt");24 assertThat(file).hasName("1.txt");25 }26}

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import java.io.File;3public class JavaFileAssertDemo {4 public static void main(String[] args) {5 File file = new File("C:\\Users\\Public\\Desktop\\1.txt");6 assertThat(file).isReadable();7 }8}

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1mport org.juit.Test;2import static or.assertj.core.apiAssertions.assertThat;3import java.io.File;4import java.io.IOException;5public class FileTest {6 public void test1() throws IOException {7 File file = new File("test.txt");8 if (!file.exists()) {9 file.createNewFile();10 }11 assertThat(file).isReadable();12 }13}14assertThat(File file).isWritable();15import static org.assertj.core.api.Assertions.*;16import java.io.File;17public class JavaFileAssertDemo {18 public static void main(String[] args) {19 File file = new File("C:\\Users\\Public\\Desktop\\1.txt");20 assertThat(file).isWritable();21 }22}23assertThat(File file).hasName(String name);24import static org.assertj.core.api.Assertions.*;25import java.io.File;26public class JavaFileAssertDemo {27 public static void main(String[] args) {28 File file = new File("C:\\Users\\Public\\Desktop\\1.txt");29 assertThat(file).hasName("1.txt");30 }31}

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1public class AssertJFileAssertTest {2 public static void main(String[] args) {3 File file = new File("C:\\Users\\Saurabh\\Documents\\test.txt");4 assertThat(file).isReadable();5 }6}7 public static void main(String[] args) {8 File file = new File("C:\\Users\\admin\\Desktop\\test.txt");9 assertThat(file).isReadable();10 }11}

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1public class FileAssertIsReadable_Test {2 public void testIsReadable() {3 File file = new File("C:\\Users\\user\\Desktop\\test.txt");4 assertThat(file).isReadable();5 }6}7 at FileAssertIsReadable_Test.testIsReadable(FileAssertIsReadable_Test.java:10)8test.txt NT AUTHORITY\SYSTEM:(I)(F)9 NT AUTHORITY\SYSTEM:(I)(OI)(CI)(IO)(F)10 BUILTIN\Administrators:(I)(OI)(CI)(F)11 BUILTIN\Administrators:(I)(CI)(IO)(F)12 NT AUTHORITY\SYSTEM:(I)(F)13 NT AUTHORITY\SYSTEM:(I)(OI)(CI)(IO)(F)14 BUILTIN\Administrators:(I)(OI)(CI)(F)15 BUILTIN\Administrators:(I)(CI)(IO)(F)16 BUILTIN\Users:(I)(OI)(CI)(RX)17 BUILTIN\Users:(I)(CI)(AD)18 BUILTIN\Users:(I)(CI)(WD)19Successfully processed 1 files; Failed processing 0 files20[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ FileAssertIsReadable ---

Full Screen

Full Screen

isReadable

Using AI Code Generation

copy

Full Screen

1public class AssertJFileAssertTest {2 public static void main(String[] args) {3 File file = new File("C:\\Users\\Saurabh\\Documents\\test.txt");4 assertThat(file).isReadable();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