Skip to content

Instantly share code, notes, and snippets.

@fge
Created January 3, 2015 00:41
Show Gist options
  • Save fge/8f94693e0763a50ea85c to your computer and use it in GitHub Desktop.
Save fge/8f94693e0763a50ea85c to your computer and use it in GitHub Desktop.
/**
* Assert whether the tested path has the expected parent path
*
* <p><strong>IMPORTANT NOTE:</strong> this assertion uses, and behaves the
* same, as {@link Path#getParent()}. This means that the tested path will
* <strong>not</strong> be normalized, and will <strong>not</strong> be
* resolved to a canonical path either.</p>
*
* <p>This means that for instance, even though their canonical form would
* have the assertion succeed on Unix systems, {@code /home} is
* <strong>not</strong> a parent of {@code /home/foo/../bar} (the parent of
* the latter being... {@code /home/foo/..}!). While this may seem
* counterintuitive, it has to be recalled here that {@link FileSystem}s are
* not required to be hierarchical; some of them do not even have the notion
* of a parent (paths issued from such filesystems would always return
* {@code null} for {@code .getParent()}).</p>
*
* <p>It is therefore of the responsibility of the user to ensure that
* tested paths are {@link Path#normalize() normalized} and, if necessary,
* {@link Path#toAbsolutePath() absolute} as well.</p>
*
* <p>For instance, if the actual (resolved) path is {@code /dir1/dir2/file}
* then the following happens:</p>
*
* <pre><code class="java">
* // (resolved) parent is /dir1/dir2
* assertThat(actual).hasParent(parent); // success
* // (resolved) parent is /dir1
* assertThat(actual).hasParent(parent); // FAILURE
* </code></pre>
*
* @param expected the expected parent path
* @return self
*
* @see Path#getParent()
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment