forked from j62/ctbrec
1
0
Fork 0

Add tests for RecordingPreconditions

This commit is contained in:
0xb00bface 2021-06-06 13:26:59 +02:00
parent 12899cac4c
commit a9536a428f
25 changed files with 485 additions and 136 deletions

View File

@ -11,7 +11,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

View File

@ -12,5 +12,5 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=15 org.eclipse.jdt.core.compiler.source=15

View File

@ -6,7 +6,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -19,5 +23,10 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -1,4 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8 encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

View File

@ -70,16 +70,6 @@
<version>3.1.0</version> <version>3.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>javax.xml.bind</groupId> <groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId> <artifactId>jaxb-api</artifactId>

View File

@ -40,6 +40,7 @@ import ctbrec.recorder.postprocessing.Script;
import ctbrec.sites.Site; import ctbrec.sites.Site;
import ctbrec.sites.cam4.Cam4Model; import ctbrec.sites.cam4.Cam4Model;
// TODO don't use singleton pattern
public class Config { public class Config {
private static final Logger LOG = LoggerFactory.getLogger(Config.class); private static final Logger LOG = LoggerFactory.getLogger(Config.class);
@ -56,7 +57,7 @@ public class Config {
private boolean savingDisabled = false; private boolean savingDisabled = false;
public static final String RECORDING_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss_SSS"; public static final String RECORDING_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss_SSS";
private Config(List<Site> sites) { public Config(List<Site> sites) {
this.sites = sites; this.sites = sites;
if(System.getProperty("ctbrec.config.dir") != null) { if(System.getProperty("ctbrec.config.dir") != null) {
configDir = new File(System.getProperty("ctbrec.config.dir")); configDir = new File(System.getProperty("ctbrec.config.dir"));

View File

@ -287,7 +287,7 @@ public class NextGenLocalRecorder implements Recorder {
return CompletableFuture.runAsync(() -> { return CompletableFuture.runAsync(() -> {
recorderLock.lock(); recorderLock.lock();
try { try {
preconditions.check(model); preconditions.check(model, config);
LOG.info("Starting recording for model {}", model.getName()); LOG.info("Starting recording for model {}", model.getName());
Download download = createDownload(model); Download download = createDownload(model);
Recording rec = createRecording(download); Recording rec = createRecording(download);

View File

@ -23,14 +23,17 @@ public class RecordingPreconditions {
private static final Logger LOG = LoggerFactory.getLogger(RecordingPreconditions.class); private static final Logger LOG = LoggerFactory.getLogger(RecordingPreconditions.class);
private Config config;
private NextGenLocalRecorder recorder; private NextGenLocalRecorder recorder;
private long lastPreconditionMessage = 0; private long lastPreconditionMessage = 0;
RecordingPreconditions(NextGenLocalRecorder recorder) { RecordingPreconditions(NextGenLocalRecorder recorder) {
this.recorder = recorder; this.recorder = recorder;
} }
void check(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException { void check(Model model, Config config) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
this.config = config;
LOG.debug("Checking preconditions for model {}", model); LOG.debug("Checking preconditions for model {}", model);
ensureRecorderIsActive(); ensureRecorderIsActive();
ensureModelIsNotSuspended(model); ensureModelIsNotSuspended(model);
@ -133,7 +136,7 @@ public class RecordingPreconditions {
} }
private boolean downloadSlotAvailable() { private boolean downloadSlotAvailable() {
int concurrentRecordings = Config.getInstance().getSettings().concurrentRecordings; int concurrentRecordings = config.getSettings().concurrentRecordings;
return concurrentRecordings == 0 || concurrentRecordings > 0 && recorder.getRecordingProcesses().size() < concurrentRecordings; return concurrentRecordings == 0 || concurrentRecordings > 0 && recorder.getRecordingProcesses().size() < concurrentRecordings;
} }
@ -168,7 +171,7 @@ public class RecordingPreconditions {
} }
private Optional<Model> getModelForUrl(String modelUrl) { private Optional<Model> getModelForUrl(String modelUrl) {
return Config.getInstance().getSettings().models.stream() return config.getSettings().models.stream()
.filter(m -> Objects.equals(m.getUrl(), modelUrl)) .filter(m -> Objects.equals(m.getUrl(), modelUrl))
.findFirst(); .findFirst();
} }

View File

@ -26,7 +26,7 @@ import okhttp3.Response;
public class XloveCamHttpClient extends HttpClient { public class XloveCamHttpClient extends HttpClient {
private static final Logger LOG = LoggerFactory.getLogger(XloveCamHttpClient.class); private static final Logger LOG = LoggerFactory.getLogger(XloveCamHttpClient.class);
private static final Pattern CSRF_PATTERN = Pattern.compile("CSRFToken\s*=\s*\"(.*?)\";"); private static final Pattern CSRF_PATTERN = Pattern.compile("CSRFToken\\s*=\\s*\"(.*?)\";");
private final Random rng = new Random(); private final Random rng = new Random();
public XloveCamHttpClient() { public XloveCamHttpClient() {

View File

@ -1,12 +1,12 @@
package ctbrec; package ctbrec;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class VersionTest { class VersionTest {
@Test @Test
public void testOf() { void testOf() {
Version v = Version.of("1.0.0"); Version v = Version.of("1.0.0");
assertEquals(1, v.major); assertEquals(1, v.major);
assertEquals(0, v.minor); assertEquals(0, v.minor);
@ -25,7 +25,7 @@ public class VersionTest {
} }
@Test @Test
public void testCompareTo() { void testCompareTo() {
Version a = Version.of("1.0.0"); Version a = Version.of("1.0.0");
Version b = Version.of("1.0.0"); Version b = Version.of("1.0.0");
assertEquals(0, a.compareTo(b)); assertEquals(0, a.compareTo(b));

View File

@ -0,0 +1,331 @@
package ctbrec.recorder;
import static java.time.temporal.ChronoUnit.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.ModelGroup;
import ctbrec.Recording;
import ctbrec.Settings;
import ctbrec.recorder.download.Download;
class RecordingPreconditionsTest {
private Config config;
private Settings settings = new Settings();
@BeforeEach
void setup() {
config = mock(Config.class);
when(config.getSettings()).thenReturn(settings);
try (MockedStatic<Config> staticConfigMock = mockStatic(Config.class)) {
staticConfigMock.when(Config::getInstance).thenReturn(config);
}
}
@Test
void testRecorderNotInRecordingMode() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
Model model = mock(Model.class);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertEquals("Recorder is not in recording mode", ex.getMessage());
}
@Test
void testModelIsSuspended() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
Model model = mock(Model.class);
when(recorder.isRecording()).thenReturn(true);
when(model.isSuspended()).thenReturn(true);
when(model.toString()).thenReturn("Mockita Boobilicious");
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertEquals("Recording for model Mockita Boobilicious is suspended", ex.getMessage());
}
@Test
void testModelMarkedForLaterRecording() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
Model model = mock(Model.class);
when(recorder.isRecording()).thenReturn(true);
when(model.isMarkedForLaterRecording()).thenReturn(true);
when(model.toString()).thenReturn("Mockita Boobilicious");
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertEquals("Model Mockita Boobilicious is marked for later recording", ex.getMessage());
}
@Test
void testRecordUntil() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
Model model = mock(Model.class);
when(recorder.isRecording()).thenReturn(true);
when(model.getRecordUntil()).thenReturn(Instant.now().minus(1, HOURS));
when(model.toString()).thenReturn("Mockita Boobilicious");
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertTrue(ex.getMessage().contains("Recording expired at "));
}
@Test
void testRecordingAlreadyRunning() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
Model model = mock(Model.class);
when(recorder.isRecording()).thenReturn(true);
Map<Model, Recording> recordingProcesses = new HashMap<>();
recordingProcesses.put(model, new Recording());
when(recorder.getRecordingProcesses()).thenReturn(recordingProcesses);
when(model.getRecordUntil()).thenReturn(Instant.MAX);
when(model.toString()).thenReturn("Mockita Boobilicious");
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertEquals("A recording for model Mockita Boobilicious is already running", ex.getMessage());
}
@Test
void testModelShouldBeRecorded() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
Model model = mock(Model.class);
when(recorder.isRecording()).thenReturn(true);
List<Model> modelsToRecord = new LinkedList<>();
when(recorder.getModels()).thenReturn(modelsToRecord);
when(model.getRecordUntil()).thenReturn(Instant.MAX);
when(model.toString()).thenReturn("Mockita Boobilicious");
when(model.isOnline(true)).thenReturn(true);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertEquals("Model Mockita Boobilicious has been removed. Restarting of recording cancelled.", ex.getMessage());
modelsToRecord.add(model);
reset(recorder);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(true);
assertDoesNotThrow(() -> preconditions.check(model, config));
}
@Test
void testEnoughSpace() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
Model model = mock(Model.class);
when(model.getRecordUntil()).thenReturn(Instant.MAX);
when(model.toString()).thenReturn("Mockita Boobilicious");
when(model.isOnline(true)).thenReturn(true);
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
List<Model> modelsToRecord = new LinkedList<>();
modelsToRecord.add(model);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(false);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(model, config));
assertEquals("Not enough disk space for recording", ex.getMessage());
}
@Test
void testNoOtherFromGroupIsRecording() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
Model mockita = mock(Model.class);
when(mockita.getRecordUntil()).thenReturn(Instant.MAX);
when(mockita.toString()).thenReturn("Mockita Boobilicious");
when(mockita.isOnline(true)).thenReturn(true);
when(mockita.getUrl()).thenReturn("http://localhost/mockita");
Model theOtherOne = mock(Model.class);
when(theOtherOne.getRecordUntil()).thenReturn(Instant.MAX);
when(theOtherOne.toString()).thenReturn("The Other One");
when(theOtherOne.isOnline(true)).thenReturn(true);
when(theOtherOne.getUrl()).thenReturn("http://localhost/theOtherOne");
ModelGroup group = new ModelGroup();
group.add(theOtherOne);
group.add(mockita);
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
List<Model> modelsToRecord = new LinkedList<>();
settings.models = modelsToRecord;
modelsToRecord.add(theOtherOne);
modelsToRecord.add(mockita);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(true);
when(recorder.getModelGroup(theOtherOne)).thenReturn(Optional.of(group));
when(recorder.getModelGroup(mockita)).thenReturn(Optional.of(group));
Map<Model, Recording> recordingProcesses = new HashMap<>();
recordingProcesses.put(theOtherOne, new Recording());
when(recorder.getRecordingProcesses()).thenReturn(recordingProcesses);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(mockita, config));
assertEquals("The Other One from the same group is already recorded", ex.getMessage());
}
@Test
void testModelIsOffline() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
Model mockita = mock(Model.class);
when(mockita.getRecordUntil()).thenReturn(Instant.MAX);
when(mockita.getName()).thenReturn("Mockita Boobilicious");
when(mockita.toString()).thenReturn("Mockita Boobilicious");
when(mockita.isOnline(true)).thenReturn(false);
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
List<Model> modelsToRecord = new LinkedList<>();
settings.models = modelsToRecord;
modelsToRecord.add(mockita);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(true);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(mockita, config));
assertEquals("Mockita Boobilicious's room is not public", ex.getMessage());
}
@Test
void testModelIsOnlineWithExpection() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
Model mockita = mock(Model.class);
when(mockita.isOnline(true)).thenThrow(new IOException("Service unavailable"));
when(mockita.getRecordUntil()).thenReturn(Instant.MAX);
when(mockita.getName()).thenReturn("Mockita Boobilicious");
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
List<Model> modelsToRecord = new LinkedList<>();
settings.models = modelsToRecord;
modelsToRecord.add(mockita);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(true);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(mockita, config));
assertEquals("Mockita Boobilicious's room is not public", ex.getMessage());
reset(mockita);
when(mockita.isOnline(true)).thenThrow(new InterruptedException());
when(mockita.getRecordUntil()).thenReturn(Instant.MAX);
when(mockita.getName()).thenReturn("Mockita Boobilicious");
ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(mockita, config));
assertEquals("Mockita Boobilicious's room is not public", ex.getMessage());
}
@Test
void testDownloadSlotsExhausted() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
settings.concurrentRecordings = 1;
Model mockita = mock(Model.class);
when(mockita.isOnline(true)).thenReturn(true);
when(mockita.getRecordUntil()).thenReturn(Instant.MAX);
when(mockita.getName()).thenReturn("Mockita Boobilicious");
Model theOtherOne = mock(Model.class);
when(theOtherOne.getRecordUntil()).thenReturn(Instant.MAX);
when(theOtherOne.toString()).thenReturn("The Other One");
when(theOtherOne.isOnline(true)).thenReturn(true);
when(theOtherOne.getUrl()).thenReturn("http://localhost/theOtherOne");
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
List<Model> modelsToRecord = new LinkedList<>();
settings.models = modelsToRecord;
modelsToRecord.add(mockita);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(true);
Map<Model, Recording> recordingProcesses = new HashMap<>();
recordingProcesses.put(theOtherOne, new Recording());
when(recorder.getRecordingProcesses()).thenReturn(recordingProcesses);
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
PreconditionNotMetException ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(mockita, config));
assertEquals("Other models have higher prio, not starting recording for Mockita Boobilicious", ex.getMessage());
settings.concurrentRecordings = -1;
ex = assertThrows(PreconditionNotMetException.class, () -> preconditions.check(mockita, config));
assertEquals("Other models have higher prio, not starting recording for Mockita Boobilicious", ex.getMessage());
settings.concurrentRecordings = 0;
assertDoesNotThrow(() -> preconditions.check(mockita, config));
settings.concurrentRecordings = 1;
recordingProcesses.clear();
assertDoesNotThrow(() -> preconditions.check(mockita, config));
}
@Test
void testDownloadSlotFreedUp() throws InvalidKeyException, NoSuchAlgorithmException, IOException, ExecutionException, InterruptedException {
settings.concurrentRecordings = 1;
Model mockita = mock(Model.class);
when(mockita.isOnline(true)).thenReturn(true);
when(mockita.getRecordUntil()).thenReturn(Instant.MAX);
when(mockita.getName()).thenReturn("Mockita Boobilicious");
when(mockita.getPriority()).thenReturn(100);
NextGenLocalRecorder recorder = mock(NextGenLocalRecorder.class);
List<Model> modelsToRecord = new LinkedList<>();
settings.models = modelsToRecord;
modelsToRecord.add(mockita);
when(recorder.isRecording()).thenReturn(true);
when(recorder.getModels()).thenReturn(modelsToRecord);
when(recorder.enoughSpaceForRecording()).thenReturn(true);
Map<Model, Recording> recordingProcesses = new HashMap<>();
when(recorder.getRecordingProcesses()).thenReturn(recordingProcesses);
Model theOtherOne = mock(Model.class);
when(theOtherOne.getRecordUntil()).thenReturn(Instant.MAX);
when(theOtherOne.toString()).thenReturn("The Other One");
when(theOtherOne.isOnline(true)).thenReturn(true);
when(theOtherOne.getUrl()).thenReturn("http://localhost/theOtherOne");
when(theOtherOne.getPriority()).thenReturn(50);
recordingProcesses.put(theOtherOne, mockRecordingProcess(theOtherOne));
Model lowestPrio = mock(Model.class);
when(lowestPrio.getRecordUntil()).thenReturn(Instant.MAX);
when(lowestPrio.toString()).thenReturn("Lowest");
when(lowestPrio.isOnline(true)).thenReturn(true);
when(lowestPrio.getUrl()).thenReturn("http://localhost/lowest");
when(lowestPrio.getPriority()).thenReturn(1);
recordingProcesses.put(theOtherOne, mockRecordingProcess(lowestPrio));
RecordingPreconditions preconditions = new RecordingPreconditions(recorder);
assertDoesNotThrow(() -> preconditions.check(mockita, config));
verify(recorder).stopRecordingProcess(lowestPrio);
}
private Recording mockRecordingProcess(Model model) {
Download download = mock(Download.class);
when(download.getModel()).thenReturn(model);
Recording runningRecording = mock(Recording.class);
when(runningRecording.getDownload()).thenReturn(download);
return runningRecording;
}
}

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -10,20 +10,20 @@ import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Locale; import java.util.Locale;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Recording; import ctbrec.Recording;
public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest { class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
Recording rec; Recording rec;
Config config; Config config;
Move placeHolderAwarePp; Move placeHolderAwarePp;
@Override @Override
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
super.setup(); super.setup();
rec = new Recording(); rec = new Recording();
@ -37,7 +37,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
} }
@Test @Test
public void testModelNameReplacement() { void testModelNameReplacement() {
String input = "asdf_${modelName}_asdf"; String input = "asdf_${modelName}_asdf";
assertEquals("asdf_Mockita Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_Mockita Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
input = "asdf_${modelDisplayName}_asdf"; input = "asdf_${modelDisplayName}_asdf";
@ -47,7 +47,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
} }
@Test @Test
public void testSiteNameReplacement() { void testSiteNameReplacement() {
String input = "asdf_${siteName}_asdf"; String input = "asdf_${siteName}_asdf";
assertEquals("asdf_Chaturbate_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_Chaturbate_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
input = "asdf_${siteSanitizedName}_asdf"; input = "asdf_${siteSanitizedName}_asdf";
@ -55,7 +55,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
} }
@Test @Test
public void testUtcTimeReplacement() { void testUtcTimeReplacement() {
// without user defined pattern // without user defined pattern
String date = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss") String date = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss")
.withLocale(Locale.US) .withLocale(Locale.US)
@ -82,7 +82,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
} }
@Test @Test
public void testLocalTimeReplacement() { void testLocalTimeReplacement() {
String date = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss") String date = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss")
.withLocale(Locale.US) .withLocale(Locale.US)
.withZone(ZoneId.systemDefault()) .withZone(ZoneId.systemDefault())
@ -99,44 +99,44 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
} }
@Test @Test
public void testEpochReplacement() { void testEpochReplacement() {
long epoch = now.toEpochMilli() / 1000; long epoch = now.toEpochMilli() / 1000;
String input = "asdf_${epochSecond}_asdf"; String input = "asdf_${epochSecond}_asdf";
assertEquals("asdf_" + epoch + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_" + epoch + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
} }
@Test @Test
public void testFileSuffixReplacement() { void testFileSuffixReplacement() {
String input = "asdf_${fileSuffix}_asdf"; String input = "asdf_${fileSuffix}_asdf";
assertEquals("asdf_ts_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_ts_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
} }
@Test @Test
public void testRecordingsDirReplacement() { void testRecordingsDirReplacement() {
String input = "asdf_${recordingsDir}_asdf"; String input = "asdf_${recordingsDir}_asdf";
assertEquals("asdf_" + recDir.toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_" + recDir.toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
} }
@Test @Test
public void testAbsolutePathReplacement() { void testAbsolutePathReplacement() {
String input = "asdf_${absolutePath}_asdf"; String input = "asdf_${absolutePath}_asdf";
assertEquals("asdf_" + postProcessed.getAbsolutePath().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_" + postProcessed.getAbsolutePath().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
} }
@Test @Test
public void testAbsoluteParentPathReplacement() { void testAbsoluteParentPathReplacement() {
String input = "asdf_${absoluteParentPath}_asdf"; String input = "asdf_${absoluteParentPath}_asdf";
assertEquals("asdf_" + postProcessed.getParentFile().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_" + postProcessed.getParentFile().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
} }
@Test @Test
public void testModelNotesReplacement() { void testModelNotesReplacement() {
String input = "asdf_${modelNotes}_asdf"; String input = "asdf_${modelNotes}_asdf";
assertEquals("asdf_tag,_foo,_bar_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf_tag,_foo,_bar_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
} }
@Test @Test
public void testPlaceholderDefaultValues() throws IOException { void testPlaceholderDefaultValues() throws IOException {
String input = "asdf_${modelGroupName?${modelSanitizedName?anonymous}}_asdf"; String input = "asdf_${modelGroupName?${modelSanitizedName?anonymous}}_asdf";
PostProcessingContext ctx = createPostProcessingContext(rec, null, config); PostProcessingContext ctx = createPostProcessingContext(rec, null, config);
ctx.getRecording().getModel().setName(null); ctx.getRecording().getModel().setName(null);
@ -154,7 +154,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
} }
@Test @Test
public void testMissingValueForPlaceholder() throws IOException { void testMissingValueForPlaceholder() throws IOException {
String input = "asdf_${modelNotes}_asdf"; String input = "asdf_${modelNotes}_asdf";
when(config.getModelNotes(any())).thenReturn(null); when(config.getModelNotes(any())).thenReturn(null);
assertEquals("asdf__asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config))); assertEquals("asdf__asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));

View File

@ -12,8 +12,8 @@ import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import ctbrec.Config; import ctbrec.Config;
@ -37,7 +37,7 @@ public abstract class AbstractPpTest {
MockedStatic<Config> configStatic; MockedStatic<Config> configStatic;
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
baseDir = Files.createTempDirectory("ctbrec_test_"); baseDir = Files.createTempDirectory("ctbrec_test_");
recDir = baseDir.resolve("recordings"); recDir = baseDir.resolve("recordings");
@ -52,7 +52,7 @@ public abstract class AbstractPpTest {
FileUtils.touch(new File(originalDir, "playlist.m3u8")); FileUtils.touch(new File(originalDir, "playlist.m3u8"));
} }
@After @AfterEach
public void teardown() throws IOException { public void teardown() throws IOException {
FileUtils.deleteDirectory(baseDir.toFile()); FileUtils.deleteDirectory(baseDir.toFile());
if (configStatic != null) { if (configStatic != null) {
@ -63,7 +63,8 @@ public abstract class AbstractPpTest {
Config mockConfig() { Config mockConfig() {
Config config = mock(Config.class); Config config = mock(Config.class);
when(config.getSettings()).thenReturn(mockSettings()); Settings settings = mockSettings();
when(config.getSettings()).thenReturn(settings);
when(config.getModelNotes(any())).thenReturn("tag, foo, bar"); when(config.getModelNotes(any())).thenReturn("tag, foo, bar");
when(config.getConfigDir()).thenReturn(new File(baseDir.toFile(), "config")); when(config.getConfigDir()).thenReturn(new File(baseDir.toFile(), "config"));
configStatic = mockStatic(Config.class); configStatic = mockStatic(Config.class);

View File

@ -1,18 +1,18 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException; import java.io.IOException;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Recording; import ctbrec.Recording;
public class CopyTest extends AbstractPpTest { class CopyTest extends AbstractPpTest {
@Test @Test
public void testCopySingleFile() throws IOException, InterruptedException { void testCopySingleFile() throws IOException, InterruptedException {
Config config = mockConfig(); Config config = mockConfig();
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
@ -28,7 +28,7 @@ public class CopyTest extends AbstractPpTest {
} }
@Test @Test
public void testCopyDirectory() throws IOException, InterruptedException { void testCopyDirectory() throws IOException, InterruptedException {
Config config = mockConfig(); Config config = mockConfig();
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
@ -44,7 +44,7 @@ public class CopyTest extends AbstractPpTest {
} }
@Test @Test
public void testGetName() { void testGetName() {
assertEquals("create a copy", new Copy().getName()); assertEquals("create a copy", new Copy().getName());
} }
} }

View File

@ -1,19 +1,19 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Recording; import ctbrec.Recording;
public class DeleteOriginalTest extends AbstractPpTest { class DeleteOriginalTest extends AbstractPpTest {
@Test @Test
public void testPostProcessWithSingleFile() throws IOException, InterruptedException { void testPostProcessWithSingleFile() throws IOException, InterruptedException {
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
rec.setAbsoluteFile(original); rec.setAbsoluteFile(original);
@ -31,7 +31,7 @@ public class DeleteOriginalTest extends AbstractPpTest {
} }
@Test @Test
public void testPostProcessWithDirectory() throws IOException, InterruptedException { void testPostProcessWithDirectory() throws IOException, InterruptedException {
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
rec.setAbsoluteFile(originalDir); rec.setAbsoluteFile(originalDir);
@ -50,7 +50,7 @@ public class DeleteOriginalTest extends AbstractPpTest {
} }
@Test @Test
public void testGetName() { void testGetName() {
assertEquals("delete original", new DeleteOriginal().getName()); assertEquals("delete original", new DeleteOriginal().getName());
} }

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -9,7 +9,7 @@ import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import ctbrec.Config; import ctbrec.Config;
@ -18,15 +18,15 @@ import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.download.Download; import ctbrec.recorder.download.Download;
import ctbrec.recorder.download.VideoLengthDetector; import ctbrec.recorder.download.VideoLengthDetector;
public class DeleteTooShortTest extends AbstractPpTest { class DeleteTooShortTest extends AbstractPpTest {
@Test @Test
public void tooShortSingleFileRecShouldBeDeleted() throws IOException, InterruptedException { void tooShortSingleFileRecShouldBeDeleted() throws IOException, InterruptedException {
testProcess(original); testProcess(original);
} }
@Test @Test
public void tooShortDirectoryRecShouldBeDeleted() throws IOException, InterruptedException { void tooShortDirectoryRecShouldBeDeleted() throws IOException, InterruptedException {
testProcess(originalDir); testProcess(originalDir);
} }
@ -52,12 +52,12 @@ public class DeleteTooShortTest extends AbstractPpTest {
} }
@Test @Test
public void testGetName() { void testGetName() {
assertEquals("delete too short", new DeleteTooShort().getName()); assertEquals("delete too short", new DeleteTooShort().getName());
} }
@Test @Test
public void testDisabledWithSingleFile() throws IOException, InterruptedException { void testDisabledWithSingleFile() throws IOException, InterruptedException {
Recording rec = createRec(original); Recording rec = createRec(original);
Config config = mockConfig(); Config config = mockConfig();
RecordingManager recordingManager = new RecordingManager(config, Collections.emptyList()); RecordingManager recordingManager = new RecordingManager(config, Collections.emptyList());
@ -74,7 +74,7 @@ public class DeleteTooShortTest extends AbstractPpTest {
} }
@Test @Test
public void longEnoughVideoShouldStay() throws IOException, InterruptedException { void longEnoughVideoShouldStay() throws IOException, InterruptedException {
Recording rec = createRec(original); Recording rec = createRec(original);
Config config = mockConfig(); Config config = mockConfig();
RecordingManager recordingManager = new RecordingManager(config, Collections.emptyList()); RecordingManager recordingManager = new RecordingManager(config, Collections.emptyList());

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -10,16 +10,16 @@ import java.nio.file.Files;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.Recording; import ctbrec.Recording;
public class MoveDirectoryTest extends AbstractPpTest { class MoveDirectoryTest extends AbstractPpTest {
@Test @Test
public void testOriginalFileReplacement() throws IOException { void testOriginalFileReplacement() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
@ -37,7 +37,7 @@ public class MoveDirectoryTest extends AbstractPpTest {
} }
@Test @Test
public void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException { void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException {
Model model = mockModel(); Model model = mockModel();
Recording rec = mock(Recording.class); Recording rec = mock(Recording.class);
when(rec.getModel()).thenReturn(model); when(rec.getModel()).thenReturn(model);
@ -50,6 +50,6 @@ public class MoveDirectoryTest extends AbstractPpTest {
Move pp = new Move(); Move pp = new Move();
Config config = mockConfig(); Config config = mockConfig();
pp.getConfig().put(Move.PATH_TEMPLATE, new File(baseDir.toFile(), Move.DEFAULT).getAbsolutePath()); pp.getConfig().put(Move.PATH_TEMPLATE, new File(baseDir.toFile(), Move.DEFAULT).getAbsolutePath());
pp.postprocess(createPostProcessingContext(rec, recordingManager, config)); assertDoesNotThrow(() -> pp.postprocess(createPostProcessingContext(rec, recordingManager, config)));
} }
} }

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -9,16 +9,16 @@ import java.io.IOException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.Recording; import ctbrec.Recording;
public class MoveSingleFileTest extends AbstractPpTest { class MoveSingleFileTest extends AbstractPpTest {
@Test @Test
public void testOriginalFileReplacement() throws IOException { void testOriginalFileReplacement() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
@ -37,7 +37,7 @@ public class MoveSingleFileTest extends AbstractPpTest {
} }
@Test @Test
public void testEarlyExit() throws IOException { void testEarlyExit() throws IOException {
Model model = mockModel(); Model model = mockModel();
Recording rec = mock(Recording.class); Recording rec = mock(Recording.class);
when(rec.getModel()).thenReturn(model); when(rec.getModel()).thenReturn(model);
@ -52,7 +52,7 @@ public class MoveSingleFileTest extends AbstractPpTest {
} }
@Test @Test
public void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException { void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException {
Model model = mockModel(); Model model = mockModel();
Recording rec = mock(Recording.class); Recording rec = mock(Recording.class);
when(rec.getModel()).thenReturn(model); when(rec.getModel()).thenReturn(model);
@ -67,7 +67,7 @@ public class MoveSingleFileTest extends AbstractPpTest {
} }
@Test @Test
public void testToString() { void testToString() {
Move pp = new Move(); Move pp = new Move();
assertEquals("move", pp.toString()); assertEquals("move", pp.toString());

View File

@ -1,20 +1,20 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Recording; import ctbrec.Recording;
import ctbrec.recorder.RecordingManager; import ctbrec.recorder.RecordingManager;
public class RemoveKeepFileTest extends AbstractPpTest { class RemoveKeepFileTest extends AbstractPpTest {
@Test @Test
public void testPostProcessWithSingleFile() throws IOException, InterruptedException { void testPostProcessWithSingleFile() throws IOException, InterruptedException {
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
rec.setAbsoluteFile(original); rec.setAbsoluteFile(original);
@ -35,7 +35,7 @@ public class RemoveKeepFileTest extends AbstractPpTest {
} }
@Test @Test
public void testGetName() { void testGetName() {
assertEquals("remove recording, but keep the files", new RemoveKeepFile().getName()); assertEquals("remove recording, but keep the files", new RemoveKeepFile().getName());
} }

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -9,16 +9,16 @@ import java.nio.file.Files;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.Recording; import ctbrec.Recording;
public class RenameDirectoryTest extends AbstractPpTest { class RenameDirectoryTest extends AbstractPpTest {
@Test @Test
public void testOriginalFileReplacement() throws IOException { void testOriginalFileReplacement() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
@ -35,7 +35,7 @@ public class RenameDirectoryTest extends AbstractPpTest {
} }
@Test @Test
public void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException { void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Model model = mockModel(); Model model = mockModel();
Recording rec = mock(Recording.class); Recording rec = mock(Recording.class);

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -8,16 +8,16 @@ import java.io.IOException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.Recording; import ctbrec.Recording;
public class RenameSingleFileTest extends AbstractPpTest { class RenameSingleFileTest extends AbstractPpTest {
@Test @Test
public void testOriginalFileReplacement() throws IOException { void testOriginalFileReplacement() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Recording rec = new Recording(); Recording rec = new Recording();
rec.setModel(mockModel()); rec.setModel(mockModel());
@ -34,7 +34,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
} }
@Test @Test
public void testEarlyExit() throws IOException { void testEarlyExit() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Model model = mockModel(); Model model = mockModel();
Recording rec = mock(Recording.class); Recording rec = mock(Recording.class);
@ -49,7 +49,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
} }
@Test @Test
public void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException { void absoluteFileShouldKeepBeingOriginalIfFilesDiffer() throws IOException {
Config config = mockConfig(); Config config = mockConfig();
Model model = mockModel(); Model model = mockModel();
Recording rec = mock(Recording.class); Recording rec = mock(Recording.class);
@ -63,7 +63,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
} }
@Test @Test
public void testToString() { void testToString() {
Rename pp = new Rename(); Rename pp = new Rename();
assertEquals("rename", pp.toString()); assertEquals("rename", pp.toString());

View File

@ -1,11 +1,12 @@
package ctbrec.sites.mfc; package ctbrec.sites.mfc;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.json.JSONObject; import org.json.JSONObject;
import org.junit.Test; import org.junit.jupiter.api.Test;
import ctbrec.ReflectionUtil; import ctbrec.ReflectionUtil;
import ctbrec.StringUtil; import ctbrec.StringUtil;

View File

@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>ctbrec</groupId> <groupId>ctbrec</groupId>
@ -17,6 +17,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.javafx>17-ea+9</version.javafx> <version.javafx>17-ea+9</version.javafx>
<version.junit>5.7.2</version.junit>
</properties> </properties>
<build> <build>
@ -27,12 +28,12 @@
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version> <version>2.22.2</version>
<configuration> <configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile> <redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
@ -117,15 +118,21 @@
<version>2.8.0</version> <version>2.8.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>4.12</version> <version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId> <artifactId>mockito-inline</artifactId>
<version>3.5.11</version> <version>3.11.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -145,8 +152,23 @@
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>

View File

@ -1,28 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -6,11 +6,11 @@
<artifactId>server</artifactId> <artifactId>server</artifactId>
<parent> <parent>
<groupId>ctbrec</groupId> <groupId>ctbrec</groupId>
<artifactId>master</artifactId> <artifactId>master</artifactId>
<version>4.3.1</version> <version>4.3.1</version>
<relativePath>../master</relativePath> <relativePath>../master</relativePath>
</parent> </parent>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
@ -96,10 +96,5 @@
<version>1.2.0</version> <version>1.2.0</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>