File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .schabi .newpipe .downloader ;
2+
3+ import org .junit .jupiter .api .extension .ExtendWith ;
4+
5+ import java .lang .annotation .Retention ;
6+ import java .lang .annotation .RetentionPolicy ;
7+
8+ /**
9+ * Use this to annotate tests methods/classes that should only be run when the downloader is of type
10+ * {@link DownloaderType#MOCK} or {@link DownloaderType#RECORDING}. This should be used when e.g. an
11+ * extractor returns different results each time because the underlying service web page does so. In
12+ * that case it makes sense to only run the tests with the mock downloader, since the real web page
13+ * is not reliable, but we still want to make sure that the code correctly interprets the stored and
14+ * mocked web page data.
15+ * @see MockOnlyCondition
16+ */
17+ @ Retention (RetentionPolicy .RUNTIME )
18+ @ ExtendWith (MockOnlyCondition .class )
19+ public @interface MockOnly {
20+ }
Original file line number Diff line number Diff line change 1+ package org .schabi .newpipe .downloader ;
2+
3+ import org .junit .jupiter .api .extension .ConditionEvaluationResult ;
4+ import org .junit .jupiter .api .extension .ExecutionCondition ;
5+ import org .junit .jupiter .api .extension .ExtensionContext ;
6+
7+ /**
8+ * @see MockOnly
9+ */
10+ public class MockOnlyCondition implements ExecutionCondition {
11+ private static final String MOCK_ONLY_REASON = "Mock only" ;
12+
13+ @ Override
14+ public ConditionEvaluationResult evaluateExecutionCondition (final ExtensionContext context ) {
15+ if (DownloaderFactory .getDownloaderType () == DownloaderType .REAL ) {
16+ return ConditionEvaluationResult .disabled (MOCK_ONLY_REASON );
17+ } else {
18+ return ConditionEvaluationResult .enabled (MOCK_ONLY_REASON );
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments