class JGitSourceReferencesProvider implements SourceReferencesProvider {

    String getRelativePath(File subDir, File parentDir) throws MojoExecutionException {
        URI subDirUri;
        URI relativeUri;
        try {
            // have to canonicalize before comparing on case-insensitive filesystems
            subDirUri = subDir.getCanonicalFile().toURI();
            relativeUri = parentDir.getCanonicalFile().toURI().relativize(subDirUri);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        if (relativeUri.equals(subDirUri)) {
            throw new MojoExecutionException(subDir + " is not a subdir of " + parentDir);
        }
        String relative = relativeUri.getPath();
        // remove surrounding slashes
        if (relative.startsWith("/")) {
            relative = relative.substring(1);
        }
        if (relative.endsWith("/")) {
            relative = relative.substring(0, relative.length() - 1);
        }
        return relative;
    }

}

class JGitSourceReferencesProviderTest {

    @Test
    public void testGetRelativePathNoCommonBasedir() throws MojoExecutionException {

        JGitSourceReferencesProvider provider = new JGitSourceReferencesProvider();
        File projectBasedir = new File("/foo/test/bar");
        File repoRoot = new File("/baz");
        assertThrows(MojoExecutionException.class, () -> provider.getRelativePath(projectBasedir, repoRoot));
    }

}