mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Add test for FileFilter
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -450,6 +450,12 @@
|
|||||||
<version>5.20.0</version>
|
<version>5.20.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>5.20.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
|
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class FileFilterTest {
|
||||||
|
@Mock(strictness = Mock.Strictness.LENIENT)
|
||||||
|
File file;
|
||||||
|
|
||||||
|
@Mock(strictness = Mock.Strictness.LENIENT)
|
||||||
|
BasicFileAttributes attributes;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void beforeEach() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> accept() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of("~/video.mkv", new String[]{".mkv"}, null, null, ".*", true),
|
||||||
|
Arguments.of("~/video.mp4", new String[]{".mkv"}, null, null, ".*", false),
|
||||||
|
|
||||||
|
Arguments.of("~/video.mkv", new String[]{".mkv"}, null, null, "v.*", true),
|
||||||
|
Arguments.of("~/video.mkv", new String[]{".mkv"}, null, null, "a.*", false),
|
||||||
|
|
||||||
|
Arguments.of("~/video.mkv", new String[]{".mkv"}, new Date(System.currentTimeMillis() - 1000), new Date(), ".*", false),
|
||||||
|
Arguments.of("~/video.mkv", new String[]{".mkv"}, new Date(), new Date(System.currentTimeMillis() - 1000), ".*", true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource
|
||||||
|
void accept(String path, String[] args, Date fileCreationDate, Date filterDate, String pattern, boolean expected) {
|
||||||
|
when(file.getAbsolutePath()).thenReturn(path);
|
||||||
|
when(file.getName()).thenReturn(List.of(path.split("/")).get(1));
|
||||||
|
when(file.toPath()).thenReturn(Path.of(TEST_FILE));
|
||||||
|
|
||||||
|
Config.getInstance(true).setIncludePattern(Pattern.compile(pattern));
|
||||||
|
if (filterDate != null) Config.getInstance().setFilterDate(filterDate);
|
||||||
|
|
||||||
|
try (MockedStatic<DateUtils> mockedFiles = Mockito.mockStatic(DateUtils.class)) {
|
||||||
|
mockedFiles
|
||||||
|
.when(() -> DateUtils.convert(anyLong()))
|
||||||
|
.thenReturn(fileCreationDate);
|
||||||
|
|
||||||
|
assertEquals(expected, FileFilter.accept(file, args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,33 +1,12 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.joining;
|
|
||||||
|
|
||||||
public class TestUtil {
|
public class TestUtil {
|
||||||
public static String yamlList(ConfigProperty main, ConfigProperty... child) {
|
|
||||||
return main.prop() + ":\n" + Arrays.stream(child)
|
|
||||||
.map(ConfigProperty::prop)
|
|
||||||
.collect(joining("\n", " - ", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Arguments argumentsOf(ConfigProperty property, boolean required, T defaultValue, String yaml, String[] cmd,
|
|
||||||
ValidationResult result) {
|
|
||||||
return Arguments.of(property, required, defaultValue, yaml, cmd, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Arguments argumentsOf(ConfigProperty property, boolean required, boolean append, String yaml, String[] cmd,
|
|
||||||
ValidationResult result, int expectedSize) {
|
|
||||||
return Arguments.of(property, required, append, yaml, cmd, result, expectedSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FileInfo createFileInfoAudio(Set<FileAttribute> defaultAudio, FileAttribute desiredAudio, AttributeConfig config) {
|
public static FileInfo createFileInfoAudio(Set<FileAttribute> defaultAudio, FileAttribute desiredAudio, AttributeConfig config) {
|
||||||
FileInfo fileInfo = new FileInfo(null);
|
FileInfo fileInfo = new FileInfo(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user