mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 00:30:02 +00:00
Implement some more test cases for ProtobufUtil and FilenameUtil
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package de.grimsi.gameyfin.util;
|
||||
|
||||
import com.google.common.jimfs.Configuration;
|
||||
import com.google.common.jimfs.Jimfs;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
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");
|
||||
|
||||
@AfterAll
|
||||
static void close() throws IOException {
|
||||
unixFS.close();
|
||||
osxFS.close();
|
||||
winFS.close();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("fileSystems")
|
||||
void getFilenameWithoutExtension_File(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.getFilenameWithoutExtension(p);
|
||||
|
||||
assertThat(result).isEqualTo(filename);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("fileSystems")
|
||||
void getFilenameWithoutExtension_Folder(FileSystem fileSystem) throws IOException {
|
||||
String filename = "example_folder";
|
||||
|
||||
Path p = fileSystem.getPath("%s.%s".formatted(filename, gameFileExtensions.get(0)));
|
||||
Files.createDirectory(p);
|
||||
|
||||
String result = FilenameUtil.getFilenameWithoutExtension(p);
|
||||
|
||||
assertThat(result).isEqualTo("%s.%s".formatted(filename, gameFileExtensions.get(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFilenameWithExtension_Unix() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFilenameWithExtension_OSX() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFilenameWithExtension_Windows() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGameArchiveExtension_Unix() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGameArchiveExtension_OSX() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGameArchiveExtension_Windows() {
|
||||
}
|
||||
|
||||
private static Stream<Arguments> fileSystems() {
|
||||
return Stream.of(
|
||||
arguments(named("Unix", unixFS)),
|
||||
arguments(named("OSX", osxFS)),
|
||||
arguments(named("Windows", winFS))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package de.grimsi.gameyfin.util;
|
||||
|
||||
import com.google.protobuf.Timestamp;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ProtobufUtilTest {
|
||||
|
||||
@Test
|
||||
void toInstant() {
|
||||
Timestamp t = Timestamp.newBuilder().setSeconds(1).build();
|
||||
|
||||
Instant i = ProtobufUtil.toInstant(t);
|
||||
|
||||
assertThat(i.getEpochSecond()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,4 @@ gameyfin:
|
||||
igdb:
|
||||
api:
|
||||
client-id: igdb_client_id
|
||||
client-secret: igdb_client_secret
|
||||
config:
|
||||
preferred-platforms: 6
|
||||
client-secret: igdb_client_secret
|
||||
Reference in New Issue
Block a user