@Test public void getFilenameWithoutVariant_when_variants_defined() { assertEquals("filename1.txt",converterToTest.getFilenameWithoutVariant("filename1-variant_variant1.txt")); assertEquals("filename21.pdf",converterToTest.getFilenameWithoutVariant("filename21-variant_variantXY.pdf")); assertEquals("filename22.xyz.pdf",converterToTest.getFilenameWithoutVariant("filename22-variant_variant21.xyz.pdf")); }
public String getFilenameWithoutVariant(String fileName) { if (fileName == null) { return null; } int index = fileName.indexOf(variantIdentifier); if (index == -1) { return fileName; } String before = fileName.substring(0,index); String subString = fileName.substring(index + variantIdentifier.length()); index = subString.indexOf('.'); if (index == -1) { throw new IllegalArgumentException("no '.' found, but this is not allowed!"); } String ending = subString.substring(index); return before+ending; }
FilenameVariantConverter { public String getFilenameWithoutVariant(String fileName) { if (fileName == null) { return null; } int index = fileName.indexOf(variantIdentifier); if (index == -1) { return fileName; } String before = fileName.substring(0,index); String subString = fileName.substring(index + variantIdentifier.length()); index = subString.indexOf('.'); if (index == -1) { throw new IllegalArgumentException("no '.' found, but this is not allowed!"); } String ending = subString.substring(index); return before+ending; } }
FilenameVariantConverter { public String getFilenameWithoutVariant(String fileName) { if (fileName == null) { return null; } int index = fileName.indexOf(variantIdentifier); if (index == -1) { return fileName; } String before = fileName.substring(0,index); String subString = fileName.substring(index + variantIdentifier.length()); index = subString.indexOf('.'); if (index == -1) { throw new IllegalArgumentException("no '.' found, but this is not allowed!"); } String ending = subString.substring(index); return before+ending; } FilenameVariantConverter();  FilenameVariantConverter(String varIdentifier); }
FilenameVariantConverter { public String getFilenameWithoutVariant(String fileName) { if (fileName == null) { return null; } int index = fileName.indexOf(variantIdentifier); if (index == -1) { return fileName; } String before = fileName.substring(0,index); String subString = fileName.substring(index + variantIdentifier.length()); index = subString.indexOf('.'); if (index == -1) { throw new IllegalArgumentException("no '.' found, but this is not allowed!"); } String ending = subString.substring(index); return before+ending; } FilenameVariantConverter();  FilenameVariantConverter(String varIdentifier); String getVariantFromFilename(String fileName); String toVariantFileName(String fileName, String variant); String getFilenameWithoutVariant(String fileName); }
FilenameVariantConverter { public String getFilenameWithoutVariant(String fileName) { if (fileName == null) { return null; } int index = fileName.indexOf(variantIdentifier); if (index == -1) { return fileName; } String before = fileName.substring(0,index); String subString = fileName.substring(index + variantIdentifier.length()); index = subString.indexOf('.'); if (index == -1) { throw new IllegalArgumentException("no '.' found, but this is not allowed!"); } String ending = subString.substring(index); return before+ending; } FilenameVariantConverter();  FilenameVariantConverter(String varIdentifier); String getVariantFromFilename(String fileName); String toVariantFileName(String fileName, String variant); String getFilenameWithoutVariant(String fileName); static final String DEFAULT_IDENTIFIER; }