mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2024-12-13 20:40:03 +01:00
Add MockOnly junit 5 test extension
This commit is contained in:
parent
ef71a5fa0f
commit
73d1fd472f
@ -0,0 +1,20 @@
|
||||
package org.schabi.newpipe.downloader;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Use this to annotate tests methods/classes that should only be run when the downloader is of type
|
||||
* {@link DownloaderType#MOCK} or {@link DownloaderType#RECORDING}. This should be used when e.g. an
|
||||
* extractor returns different results each time because the underlying service web page does so. In
|
||||
* that case it makes sense to only run the tests with the mock downloader, since the real web page
|
||||
* is not reliable, but we still want to make sure that the code correctly interprets the stored and
|
||||
* mocked web page data.
|
||||
* @see MockOnlyCondition
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ExtendWith(MockOnlyCondition.class)
|
||||
public @interface MockOnly {
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.schabi.newpipe.downloader;
|
||||
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
/**
|
||||
* @see MockOnly
|
||||
*/
|
||||
public class MockOnlyCondition implements ExecutionCondition {
|
||||
private static final String MOCK_ONLY_REASON = "Mock only";
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
|
||||
if (DownloaderFactory.getDownloaderType() == DownloaderType.REAL) {
|
||||
return ConditionEvaluationResult.disabled(MOCK_ONLY_REASON);
|
||||
} else {
|
||||
return ConditionEvaluationResult.enabled(MOCK_ONLY_REASON);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user