ResourceBundleContentHelper { protected String getBundlePrefix(final Path path) { LOGGER.traceEntry("getBundlePrefix for path: {}", path); Require.nonNull(path); if (!path.toAbsolutePath().startsWith(this.ignorableBasePath.toAbsolutePath())) { throw new IllegalArgumentException("All files should live below the ignorable base path "+this.ignorableBasePath.toAbsolutePath().toString()+". Given path is "+path.toAbsolutePath().toString()); } final Path prefixPath= this.ignorableBasePath.toAbsolutePath().relativize(path.toAbsolutePath().getParent()); final String bundlePrefix= prefixPath.toString() .replaceFirst("^/+", "") .replaceFirst("$/+", "") .replaceAll("\\/+", "/") ; return LOGGER.traceExit(bundlePrefix); } ResourceBundleContentHelper();  ResourceBundleContentHelper(final File ignorableBasePath);  ResourceBundleContentHelper(final Path ignorableBasePath); Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles);  }
@Test public void testGetBundlePrefix() { final Path ignorableBasePath= Paths.get("/some/path/src/main/resources"); final ResourceBundleContentHelper helper= new ResourceBundleContentHelper(ignorableBasePath); assertThat(helper.getBundlePrefix(ignorableBasePath.resolve("i18n/messages_de.properties"))).isEqualTo("i18n"); assertThat(helper.getBundlePrefix(ignorableBasePath.resolve("i18n/my/sub/options_de.properties"))).isEqualTo("i18n/my/sub"); }
@Test public void testGetBundlePrefix_inWrongBasePath() { final Path ignorableBasePath= Paths.get("/some/path/src/main/resources"); final Path otherBasePath= Paths.get("/some/other/path"); final ResourceBundleContentHelper helper= new ResourceBundleContentHelper(ignorableBasePath); assertThatIllegalArgumentException().isThrownBy(() -> { helper.getBundlePrefix(otherBasePath.resolve("i18n/messages_de.properties")); }).withMessage("All files should live below the ignorable base path /some/path/src/main/resources. Given path is /some/other/path/i18n/messages_de.properties"); }
@Test public void testGetBundlePrefix_byPathOrFile() { final Path ignorableBasePath= Paths.get("/some/path/src/main/resources"); final ResourceBundleContentHelper helper= new ResourceBundleContentHelper(ignorableBasePath); assertThat(helper.getBundlePrefix(ignorableBasePath.resolve("i18n/messages_de.properties"))).isEqualTo("i18n"); assertThat(helper.getBundlePrefix(ignorableBasePath.resolve("i18n/messages_de.properties").toFile())).isEqualTo("i18n"); assertThat(helper.getBundlePrefix(new File(ignorableBasePath.toFile(), "i18n/messages_de.properties"))).isEqualTo("i18n"); }