Skip to content

Commit

Permalink
"Converted test cases in FileNameCleanerTest to use @CsvSource for im… (
Browse files Browse the repository at this point in the history
JabRef#12014)

* "Converted test cases in FileNameCleanerTest to use @CsvSource for improved readability. Added additional test cases for Linux to handle file name restrictions.

* Fixed checkstyle error

* Removed empytline for checkstyle

* Fixed CSV parsing issues by enclosing values containing commas in double quotes.

Test case was failing so had to fix

* Changed the custom test

* Fixed custom test

* Fixed custom test (again)

* Revised custom test

* Fixed the ordering of expected and input

* Swapped for all test cases

* Added removed test case

* Added forgotten comma

* Added singlequotes so csvSource can differentiate the 2 strings
  • Loading branch information
adambash12 authored Oct 18, 2024
1 parent a3f13aa commit 4351a39
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/test/java/org/jabref/logic/util/FileNameCleanerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,42 @@

import org.jabref.logic.util.io.FileNameCleaner;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

class FileNameCleanerTest {

@Test
void cleanFileName() {
assertEquals("legalFilename.txt", FileNameCleaner.cleanFileName("legalFilename.txt"));
assertEquals("illegalFilename______.txt", FileNameCleaner.cleanFileName("illegalFilename/?*<>|.txt"));
assertEquals("illegalFileName_.txt", FileNameCleaner.cleanFileName("illegalFileName{.txt"));
@ParameterizedTest
@CsvSource({
"legalFilename.txt, legalFilename.txt",
"illegalFilename______.txt, illegalFilename/?*<>|.txt",
"illegalFileName_.txt, illegalFileName{.txt",
"_The Evolution of Sentiment_ Analysis_.PDF, ?The Evolution of Sentiment} Analysis}.PDF",
"'The Evolution of Sentiment_ Analysis_A Review of Research Topics, Venues, and Top Cited Papers.PDF', 'The Evolution of Sentiment} Analysis}A Review of Research Topics, Venues, and Top Cited Papers.PDF'"
})
void cleanFileName(String expected, String input) {
assertEquals(expected, FileNameCleaner.cleanFileName(input));
}

@Test
void cleanDirectoryName() {
assertEquals("legalFilename.txt", FileNameCleaner.cleanDirectoryName("legalFilename.txt"));
assertEquals("subdir/legalFilename.txt", FileNameCleaner.cleanDirectoryName("subdir/legalFilename.txt"));
assertEquals("illegalFilename/_____.txt", FileNameCleaner.cleanDirectoryName("illegalFilename/?*<>|.txt"));
@ParameterizedTest
@CsvSource({
"legalFilename.txt, legalFilename.txt",
"subdir/legalFilename.txt, subdir/legalFilename.txt",
"illegalFilename/_____.txt, illegalFilename/?*<>|.txt"
})
void cleanDirectoryName(String expected, String input) {
assertEquals(expected, FileNameCleaner.cleanDirectoryName(input));
}

@Test
void cleanDirectoryNameForWindows() {
assertEquals("legalFilename.txt", FileNameCleaner.cleanDirectoryName("legalFilename.txt"));
assertEquals("subdir\\legalFilename.txt", FileNameCleaner.cleanDirectoryName("subdir\\legalFilename.txt"));
assertEquals("illegalFilename\\_____.txt", FileNameCleaner.cleanDirectoryName("illegalFilename\\?*<>|.txt"));
}

@Test
void cleanCurlyBracesAsWell() {
assertEquals("The Evolution of Sentiment_ Analysis_A Review of Research Topics, Venues, and Top Cited Papers.PDF", FileNameCleaner.cleanFileName("The Evolution of Sentiment} Analysis}A Review of Research Topics, Venues, and Top Cited Papers.PDF"));
@ParameterizedTest
@CsvSource({
"legalFilename.txt, legalFilename.txt",
"subdir\\legalFilename.txt, subdir\\legalFilename.txt",
"illegalFilename\\_____.txt, illegalFilename\\?*<>|.txt"
})
void cleanDirectoryNameForWindows(String expected, String input) {
assertEquals(expected, FileNameCleaner.cleanDirectoryName(input));
}
}

0 comments on commit 4351a39

Please sign in to comment.