parent
0c59b3d0af
commit
1276790b07
@ -0,0 +1,18 @@ |
||||
package com.otaliastudios.cameraview.runner; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Like {@link androidx.test.filters.SdkSuppress}, but negative. |
||||
*/ |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target({ElementType.TYPE, ElementType.METHOD}) |
||||
public @interface SdkExclude { |
||||
/** The minimum API level to drop (inclusive) */ |
||||
int minSdkVersion() default 1; |
||||
/** The maximum API level to drop (inclusive) */ |
||||
int maxSdkVersion() default Integer.MAX_VALUE; |
||||
} |
@ -0,0 +1,46 @@ |
||||
package com.otaliastudios.cameraview.runner; |
||||
|
||||
|
||||
import android.os.Build; |
||||
|
||||
import androidx.annotation.Nullable; |
||||
import androidx.test.internal.runner.filters.ParentFilter; |
||||
|
||||
import org.junit.runner.Description; |
||||
|
||||
/** |
||||
* Filter for {@link SdkExclude}, based on |
||||
* {@link androidx.test.internal.runner.TestRequestBuilder}'s SdkSuppressFilter. |
||||
*/ |
||||
public class SdkExcludeFilter extends ParentFilter { |
||||
|
||||
protected boolean evaluateTest(Description description) { |
||||
final SdkExclude sdkSuppress = getAnnotationForTest(description); |
||||
if (sdkSuppress != null) { |
||||
if (Build.VERSION.SDK_INT >= sdkSuppress.minSdkVersion() |
||||
&& Build.VERSION.SDK_INT <= sdkSuppress.maxSdkVersion()) { |
||||
return false; // exclude the test
|
||||
} |
||||
return true; // run the test
|
||||
} |
||||
return true; // no annotation, run the test
|
||||
} |
||||
|
||||
@Nullable |
||||
private SdkExclude getAnnotationForTest(Description description) { |
||||
final SdkExclude s = description.getAnnotation(SdkExclude.class); |
||||
if (s != null) { |
||||
return s; |
||||
} |
||||
final Class<?> testClass = description.getTestClass(); |
||||
if (testClass != null) { |
||||
return testClass.getAnnotation(SdkExclude.class); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String describe() { |
||||
return "Skip tests annotated with SdkExclude"; |
||||
} |
||||
} |
Loading…
Reference in new issue