mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 18:15:57 +01:00
Add tests
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.createFileInfo;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FileInfoDtoTest {
|
||||
private static final FileAttribute AUDIO_GER_DEFAULT = new FileAttribute(0, "ger", "", true, false, LaneType.AUDIO);
|
||||
private static final FileAttribute AUDIO_GER = new FileAttribute(0, "ger", "", false, false, LaneType.AUDIO);
|
||||
private static final FileAttribute AUDIO_ENG_DEFAULT = new FileAttribute(1, "eng", "", true, false, LaneType.AUDIO);
|
||||
private static final FileAttribute AUDIO_ENG = new FileAttribute(1, "eng", "", false, false, LaneType.AUDIO);
|
||||
|
||||
private static final FileAttribute SUB_GER_DEFAULT = new FileAttribute(0, "ger", "", true, false, LaneType.SUBTITLES);
|
||||
private static final FileAttribute SUB_GER = new FileAttribute(0, "ger", "", false, false, LaneType.SUBTITLES);
|
||||
private static final FileAttribute SUB_ENG_DEFAULT = new FileAttribute(1, "eng", "", true, false, LaneType.SUBTITLES);
|
||||
private static final FileAttribute SUB_ENG = new FileAttribute(1, "eng", "", false, false, LaneType.SUBTITLES);
|
||||
|
||||
|
||||
private static Stream<Arguments> isAudioDifferent() {
|
||||
return Stream.of(
|
||||
Arguments.of(createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT), false),
|
||||
Arguments.of(createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_ENG), true),
|
||||
Arguments.of(createFileInfo(Set.of(AUDIO_GER_DEFAULT, AUDIO_ENG_DEFAULT), AUDIO_GER_DEFAULT), true),
|
||||
Arguments.of(createFileInfo(Set.of(), AUDIO_GER), true),
|
||||
Arguments.of(createFileInfo(null, AUDIO_GER), true)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void isAudioDifferent(FileInfoDto underTest, boolean expected) {
|
||||
assertEquals(expected, underTest.isAudioDifferent());
|
||||
}
|
||||
|
||||
private static Stream<Arguments> isSubtitleDifferent() {
|
||||
return Stream.of(
|
||||
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT), SUB_GER_DEFAULT, new AttributeConfig("", "ger")), false),
|
||||
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT), SUB_ENG, new AttributeConfig("", "eng")), true),
|
||||
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT, SUB_ENG_DEFAULT), SUB_ENG, new AttributeConfig("", "eng")), true),
|
||||
Arguments.of(createFileInfo(Set.of(), SUB_ENG, new AttributeConfig("", "ger")), true),
|
||||
Arguments.of(createFileInfo(null, SUB_GER, new AttributeConfig("", "ger")), true),
|
||||
Arguments.of(createFileInfo(null, null, new AttributeConfig("", "OFF")), false),
|
||||
Arguments.of(createFileInfo(Set.of(), null, new AttributeConfig("", "OFF")), false),
|
||||
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT), null, new AttributeConfig("", "OFF")), true)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void isSubtitleDifferent(FileInfoDto underTest, boolean expected) {
|
||||
assertEquals(expected, underTest.isSubtitleDifferent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DateUtilsTest {
|
||||
|
||||
@Test
|
||||
void convert() {
|
||||
Date expectedDate = new Date(0);
|
||||
String expectedString = "01.01.1970-01:00:00";
|
||||
|
||||
assertEquals(expectedDate, DateUtils.convert(0));
|
||||
assertEquals(expectedDate, DateUtils.convert(expectedString, expectedDate));
|
||||
assertEquals(expectedDate, DateUtils.convert("1234;15", expectedDate));
|
||||
assertEquals(expectedString, DateUtils.convert(expectedDate));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SetUtilsTest {
|
||||
|
||||
@Test
|
||||
void retainOf() {
|
||||
List<Integer> list1 = List.of(1, 2, 3, 4, 5);
|
||||
List<Integer> list2 = List.of(2, 4, 6, 8, 10);
|
||||
Set<Integer> expected = Set.of(2, 4);
|
||||
|
||||
assertEquals(expected, SetUtils.retainOf(list1, list2));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
@@ -25,4 +29,18 @@ public class TestUtil {
|
||||
return Arguments.of(property, required, append, yaml, cmd, result, expectedSize);
|
||||
}
|
||||
|
||||
public static FileInfoDto createFileInfo(Set<FileAttribute> defaultAudio, FileAttribute desiredAudio) {
|
||||
FileInfoDto fileInfoDto = new FileInfoDto(null);
|
||||
fileInfoDto.setDefaultAudioLanes(defaultAudio);
|
||||
fileInfoDto.setDesiredAudioLane(desiredAudio);
|
||||
return fileInfoDto;
|
||||
}
|
||||
|
||||
public static FileInfoDto createFileInfo(Set<FileAttribute> defaultSubtitle, FileAttribute desiredSubtitle, AttributeConfig config) {
|
||||
FileInfoDto fileInfoDto = new FileInfoDto(null);
|
||||
fileInfoDto.setDefaultSubtitleLanes(defaultSubtitle);
|
||||
fileInfoDto.setDesiredSubtitleLane(desiredSubtitle);
|
||||
fileInfoDto.setMatchedConfig(config);
|
||||
return fileInfoDto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user