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

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

Source:AssertJAssertions.java Github

copy

Full Screen

...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; }1913 public AbstractPathAssert hasDigest(java.security.MessageDigest p0, String p1) { return (AbstractPathAssert) (Object) null; }1914 public AbstractPathAssert hasDigest(String p0, byte[] p1) { return (AbstractPathAssert) (Object) null; }1915 public AbstractPathAssert hasDigest(String p0, String p1) { return (AbstractPathAssert) (Object) null; }1916 public AbstractPathAssert isDirectoryContaining(java.util.function.Predicate p0) { return (AbstractPathAssert) (Object) null; }1917 public AbstractPathAssert isDirectoryContaining(String p0) { return (AbstractPathAssert) (Object) null; }1918 public AbstractPathAssert isDirectoryRecursivelyContaining(String p0) { return (AbstractPathAssert) (Object) null; }1919 public AbstractPathAssert isDirectoryRecursivelyContaining(java.util.function.Predicate p0) { return (AbstractPathAssert) (Object) null; }...

Full Screen

Full Screen

Source:AbstractPathAssert.java Github

copy

Full Screen

...30 * Assertions for {@link Path} objects31 *32 * <p>33 * Note that some assertions have two versions: a normal one and a "raw" one (for instance, {@code hasParent()} and34 * {@code hasParentRaw()}. The difference is that normal assertions will {@link Path#toRealPath(LinkOption...)35 * canonicalize} or {@link Path#normalize() normalize} the tested path and, where applicable, the path argument, before36 * performing the actual test. Canonicalization includes normalization.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&lt;PosixFilePermission&gt; 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&lt;PosixFilePermission&gt; 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&lt;PosixFilePermission&gt; 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&lt;PosixFilePermission&gt; 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");721 * Files.createSymbolicLink(symlinkToExistingFile, existingFile);722 *723 * // The following assertion succeeds:724 * assertThat(existingFile).isCanonical();725 *726 * // The following assertion fails:727 * assertThat(symlinkToExistingFile).isCanonical();</code></pre>728 *729 * @throws PathsException an I/O error occurred while evaluating the path730 *731 * @see Path#toRealPath(LinkOption...)732 * @see Files#isSameFile(Path, Path)733 */734 public S isCanonical() {735 paths.assertIsCanonical(info, actual);736 return myself;737 }738 /**739 * Assert that the tested {@link Path} last element String representation is equal to the given filename.740 *741 * <p>742 * Note that the path does not need to exist to check its file name.743 * </p>744 *745 * Examples:746 * <pre><code class="java"> // fs is a Unix filesystem747 * final Path file = fs.getPath("/foo/foo.txt");748 * final Path symlink = fs.getPath("/home/symlink-to-foo");749 * Files.createSymbolicLink(symlink, file);750 *751 * // the following assertions succeed:752 * assertThat(fs.getPath("/dir1/file.txt")).hasFileName("file.txt");753 * assertThat(fs.getPath("/dir1/dir2")).hasFileName("dir2");754 * // you can check file name on non existent paths755 * assertThat(file).hasFileName("foo.txt");756 * assertThat(symlink).hasFileName("symlink-to-foo");757 *758 * // the following assertions fail:759 * assertThat(fs.getPath("/dir1/file.txt").hasFileName("other.txt");760 * // fail because, last element is "." 761 * assertThat(fs.getPath("/dir1/.")).hasFileName("dir1");762 * // fail because a link filename is not the same as its target filename763 * assertThat(symlink).hasFileName("file.txt");</code></pre>764 *765 * @param fileName the expected filename766 * @return self767 *768 * @throws NullPointerException if the given fileName is null.769 * @see Path#getFileName()770 */771 public S hasFileName(final String fileName) {772 paths.assertHasFileName(info, actual, fileName);773 return myself;774 }775 /**776 * Assert that the tested {@link Path} has the expected parent path.777 *778 * <p>779 * <em>This assertion will perform canonicalization of the tested path and of the given argument before performing the test; see the class780 * description for more details. If this is not what you want, use {@link #hasParentRaw(Path)} instead.</em>781 * </p>782 *783 * <p>784 * Checks that the tested path has the given parent. This assertion will fail both if the tested path has no parent,785 * or has a different parent than what is expected.786 * </p>787 *788 * Examples:789 * <pre><code class="java"> // fs is a Unix filesystem790 * final Path actual = fs.getPath("/dir1/dir2/file");791 *792 * // the following assertion succeeds:793 * assertThat(actual).hasParent(fs.getPath("/dir1/dir2/."));794 * // this one too as this path will be normalized to "/dir1/dir2":795 * assertThat(actual).hasParent(fs.getPath("/dir1/dir3/../dir2/."));796 *797 * // the following assertion fails:798 * assertThat(actual).hasParent(fs.getPath("/dir1"));</code></pre>799 *800 * @param expected the expected parent path801 * @return self802 *803 * @throws NullPointerException if the given parent path is null.804 * @throws PathsException failed to canonicalize the tested path or the path given as an argument805 * 806 * @see Path#getParent()807 */808 public S hasParent(final Path expected) {809 paths.assertHasParent(info, actual, expected);810 return myself;811 }812 /**813 * Assert that the tested {@link Path} has the expected parent path.814 *815 * <p>816 * <em>This assertion will not perform any canonicalization of either the tested path or the path given as an argument; 817 * see class description for more details. If this is not what you want, use {@link #hasParent(Path)} instead.</em>818 * </p>819 *820 * <p>821 * This assertion uses {@link Path#getParent()} with no modification, which means the only criterion for this822 * assertion's success is the path's components (its root and its name elements).823 * </p>824 *825 * <p>826 * This may lead to surprising results if the tested path and the path given as an argument are not normalized. For827 * instance, if the tested path is {@code /home/foo/../bar} and the argument is {@code /home}, the assertion will828 * <em>fail</em> since the parent of the tested path is not {@code /home} but... {@code /home/foo/..}.829 * </p>830 *831 * <p>832 * While this may seem counterintuitive, it has to be recalled here that it is not required for a {@link FileSystem}833 * to consider that {@code .} and {@code ..} are name elements for respectively the current directory and the parent834 * directory respectively. In fact, it is not even required that a {@link FileSystem} be hierarchical at all.835 * </p>836 *837 * Examples:838 * <pre><code class="java"> // fs is a Unix filesystem839 * final Path actual = fs.getPath("/dir1/dir2/file");840 *841 * // the following assertion succeeds:842 * assertThat(actual).hasParentRaw(fs.getPath("/dir1/dir2"));843 *844 * // the following assertions fails:845 * assertThat(actual).hasParent(fs.getPath("/dir1"));846 * // ... and this one too as expected path is not canonicalized.847 * assertThat(actual).hasParentRaw(fs.getPath("/dir1/dir3/../dir2"));</code></pre>848 *849 * @param expected the expected parent path850 * @return self851 *852 * @throws NullPointerException if the given parent path is null.853 * 854 * @see Path#getParent()855 */856 public S hasParentRaw(final Path expected) {857 paths.assertHasParentRaw(info, actual, expected);858 return myself;859 }860 /**861 * Assert that the tested {@link Path} has no parent.862 *863 * <p>864 * <em>This assertion will first canonicalize the tested path before performing the test; if this is not what you want, use {@link #hasNoParentRaw()} instead.</em>865 * </p>866 *867 * <p>868 * Check that the tested path, after canonicalization, has no parent. See the class description for more information869 * about canonicalization.870 * </p>...

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.assertj;2import static org.assertj.core.api.Assertions.assertThat;3import java.nio.file.Path;4import java.nio.file.Paths;5public class AssertJHasParentRawMethod {6 public static void main(String[] args) {7 Path path = Paths.get("D:\\test\\file.txt");8 assertThat(path).hasParentRaw("D:\\test");9 }10}

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1package org.example;2import org.assertj.core.api.Assertions;3import org.junit.jupiter.api.Test;4import java.nio.file.Path;5import java.nio.file.Paths;6public class Test1 {7 public void test1() {8 Path path = Paths.get("C:\\Users\\user\\Downloads");9 Assertions.assertThat(path).hasParentRaw("C:\\Users\\user");10 }11}12package org.example;13import org.assertj.core.api.Assertions;14import org.junit.jupiter.api.Test;15import java.nio.file.Path;16import java.nio.file.Paths;17public class Test2 {18 public void test1() {19 Path path = Paths.get("C:\\Users\\user\\Downloads");20 Assertions.assertThat(path).hasParentRaw("C:\\Users\\user");21 }22}23package org.example;24import org.assertj.core.api.Assertions;25import org.junit.jupiter.api.Test;26import java.nio.file.Path;27import java.nio.file.Paths;28public class Test3 {29 public void test1() {30 Path path = Paths.get("C:\\Users\\user\\Downloads");31 Assertions.assertThat(path).hasParentRaw("C:\\Users\\user");32 }33}34package org.example;35import org.assertj.core.api.Assertions;36import org.junit.jupiter.api.Test;37import java.nio.file.Path;38import java.nio.file.Paths;39public class Test4 {40 public void test1() {41 Path path = Paths.get("C:\\Users\\user\\Downloads");42 Assertions.assertThat(path).hasParentRaw("C:\\Users\\user");43 }44}45package org.example;46import org.assertj.core.api.Assertions;47import org.junit.jupiter.api.Test;48import java.nio.file.Path;49import java.nio.file.Paths;50public class Test5 {51 public void test1() {52 Path path = Paths.get("C:\\Users\\user\\Downloads");53 Assertions.assertThat(path).hasParentRaw("C:\\Users\\user");54 }55}56package org.example;57import org.assertj.core.api.Assertions;58import org.junit.jupiter.api.Test;

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api.path;2import java.nio.file.Path;3import org.assertj.core.api.AbstractPathAssert;4import org.assertj.core.api.Assertions;5public class HasParentRaw {6 public static void main(String[] args) {7 Path path = Path.of("foo", "bar");8 AbstractPathAssert<?> assertions = Assertions.assertThat(path);9 assertions.hasParentRaw(Path.of("foo"));10 }11}12package org.assertj.core.api.path;13import java.nio.file.Path;14import org.assertj.core.api.PathAssert;15import org.assertj.core.api.Assertions;16public class HasParentRaw {17 public static void main(String[] args) {18 Path path = Path.of("foo", "bar");19 PathAssert assertions = Assertions.assertThat(path);20 assertions.hasParentRaw(Path.of("foo"));21 }22}23package org.assertj.core.api.file;24import java.io.File;25import org.assertj.core.api.AbstractFileAssert;26import org.assertj.core.api.Assertions;27public class HasParentRaw {28 public static void main(String[] args) {29 File file = new File("foo/bar");30 AbstractFileAssert<?> assertions = Assertions.assertThat(file);31 assertions.hasParentRaw(new File("foo"));32 }33}34package org.assertj.core.api.file;35import java.io.File;36import org.assertj.core.api.FileAssert;37import org.assertj.core.api.Assertions;38public class HasParentRaw {39 public static void main(String[] args) {40 File file = new File("foo/bar");41 FileAssert assertions = Assertions.assertThat(file);42 assertions.hasParentRaw(new File("foo"));43 }44}45package org.assertj.core.api.file;46import java.io.File;47import org.assertj.core.api.AbstractFileAssert;48import org.assertj.core.api.Assertions;49public class HasParentRaw {50 public static void main(String[] args) {51 File file = new File("foo/bar");52 AbstractFileAssert<?> assertions = Assertions.assertThat(file);53 assertions.hasParentRaw("foo");54 }55}

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import java.nio.file.Path;3import java.nio.file.Paths;4public class 1 {5 public static void main(String[] args) {6 Path path = Paths.get("/home/joel/foobar");7 assertThat(path).hasParentRaw("/home/joel");8 }9}10 at org.assertj.core.api.AbstractPathAssert.hasParentRaw(AbstractPathAssert.java:120)11 at 1.main(1.java:8)12import static org.assertj.core.api.Assertions.assertThat;13import java.nio.file.Path;14import java.nio.file.Paths;15public class 2 {16 public static void main(String[] args) {17 Path path = Paths.get("/home/joel/foobar");18 assertThat(path).hasParentRaw("/home/foobar");19 }20}21 at org.assertj.core.api.AbstractPathAssert.hasParentRaw(AbstractPathAssert.java:120)22 at 2.main(2.java:8)23import static org.assertj.core.api.Assertions.assertThat;24import java.nio.file.Path;25import java.nio.file.Paths;26public class 3 {27 public static void main(String[] args) {28 Path path = Paths.get("/home/joel/foobar");29 assertThat(path).hasParentRaw("/home/foobar/");30 }31}32 at org.assertj.core.api.AbstractPathAssert.hasParentRaw(AbstractPathAssert.java:120)33 at 3.main(3.java:8)

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.junit.Test;3import java.nio.file.Path;4import java.nio.file.Paths;5public class AssertJPath {6 public void testHasParentRaw() {7 Path path = Paths.get("/home", "user", "test", "file.txt");8 Assertions.assertThat(path).hasParentRaw(Paths.get("/home", "user", "test"));9 }10}11public AbstractPathAssert<S> hasParentRaw(Path expected) {12 paths.assertHasParent(info, actual, expected);13 return myself;14}15public AbstractPathAssert<S> hasParent(Path expected) {16 paths.assertHasParent(info, actual, expected);17 return myself;18}19public void assertHasParent(AssertionInfo info, Path actual, Path expected) {20 assertNotNull(info, actual);21 assertNotNull(info, expected);22 if (actual.getParent() == null) {23 throw failures.failure(info, shouldHaveParent(actual, expected));24 }25 if (!actual.getParent().equals(expected)) {26 throw failures.failure(info, shouldHaveParent(actual, expected));27 }28}

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import java.nio.file.Paths;3import org.junit.Test;4public class PathHasParentRawTest {5 public void test() {6 assertThat(Paths.get("/home/user")).hasParentRaw(Paths.get("/home"));7 }8}9test(org.assertj.core.api.path.PathHasParentRawTest) Time elapsed: 0.001 sec <<< FAILURE!10 at org.assertj.core.api.path.PathHasParentRawTest.test(PathHasParentRawTest.java:10)11public AbstractPathAssert hasParentRaw(Path expectedParent)12import static org.assertj.core.api.Assertions.*;13import java.nio.file.Paths;14import org.junit.Test;15public class PathHasParentRawTest {

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AbstractPathAssert;2import org.assertj.core.api.PathAssert;3import java.nio.file.Paths;4public class HasParentRaw {5 public static void main(String[] args) {6 PathAssert pathAssert = new PathAssert(Paths.get("C:\\Users\\user\\Desktop\\test.txt"));7 AbstractPathAssert abstractPathAssert = pathAssert.hasParentRaw("C:\\Users\\user\\Desktop");8 System.out.println(abstractPathAssert);9 }10}

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1public class PathAssertHasParentRaw {2 public static void main(String[] args) {3 Path path = Paths.get("src/test/java/1.java");4 PathAssert.assertThat(path).hasParentRaw("src/test/java");5 }6}

Full Screen

Full Screen

hasParentRaw

Using AI Code Generation

copy

Full Screen

1public class AssertjExample {2 public static void main(String[] args) {3 Path path = Paths.get("/home/","/home/srikanth/","/home/srikanth/Desktop/","/home/srikanth/Desktop/AssertjExample.java");4 Assertions.assertThat(path).hasParentRaw("/home/srikanth/Desktop/");5 }6}7 at org.assertj.core.api.AbstractPathAssert.hasParentRaw(AbstractPathAssert.java:264)8 at AssertjExample.main(1.java:5)9public final SELF hasFileName(String expected)10assertThat(path).hasFileName(expected);11public class AssertjExample {12 public static void main(String[] args) {13 Path path = Paths.get("/home/srikanth/Desktop/AssertjExample.java");14 Assertions.assertThat(path).hasFileName("AssertjExample.java");15 }16}17public class AssertjExample {18 public static void main(String[] args) {19 Path path = Paths.get("/home/srikanth/Desktop/AssertjExample.java");20 Assertions.assertThat(path).hasFileName("AssertjExample");21 }22}

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