Best Assertj code snippet using org.assertj.core.api.AbstractPathAssert.isSymbolicLink
Source:AssertJAssertions.java
...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; }1905 public AbstractPathAssert hasParentRaw(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }1906 public AbstractPathAssert hasNoParent() { return (AbstractPathAssert) (Object) null; }1907 public AbstractPathAssert hasNoParentRaw() { return (AbstractPathAssert) (Object) null; }1908 public AbstractPathAssert startsWith(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }1909 public AbstractPathAssert startsWithRaw(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }1910 public AbstractPathAssert endsWith(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }1911 public AbstractPathAssert endsWithRaw(java.nio.file.Path p0) { return (AbstractPathAssert) (Object) null; }1912 public AbstractPathAssert hasDigest(java.security.MessageDigest p0, byte[] p1) { return (AbstractPathAssert) (Object) null; }...
Source:AbstractPathAssert.java
...37 * </p>38 *39 * <p>40 * Canonicalization may lead to an I/O error if a path does not exist, in which case the given assertions will fail with41 * a {@link PathsException}. Also note that {@link Files#isSymbolicLink(Path) symbolic links} will be followed if the42 * filesystem supports them. Finally, if a path is not {@link Path#isAbsolute() absolute}, canonicalization will43 * resolve the path against the process' current working directory.44 * </p>45 *46 * <p>47 * These assertions are filesystem independent. You may use them on {@code Path} instances issued from the default48 * filesystem (ie, instances you get when using {@link java.nio.file.Paths#get(String, String...)}) or from other49 * filesystems. For more information, see the {@link FileSystem javadoc for {@code FileSystem} .50 * </p>51 *52 * <p>53 * Furthermore:54 * </p>55 *56 * <ul>57 * <li>Unless otherwise noted, assertions which accept arguments will not accept {@code null} arguments; if a null58 * argument is passed, these assertions will throw a {@link NullPointerException}.</li>59 * <li>It is the caller's responsibility to ensure that paths used in assertions are issued from valid filesystems which60 * are not {@link FileSystem#close() closed}. If a filesystems is closed, assertions will throw a61 * {@link ClosedFileSystemException}.</li>62 * <li>Some assertions take another {@link Path} as an argument. If this path is not issued from the same63 * {@link FileSystemProvider provider} as the tested path, assertions will throw a {@link ProviderMismatchException}.</li>64 * <li>Some assertions may need to perform I/O on the path's underlying filesystem; if an I/O error occurs when65 * accessing the filesystem, these assertions will throw a {@link PathsException}.</li>66 * </ul>67 *68 * @param <S> self type69 *70 * @see Path71 * @see java.nio.file.Paths#get(String, String...)72 * @see FileSystem73 * @see FileSystem#getPath(String, String...)74 * @see FileSystems#getDefault()75 * @see Files76 */77public abstract class AbstractPathAssert<S extends AbstractPathAssert<S>> extends AbstractComparableAssert<S, Path> {78 @VisibleForTesting79 protected Paths paths = Paths.instance();80 @VisibleForTesting81 Charset charset = Charset.defaultCharset();82 protected AbstractPathAssert(final Path actual, final Class<?> selfType) {83 super(actual, selfType);84 }85 /**86 * Verifies that the content of the actual {@code Path} is the same as the given one (both paths must be a readable87 * files). The default charset is used to read each files.88 * 89 * Examples:90 * <pre><code class="java"> // use the default charset91 * Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());92 * Path xFileClone = Files.write(Paths.get("xfile-clone.txt"), "The Truth Is Out There".getBytes());93 * Path xFileFrench = Files.write(Paths.get("xfile-french.txt"), "La Vérité Est Ailleurs".getBytes());94 * 95 * // The following assertion succeeds (default charset is used):96 * assertThat(xFile).hasSameContentAs(xFileClone);97 * 98 * // The following assertion fails:99 * assertThat(xFile).hasSameContentAs(xFileFrench);</code></pre>100 * 101 * @param expected the given {@code Path} to compare the actual {@code Path} to.102 * @return {@code this} assertion object.103 * @throws NullPointerException if the given {@code Path} is {@code null}.104 * @throws AssertionError if the actual or given {@code Path} is not an existing readable file.105 * @throws AssertionError if the actual {@code Path} is {@code null}.106 * @throws AssertionError if the content of the actual {@code Path} is not equal to the content of the given one.107 * @throws PathsException if an I/O error occurs.108 */109 public S hasSameContentAs(Path expected) {110 paths.assertHasSameContentAs(info, actual, expected);111 return myself;112 }113 /**114 * Verifies that the binary content of the actual {@code Path} is <b>exactly</b> equal to the given one.115 *116 * Examples:117 * <pre><code class="java"> // using the default charset, the following assertion succeeds:118 * Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());119 * assertThat(xFile).hasBinaryContent("The Truth Is Out There".getBytes());120 *121 * // using a specific charset 122 * Charset turkishCharset = Charset.forName("windows-1254");123 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek BaÅka bir yerde mi"), turkishCharset);124 * 125 * // The following assertion succeeds:126 * String expectedContent = "Gerçek BaÅka bir yerde mi" + org.assertj.core.util.Compatibility.System.lineSeparator();127 * byte[] binaryContent = expectedContent.getBytes(turkishCharset.name());128 * assertThat(xFileTurkish).hasBinaryContent(binaryContent);129 * 130 * // The following assertion fails ... unless you are in Turkey ;-):131 * assertThat(xFileTurkish).hasBinaryContent("Gerçek BaÅka bir yerde mi".getBytes());</code></pre>132 * 133 * @param expected the expected binary content to compare the actual {@code File}'s content to.134 * @return {@code this} assertion object.135 * @throws NullPointerException if the given content is {@code null}.136 * @throws AssertionError if the actual {@code File} is {@code null}.137 * @throws AssertionError if the actual {@code File} is not an existing file.138 * @throws RuntimeIOException if an I/O error occurs.139 * @throws AssertionError if the content of the actual {@code File} is not equal to the given binary content.140 */141 public S hasBinaryContent(byte[] expected) {142 paths.assertHasBinaryContent(info, actual, expected);143 return myself;144 }145 /**146 * Specifies the name of the charset to use for text-based assertions on the path's contents (path must be a readable147 * file).148 * 149 * Examples:150 * <pre><code class="java"> Charset turkishCharset = Charset.forName("windows-1254");151 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek BaÅka bir yerde mi"), turkishCharset);152 * 153 * // The following assertion succeeds:154 * assertThat(xFileTurkish).usingCharset("windows-1254").hasContent("Gerçek BaÅka bir yerde mi");</code></pre>155 * 156 * @param charsetName the name of the charset to use.157 * @return {@code this} assertion object.158 * @throws IllegalArgumentException if the given encoding is not supported on this platform.159 */160 public S usingCharset(String charsetName) {161 if (!Charset.isSupported(charsetName))162 throw new IllegalArgumentException(format("Charset:<'%s'> is not supported on this system", charsetName));163 return usingCharset(Charset.forName(charsetName));164 }165 /**166 * Specifies the charset to use for text-based assertions on the path's contents (path must be a readable file).167 * 168 * Examples:169 * <pre><code class="java"> Charset turkishCharset = Charset.forName("windows-1254");170 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek BaÅka bir yerde mi"), turkishCharset);171 * 172 * // The following assertion succeeds:173 * assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent("Gerçek BaÅka bir yerde mi");</code></pre>174 * 175 * @param charset the charset to use.176 * @return {@code this} assertion object.177 * @throws NullPointerException if the given charset is {@code null}.178 */179 public S usingCharset(Charset charset) {180 this.charset = checkNotNull(charset, "The charset should not be null");181 return myself;182 }183 /**184 * Verifies that the text content of the actual {@code Path} (which must be a readable file) is <b>exactly</b> equal185 * to the given one.<br/>186 * The charset to use when reading the file should be provided with {@link #usingCharset(Charset)} or187 * {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by188 * {@link Charset#defaultCharset()}) will be used.189 * 190 * Examples:191 * <pre><code class="java"> // use the default charset192 * Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());193 * 194 * // The following assertion succeeds (default charset is used):195 * assertThat(xFile).hasContent("The Truth Is Out There");196 * 197 * // The following assertion fails:198 * assertThat(xFile).hasContent("La Vérité Est Ailleurs");199 * 200 * // using a specific charset 201 * Charset turkishCharset = Charset.forName("windows-1254");202 * 203 * Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek BaÅka bir yerde mi"), turkishCharset);204 * 205 * // The following assertion succeeds:206 * assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent("Gerçek BaÅka bir yerde mi");207 * 208 * // The following assertion fails ... unless you are in Turkey ;-):209 * assertThat(xFileTurkish).hasContent("Gerçek BaÅka bir yerde mi");</code></pre>210 *211 * @param expected the expected text content to compare the actual {@code File}'s content to.212 * @return {@code this} assertion object.213 * @throws NullPointerException if the given content is {@code null}.214 * @throws RuntimeIOException if an I/O error occurs.215 * @throws AssertionError if the actual {@code Path} is {@code null}.216 * @throws AssertionError if the actual {@code Path} is not a {@link Files#isReadable(Path) readable} file.217 * @throws AssertionError if the content of the actual {@code File} is not equal to the given content.218 */219 public S hasContent(String expected) {220 paths.assertHasContent(info, actual, expected, charset);221 return myself;222 }223 /**224 * Assert that the tested {@link Path} is a readable file, it checks that the file exists (according to225 * {@link Files#exists(Path, LinkOption...)}) and that it is readable(according to {@link Files#isReadable(Path)}).226 *227 * Examples:228 * <pre><code class="java"> // Create a file and set permissions to be readable by all.229 * Path readableFile = Paths.get("readableFile");230 * Set<PosixFilePermission> perms = PosixFilePermissions.fromString("r--r--r--");231 * Files.createFile(readableFile, PosixFilePermissions.asFileAttribute(perms));232 * 233 * final Path symlinkToReadableFile = FileSystems.getDefault().getPath("symlinkToReadableFile");234 * Files.createSymbolicLink(symlinkToReadableFile, readableFile);235 * 236 * // Create a file and set permissions not to be readable.237 * Path nonReadableFile = Paths.get("nonReadableFile");238 * Set<PosixFilePermission> notReadablePerms = PosixFilePermissions.fromString("-wx------");239 * Files.createFile(nonReadableFile, PosixFilePermissions.asFileAttribute(notReadablePerms));240 * 241 * final Path nonExistentPath = FileSystems.getDefault().getPath("nonexistent");242 *243 * // The following assertions succeed:244 * assertThat(readableFile).isReadable();245 * assertThat(symlinkToReadableFile).isReadable();246 *247 * // The following assertions fail:248 * assertThat(nonReadableFile).isReadable();249 * assertThat(nonExistentPath).isReadable();</code></pre>250 *251 * @return self252 *253 * @see Files#isReadable(Path)254 */255 public S isReadable() {256 paths.assertIsReadable(info, actual);257 return myself;258 }259 /**260 * Assert that the tested {@link Path} is a writable file, it checks that the file exists (according to261 * {@link Files#exists(Path, LinkOption...)}) and that it is writable(according to {@link Files#isWritable(Path)}).262 *263 * Examples:264 * <pre><code class="java"> Create a file and set permissions to be writable by all.265 * Path writableFile = Paths.get("writableFile");266 * Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-rw-rw-");267 * Files.createFile(writableFile, PosixFilePermissions.asFileAttribute(perms));268 * 269 * final Path symlinkToWritableFile = FileSystems.getDefault().getPath("symlinkToWritableFile");270 * Files.createSymbolicLink(symlinkToWritableFile, writableFile);271 * 272 * // Create a file and set permissions not to be writable.273 * Path nonWritableFile = Paths.get("nonWritableFile");274 * perms = PosixFilePermissions.fromString("r--r--r--");275 * Files.createFile(nonWritableFile, PosixFilePermissions.asFileAttribute(perms));276 * 277 * final Path nonExistentPath = FileSystems.getDefault().getPath("nonexistent");278 *279 * // The following assertions succeed:280 * assertThat(writableFile).isWritable();281 * assertThat(symlinkToWritableFile).isWritable();282 *283 * // The following assertions fail:284 * assertThat(nonWritableFile).isWritable();285 * assertThat(nonExistentPath).isWritable();</code></pre>286 *287 * @return self288 *289 * @see Files#isWritable(Path)290 */291 public S isWritable() {292 paths.assertIsWritable(info, actual);293 return myself;294 }295 /**296 * Assert that the tested {@link Path} is a executable file, it checks that the file exists (according to297 * {@link Files#exists(Path, LinkOption...)}) and that it is executable(according to {@link Files#isExecutable(Path)}298 * ).299 *300 * Examples:301 * <pre><code class="java"> // Create a file and set permissions to be executable by all.302 * Path executableFile = Paths.get("executableFile");303 * Set<PosixFilePermission> perms = PosixFilePermissions.fromString("r-xr-xr-x");304 * Files.createFile(executableFile, PosixFilePermissions.asFileAttribute(perms));305 * 306 * final Path symlinkToExecutableFile = FileSystems.getDefault().getPath("symlinkToExecutableFile");307 * Files.createSymbolicLink(symlinkToExecutableFile, executableFile);308 * 309 * // Create a file and set permissions not to be executable.310 * Path nonExecutableFile = Paths.get("nonExecutableFile");311 * perms = PosixFilePermissions.fromString("rw-------");312 * Files.createFile(nonExecutableFile, PosixFilePermissions.asFileAttribute(perms));313 * 314 * final Path nonExistentPath = FileSystems.getDefault().getPath("nonexistent");315 *316 * // The following assertions succeed:317 * assertThat(executableFile).isExecutable();318 * assertThat(symlinkToExecutableFile).isExecutable();319 *320 * // The following assertions fail:321 * assertThat(nonExecutableFile).isExecutable();322 * assertThat(nonExistentPath).isExecutable();</code></pre>323 *324 * @return self325 *326 * @see Files#isExecutable(Path)327 */328 public S isExecutable() {329 paths.assertIsExecutable(info, actual);330 return myself;331 }332 /**333 * Assert that the tested {@link Path} exists according to {@link Files#exists(Path, LinkOption...)334 * Files#exists(Path)})335 *336 * <p>337 * <strong>Note that this assertion will follow symbolic links before asserting the path's existence.</strong>338 * </p>339 *340 * <p>341 * On Windows system, this has no influence. On Unix systems, this means the assertion result will fail if the path is342 * a symbolic link whose target does not exist. If you want to assert the existence of the symbolic link itself, use343 * {@link #existsNoFollowLinks()} instead.344 * </p>345 *346 * Examples:347 * <pre><code class="java"> // fs is a Unix filesystem348 * // Create a regular file, and a symbolic link pointing to it349 * final Path existingFile = fs.getPath("somefile");350 * Files.createFile(existingFile);351 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");352 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);353 *354 * // Create a symbolic link whose target does not exist355 * final Path nonExistentPath = fs.getPath("nonexistent");356 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");357 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);358 *359 * // The following assertions succeed:360 * assertThat(existingFile).exists();361 * assertThat(symlinkToExistingFile).exists();362 *363 * // The following assertions fail:364 * assertThat(nonExistentPath).exists();365 * assertThat(symlinkToNonExistentPath).exists();</code></pre>366 *367 * @return self368 *369 * @see Files#exists(Path, LinkOption...)370 */371 public S exists() {372 paths.assertExists(info, actual);373 return myself;374 }375 /**376 * Assert that the tested {@link Path} exists, not following symbolic links, by calling377 * {@link Files#exists(Path, LinkOption...) Files#exists(Path, LinkOption.NOFOLLOW_LINKS)}).378 *379 * <p>380 * This assertion behaves like {@link #exists()}, with the difference that it can be used to assert the existence of a381 * symbolic link even if its target is invalid.382 * </p>383 *384 * Examples:385 * <pre><code class="java"> // fs is a Unix filesystem386 * // Create a regular file, and a symbolic link pointing to it387 * final Path existingFile = fs.getPath("somefile");388 * Files.createFile(existingFile);389 * final Path symlinkToExistingFile = fs.getPath("symlink");390 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);391 * 392 * // Create a symbolic link whose target does not exist393 * final Path nonExistentPath = fs.getPath("nonexistent");394 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");395 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);396 *397 * // The following assertions succeed398 * assertThat(existingFile).existsNoFollowLinks();399 * assertThat(symlinkToExistingFile).existsNoFollowLinks();400 * assertThat(symlinkToNonExistentPath).existsNoFollowLinks();401 *402 * // The following assertion fails403 * assertThat(nonExistentPath).existsNoFollowLinks();</code></pre>404 *405 * @return self406 *407 * @see Files#exists(Path, LinkOption...)408 */409 public S existsNoFollowLinks() {410 paths.assertExistsNoFollowLinks(info, actual);411 return myself;412 }413 /**414 * Assert that the tested {@link Path} does not exist.415 *416 * <p>417 * <strong>IMPORTANT NOTE:</strong> this method will NOT follow symbolic links (provided that the underlying418 * {@link FileSystem} of this path supports symbolic links at all).419 * </p>420 *421 * <p>422 * This means that even if the link exists this assertion will fail even if the link's target does not exists - note423 * that this is unlike the default behavior of {@link #exists()}.424 * </p>425 *426 * <p>427 * If you are a Windows user, the above does not apply to you; if you are a Unix user however, this is important.428 * Consider the following:429 * <pre><code class="java"> // fs is a FileSystem430 * // Create a regular file, and a symbolic link pointing to it431 * final Path existingFile = fs.getPath("somefile");432 * Files.createFile(existingFile);433 * final Path symlinkToExistingFile = fs.getPath("symlink");434 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);435 * 436 * // Create a symbolic link to a nonexistent target file.437 * final Path nonExistentPath = fs.getPath("nonExistentPath");438 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");439 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);440 *441 * // The following assertion succeeds442 * assertThat(nonExistentPath).doesNotExist();443 * 444 * // The following assertions fail:445 * assertThat(existingFile).doesNotExist();446 * assertThat(symlinkToExistingFile).doesNotExist();447 * // fail because symlinkToNonExistentPath exists even though its target does not.448 * assertThat(symlinkToNonExistentPath).doesNotExist();</code></pre>449 *450 * @return self451 *452 * @see Files#notExists(Path, LinkOption...)453 * @see LinkOption#NOFOLLOW_LINKS454 */455 public S doesNotExist() {456 paths.assertDoesNotExist(info, actual);457 return myself;458 }459 /**460 * Assert that the tested {@link Path} is a regular file.461 *462 * <p>463 * <strong>Note that this method will follow symbolic links.</strong> If you are a Unix user and wish to assert that a464 * path is a symbolic link instead, use {@link #isSymbolicLink()}.465 * </p>466 *467 * <p>468 * This assertion first asserts the existence of the path (using {@link #exists()}) then checks whether the path is a469 * regular file.470 * </p>471 *472 * Examples:473 * <pre><code class="java"> // fs is a Unix filesystem474 *475 * // Create a regular file, and a symbolic link to that regular file476 * final Path existingFile = fs.getPath("existingFile");477 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");478 * Files.createFile(existingFile);479 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);480 *481 * // Create a directory, and a symbolic link to that directory482 * final Path dir = fs.getPath("dir");483 * final Path dirSymlink = fs.getPath("dirSymlink");484 * Files.createDirectories(dir);485 * Files.createSymbolicLink(dirSymlink, dir);486 *487 * // Create a nonexistent entry, and a symbolic link to that entry488 * final Path nonExistentPath = fs.getPath("nonexistent");489 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");490 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);491 *492 * // the following assertions succeed:493 * assertThat(existingFile).isRegularFile();494 * assertThat(symlinkToExistingFile).isRegularFile();495 *496 * // the following assertions fail because paths do not exist:497 * assertThat(nonExistentPath).isRegularFile();498 * assertThat(symlinkToNonExistentPath).isRegularFile();499 *500 * // the following assertions fail because paths exist but are not regular files:501 * assertThat(dir).isRegularFile();502 * assertThat(dirSymlink).isRegularFile();</code></pre>503 *504 * @return self505 */506 public S isRegularFile() {507 paths.assertIsRegularFile(info, actual);508 return myself;509 }510 /**511 * Assert that the tested {@link Path} is a directory.512 * <p>513 * <strong>Note that this method will follow symbolic links.</strong> If you are a Unix user and wish to assert that a514 * path is a symbolic link instead, use {@link #isSymbolicLink()}.515 * </p>516 *517 * <p>518 * This assertion first asserts the existence of the path (using {@link #exists()}) then checks whether the path is a519 * directory.520 * </p>521 *522 * Examples:523 * <pre><code class="java"> // fs is a Unix filesystem524 *525 * // Create a regular file, and a symbolic link to that regular file526 * final Path existingFile = fs.getPath("existingFile");527 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");528 * Files.createFile(existingFile);529 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);530 *531 * // Create a directory, and a symbolic link to that directory532 * final Path dir = fs.getPath("dir");533 * final Path dirSymlink = fs.getPath("dirSymlink");534 * Files.createDirectories(dir);535 * Files.createSymbolicLink(dirSymlink, dir);536 *537 * // Create a nonexistent entry, and a symbolic link to that entry538 * final Path nonExistentPath = fs.getPath("nonexistent");539 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");540 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);541 *542 * // the following assertions succeed:543 * assertThat(dir).isDirectory();544 * assertThat(dirSymlink).isDirectory();545 *546 * // the following assertions fail because paths do not exist:547 * assertThat(nonExistentPath).isDirectory();548 * assertThat(symlinkToNonExistentPath).isDirectory();549 *550 * // the following assertions fail because paths exist but are not directories:551 * assertThat(existingFile).isDirectory();552 * assertThat(symlinkToExistingFile).isDirectory();</code></pre>553 *554 * @return self555 */556 public S isDirectory() {557 paths.assertIsDirectory(info, actual);558 return myself;559 }560 /**561 * Assert that the tested {@link Path} is a symbolic link.562 * <p>563 * This assertion first asserts the existence of the path (using {@link #existsNoFollowLinks()}) then checks whether564 * the path is a symbolic link.565 * </p>566 *567 * Examples:568 * <pre><code class="java"> // fs is a Unix filesystem569 *570 * // Create a regular file, and a symbolic link to that regular file571 * final Path existingFile = fs.getPath("existingFile");572 * final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");573 * Files.createFile(existingFile);574 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);575 *576 * // Create a directory, and a symbolic link to that directory577 * final Path dir = fs.getPath("dir");578 * final Path dirSymlink = fs.getPath("dirSymlink");579 * Files.createDirectories(dir);580 * Files.createSymbolicLink(dirSymlink, dir);581 *582 * // Create a nonexistent entry, and a symbolic link to that entry583 * final Path nonExistentPath = fs.getPath("nonexistent");584 * final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");585 * Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);586 *587 * // the following assertions succeed:588 * assertThat(dirSymlink).isSymbolicLink();589 * assertThat(symlinkToExistingFile).isSymbolicLink();590 * assertThat(symlinkToNonExistentPath).isSymbolicLink();591 *592 * // the following assertion fails because the path does not exist:593 * assertThat(nonExistentPath).isSymbolicLink();594 *595 * // the following assertions fail because paths exist but are not symbolic links596 * assertThat(existingFile).isSymbolicLink();597 * assertThat(dir).isSymbolicLink();</code></pre>598 *599 * @return self600 */601 public S isSymbolicLink() {602 paths.assertIsSymbolicLink(info, actual);603 return myself;604 }605 /**606 * Assert that the tested {@link Path} is absolute (the path does not have to exist).607 *608 * <p>609 * Note that the fact that a path is absolute does not mean that it is {@link Path#normalize() normalized}:610 * {@code /foo/..} is absolute, for instance, but it is not normalized.611 * </p>612 *613 * Examples:614 * <pre><code class="java"> // unixFs is a Unix FileSystem615 *616 * // The following assertion succeeds:617 * assertThat(unixFs.getPath("/foo/bar")).isAbsolute();618 *619 * // The following assertion fails:620 * assertThat(unixFs.getPath("foo/bar")).isAbsolute();621 *622 * // windowsFs is a Windows FileSystem623 *624 * // The following assertion succeeds:625 * assertThat(windowsFs.getPath("c:\\foo")).isAbsolute();626 *627 * // The following assertions fail:628 * assertThat(windowsFs.getPath("foo\\bar")).isAbsolute();629 * assertThat(windowsFs.getPath("c:foo")).isAbsolute();630 * assertThat(windowsFs.getPath("\\foo\\bar")).isAbsolute();</code></pre>631 *632 * @return self633 *634 * @see Path#isAbsolute()635 */636 public S isAbsolute() {637 paths.assertIsAbsolute(info, actual);638 return myself;639 }640 /**641 * Assert that the tested {@link Path} is relative (opposite to {@link Path#isAbsolute()}).642 *643 * Examples:644 * <pre><code class="java"> // unixFs is a Unix FileSystem645 *646 * // The following assertions succeed:647 * assertThat(unixFs.getPath("./foo/bar")).isRelative();648 * assertThat(unixFs.getPath("foo/bar")).isRelative();649 *650 * // The following assertion fails:651 * assertThat(unixFs.getPath("/foo/bar")).isRelative();652 *653 * // windowsFs is a Windows FileSystem654 *655 * // The following assertion succeeds:656 * assertThat(windowsFs.getPath("foo\\bar")).isRelative();657 * assertThat(windowsFs.getPath("c:foo")).isRelative();658 * assertThat(windowsFs.getPath("\\foo\\bar")).isRelative();659 *660 * // The following assertions fail:661 * assertThat(windowsFs.getPath("c:\\foo")).isRelative();</code></pre>662 *663 * @return self664 *665 * @see Path#isAbsolute()666 */667 public S isRelative() {668 paths.assertIsRelative(info, actual);669 return myself;670 }671 /**672 * Assert that the tested {@link Path} is normalized.673 *674 * <p>675 * A path is normalized if it has no redundant components; typically, on both Unix and Windows, this means that the676 * path has no "self" components ({@code .}) and that its only parent components ({@code ..}), if any, are at the677 * beginning of the path.678 * </p>679 *680 * Examples:681 * <pre><code class="java"> // fs is a Unix filesystem682 *683 * // the following assertions succeed:684 * assertThat(fs.getPath("/usr/lib")).isNormalized();685 * assertThat(fs.getPath("a/b/c")).isNormalized();686 * assertThat(fs.getPath("../d")).isNormalized();687 *688 * // the following assertions fail:689 * assertThat(fs.getPath("/a/./b")).isNormalized();690 * assertThat(fs.getPath("c/b/..")).isNormalized();691 * assertThat(fs.getPath("/../../e")).isNormalized();</code></pre>692 *693 * @return self694 */695 public S isNormalized() {696 paths.assertIsNormalized(info, actual);697 return myself;698 }699 /**700 * Assert that the tested {@link Path} is canonical by comparing it to its {@link Path#toRealPath(LinkOption...) real701 * path}.702 *703 * <p>704 * For Windows users, this assertion is no different than {@link #isAbsolute()} expect that the file must exist. For705 * Unix users, this assertion ensures that the tested path is the actual file system resource, that is, it is not a706 * {@link Files#isSymbolicLink(Path) symbolic link} to the actual resource, even if the path is absolute.707 * </p>708 *709 * Examples:710 * <pre><code class="java"> // fs is a Unix filesystem711 * // Create a directory712 * final Path basedir = fs.getPath("/tmp/foo");713 * Files.createDirectories(basedir);714 * 715 * // Create a file in this directory716 * final Path existingFile = basedir.resolve("existingFile");717 * Files.createFile(existingFile);718 * 719 * // Create a symbolic link to that file720 * final Path symlinkToExistingFile = basedir.resolve("symlinkToExistingFile");...
Source:ExtendedPathAssert.java
...25 public static ExtendedPathAssert assertThatPath(Path path) {26 return new ExtendedPathAssert(path);27 }28 public ExtendedPathAssert isRelativeSymlinkTo(String path) throws IOException {29 isSymbolicLink();30 assertThatPath(Files.readSymbolicLink(this.actual)).isRelative()31 .isEqualTo(this.actual.getParent().relativize(this.actual.getParent().resolve(path)));32 return this;33 }34}
isSymbolicLink
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import java.io.IOException;3import java.nio.file.Files;4import java.nio.file.Path;5import java.nio.file.Paths;6public class 1 {7 public static void main(String[] args) throws IOException {8 Path path = Paths.get("C:\\Users\\user\\Desktop\\test.txt");9 Path link = Paths.get("C:\\Users\\user\\Desktop\\testLink.txt");10 Files.createSymbolicLink(link, path);11 assertThat(link).isSymbolicLink();12 }13}
isSymbolicLink
Using AI Code Generation
1package com.automationrhapsody.assertj;2import static org.assertj.core.api.Assertions.assertThat;3import java.nio.file.Path;4import java.nio.file.Paths;5public class PathAssertIsSymbolicLinkExample {6 public static void main(String[] args) {7 Path path1 = Paths.get("C:\\temp\\file.txt");8 Path path2 = Paths.get("C:\\temp\\linkToFile.txt");9 assertThat(path1).isSymbolicLink();10 assertThat(path2).isSymbolicLink();11 }12}
isSymbolicLink
Using AI Code Generation
1package org.example;2import org.junit.jupiter.api.Test;3import java.nio.file.Path;4import java.nio.file.Paths;5import static org.assertj.core.api.Assertions.assertThat;6public class AssertJTest {7 public void testIsSymbolicLink() {8 Path path = Paths.get("C:\\Users\\user\\Desktop\\1.java");9 assertThat(path).isSymbolicLink();10 }11}12 at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)13 at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)14 at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)15 at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:233)16 at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)17 at java.base/java.nio.file.Files.newOutputStream(Files.java:224)18 at java.base/java.nio.file.Files.write(Files.java:3312)19 at org.example.AssertJTest.testIsSymbolicLink(AssertJTest.java:13)
isSymbolicLink
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.junit.Test;3import java.nio.file.Path;4import java.nio.file.Paths;5public class AssertJTest {6 public void testSymbolicLink() {7 Path path = Paths.get("C:\\Users\\user\\Desktop\\test.txt");8 Assertions.assertThat(path).isSymbolicLink();9 }10}
isSymbolicLink
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import java.nio.file.Path;3import java.nio.file.Paths;4import org.junit.Test;5public class AssertJExample {6 public void test1() {7 Path path = Paths.get("D:\\file.txt");8 assertThat(path).isSymbolicLink();9 }10}11 at org.assertj.core.api.AbstractPathAssert.isSymbolicLink(AbstractPathAssert.java:104)12 at AssertJExample.test1(AssertJExample.java:12)13import static org.assertj.core.api.Assertions.*;14import java.nio.file.Path;15import java.nio.file.Paths;16import org.junit.Test;17public class AssertJExample {18 public void test1() {19 Path path = Paths.get("D:\\file.txt");20 assertThat(path).isAbsolute();21 }22}23 at org.assertj.core.api.AbstractPathAssert.isAbsolute(AbstractPathAssert.java:86)24 at AssertJExample.test1(AssertJExample.java:12)25import static org.assertj.core.api.Assertions.*;26import java.nio.file.Path;27import java.nio.file.Paths;28import org.junit.Test;29public class AssertJExample {30 public void test1() {31 Path path = Paths.get("D:\\file.txt");32 assertThat(path).isRegularFile();33 }34}35 at org.assertj.core.api.AbstractPathAssert.isRegularFile(AbstractPathAssert.java:92)36 at AssertJExample.test1(AssertJExample.java:12)37import static org.assertj.core.api.Assertions.*;38import java.nio.file.Path;39import java.nio.file.Paths;40import org.junit
isSymbolicLink
Using AI Code Generation
1import java.nio.file.Files;2import java.nio.file.Path;3import java.nio.file.Paths;4import org.assertj.core.api.Assertions;5public class AssertJPathAssertIsSymbolicLinkExample {6 public static void main(String[] args) {7 Path path = Paths.get("D:/test.txt");8 Assertions.assertThat(path).isSymbolicLink();9 }10}11import java.nio.file.Files;12import java.nio.file.Path;13import java.nio.file.Paths;14import org.assertj.core.api.Assertions;15public class AssertJPathAssertIsSymbolicLinkExample {16 public static void main(String[] args) {17 Path path = Paths.get("D:/test.txt");18 Assertions.assertThat(path).isSymbolicLink();19 }20}21import java.nio.file.Files;22import java.nio.file.Path;23import java.nio.file.Paths;24import org.assertj.core.api.Assertions;25public class AssertJPathAssertIsSymbolicLinkExample {26 public static void main(String[] args) {27 Path path = Paths.get("D:/test.txt");28 Assertions.assertThat(path).isSymbolicLink();29 }30}31import java.nio.file.Files;32import java.nio.file.Path;33import java.nio.file.Paths;34import org.assertj.core.api.Assertions;35public class AssertJPathAssertIsSymbolicLinkExample {36 public static void main(String[] args) {37 Path path = Paths.get("D:/test.txt");38 Assertions.assertThat(path).isSymbolicLink();39 }40}41import java.nio.file.Files;42import java.nio.file.Path;43import java.nio.file.Paths;44import org.assertj.core.api.Assertions;45public class AssertJPathAssertIsSymbolicLinkExample {46 public static void main(String[] args) {47 Path path = Paths.get("D:/test.txt");48 Assertions.assertThat(path).isSymbolicLink();49 }50}51import java.nio.file.Files;52import java.nio.file
isSymbolicLink
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import java.nio.file.Path;3import java.nio.file.Paths;4public class Test {5 public static void main(String[] args) {6 Path path = Paths.get("C:\\Users\\admin\\Desktop\\test");7 assertThat(path).isSymbolicLink();8 }9}10 at org.assertj.core.api.AbstractPathAssert.isSymbolicLink(AbstractPathAssert.java:149)11 at Test.main(Test.java:10)
isSymbolicLink
Using AI Code Generation
1package org.kodejava.example.io;2import java.nio.file.Files;3import java.nio.file.Path;4import java.nio.file.Paths;5public class IsSymbolicLinkExample {6 public static void main(String[] args) {7 Path path = Paths.get("C:/java/1.java");8 boolean isSymbolicLink = Files.isSymbolicLink(path);9 System.out.println("isSymbolicLink = " + isSymbolicLink);10 }11}
isSymbolicLink
Using AI Code Generation
1public class AssertJPathTest {2 public static void main(String[] args) {3 Path path = Paths.get("C:\\Users\\admin\\Desktop\\AssertJPathTest.java");4 assertThat(path).isSymbolicLink();5 }6}7at AssertJPathTest.main(AssertJPathTest.java:7)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!