mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-13 16:40:01 +00:00
Finished FilenameUtilTest
This commit is contained in:
@@ -2,14 +2,18 @@ package de.grimsi.gameyfin.util;
|
||||
|
||||
import com.google.common.jimfs.Configuration;
|
||||
import com.google.common.jimfs.Jimfs;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@@ -24,10 +28,16 @@ class FilenameUtilTest {
|
||||
private static final FileSystem unixFS = Jimfs.newFileSystem(Configuration.unix());
|
||||
private static final FileSystem osxFS = Jimfs.newFileSystem(Configuration.osX());
|
||||
private static final FileSystem winFS = Jimfs.newFileSystem(Configuration.windows());
|
||||
|
||||
private static final List<String> gameFileExtensions = List.of("extension_1", "extension_2", "extension_3");
|
||||
|
||||
@BeforeAll
|
||||
static void init() {
|
||||
new FilenameUtil().setPossibleGameFileExtensions(gameFileExtensions);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void close() throws IOException {
|
||||
static void closeFileSystems() throws IOException {
|
||||
unixFS.close();
|
||||
osxFS.close();
|
||||
winFS.close();
|
||||
@@ -44,6 +54,8 @@ class FilenameUtilTest {
|
||||
String result = FilenameUtil.getFilenameWithoutExtension(p);
|
||||
|
||||
assertThat(result).isEqualTo(filename);
|
||||
|
||||
Files.deleteIfExists(p);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -57,30 +69,49 @@ class FilenameUtilTest {
|
||||
String result = FilenameUtil.getFilenameWithoutExtension(p);
|
||||
|
||||
assertThat(result).isEqualTo("%s.%s".formatted(filename, gameFileExtensions.get(0)));
|
||||
|
||||
Files.deleteIfExists(p);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFilenameWithExtension_Unix() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("fileSystems")
|
||||
void getFilenameWithExtension(FileSystem fileSystem) throws IOException {
|
||||
String filename = "example_file";
|
||||
|
||||
Path p = fileSystem.getPath("%s.%s".formatted(filename, gameFileExtensions.get(0)));
|
||||
Files.createFile(p);
|
||||
|
||||
String result = FilenameUtil.getFilenameWithExtension(p);
|
||||
|
||||
assertThat(result).isEqualTo("%s.%s".formatted(filename, gameFileExtensions.get(0)));
|
||||
|
||||
Files.deleteIfExists(p);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFilenameWithExtension_OSX() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("fileSystems")
|
||||
void hasGameArchiveExtension_gameArchive(FileSystem fileSystem) throws IOException {
|
||||
String filename = "example_file";
|
||||
|
||||
Path p = fileSystem.getPath("%s.%s".formatted(filename, gameFileExtensions.get(0)));
|
||||
Files.createFile(p);
|
||||
|
||||
assertThat(FilenameUtil.hasGameArchiveExtension(p)).isTrue();
|
||||
|
||||
Files.deleteIfExists(p);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFilenameWithExtension_Windows() {
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("fileSystems")
|
||||
void hasGameArchiveExtension_notGameArchive(FileSystem fileSystem) throws IOException {
|
||||
String filename = "example_file";
|
||||
|
||||
@Test
|
||||
void hasGameArchiveExtension_Unix() {
|
||||
}
|
||||
Path p = fileSystem.getPath("%s.%s".formatted(filename, "some_other_extension"));
|
||||
Files.createFile(p);
|
||||
|
||||
@Test
|
||||
void hasGameArchiveExtension_OSX() {
|
||||
}
|
||||
assertThat(FilenameUtil.hasGameArchiveExtension(p)).isFalse();
|
||||
|
||||
@Test
|
||||
void hasGameArchiveExtension_Windows() {
|
||||
Files.deleteIfExists(p);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> fileSystems() {
|
||||
|
||||
Reference in New Issue
Block a user