mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-15 08:15:37 +00:00
Implement some more test cases for ProtobufUtil and FilenameUtil
This commit is contained in:
@@ -141,6 +141,12 @@
|
||||
<artifactId>mockwebserver</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.jimfs</groupId>
|
||||
<artifactId>jimfs</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Dev -->
|
||||
|
||||
@@ -9,7 +9,6 @@ import io.github.resilience4j.reactor.bulkhead.operator.BulkheadOperator;
|
||||
import io.github.resilience4j.reactor.ratelimiter.operator.RateLimiterOperator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -111,7 +110,7 @@ public class IgdbWrapper {
|
||||
Igdb.GameResult.class
|
||||
);
|
||||
|
||||
if(gameResult == null) return Collections.emptyList();
|
||||
if (gameResult == null) return Collections.emptyList();
|
||||
|
||||
return gameResult.getGamesList().stream().map(gameMapper::toAutocompleteSuggestionDto).toList();
|
||||
}
|
||||
@@ -129,10 +128,10 @@ public class IgdbWrapper {
|
||||
|
||||
// Try to remove brackets (and their content) at the end of the search term and search again
|
||||
// Although this process is recursive, we will only end up with a maximum recursion depth of two
|
||||
Pattern brackets = Pattern.compile ("[()<>{}\\[\\]]");
|
||||
Pattern brackets = Pattern.compile("[()<>{}\\[\\]]");
|
||||
Matcher hasBrackets = brackets.matcher(searchTerm);
|
||||
|
||||
if(hasBrackets.find()) {
|
||||
if (hasBrackets.find()) {
|
||||
String searchTermWithoutBrackets = searchTerm.split(brackets.pattern())[0].trim();
|
||||
log.warn("Trying again with search term '{}'", searchTermWithoutBrackets);
|
||||
return searchForGameByTitle(searchTermWithoutBrackets);
|
||||
|
||||
@@ -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