Permalink
Please sign in to comment.
Browse files
StorIOContentReslver fix for observing changes of Uris on Android API…
… < 16
- Loading branch information...
Showing
with
395 additions
and 102 deletions.
- +2 −1 ...ver/src/main/java/com/pushtorefresh/storio/contentresolver/impl/DefaultStorIOContentResolver.java
- +54 −23 ...ntent-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/impl/RxChangesObserver.java
- +271 −78 ...t-resolver/src/test/java/com/pushtorefresh/storio/contentresolver/impl/RxChangesObserverTest.java
- +39 −0 storio-test-common/src/main/java/com/pushtorefresh/storio/test/Utils.java
- +29 −0 storio-test-common/src/test/java/com/pushtorefresh/storio/test/UtilsTest.java
3
...main/java/com/pushtorefresh/storio/contentresolver/impl/DefaultStorIOContentResolver.java
77
...solver/src/main/java/com/pushtorefresh/storio/contentresolver/impl/RxChangesObserver.java
349
...er/src/test/java/com/pushtorefresh/storio/contentresolver/impl/RxChangesObserverTest.java
39
storio-test-common/src/main/java/com/pushtorefresh/storio/test/Utils.java
@@ -0,0 +1,39 @@ | ||
+package com.pushtorefresh.storio.test; | ||
+ | ||
+import android.os.Build; | ||
+ | ||
+import java.lang.reflect.Field; | ||
+ | ||
+public class Utils { | ||
+ | ||
+ public static final int MAX_SDK_VERSION = getMaxSdkVersion(); | ||
+ public static final int MIN_SDK_VERSION = 14; | ||
+ | ||
+ private Utils() { | ||
+ throw new IllegalStateException("No instances please!"); | ||
+ } | ||
+ | ||
+ private static int getMaxSdkVersion() { | ||
+ final Field[] versionCodesFields = Build.VERSION_CODES.class.getDeclaredFields(); | ||
+ | ||
+ // At least 23 | ||
+ int maxSdkVersion = 23; | ||
+ | ||
+ for (final Field versionCodeField : versionCodesFields) { | ||
+ versionCodeField.setAccessible(true); | ||
+ | ||
+ try { | ||
+ final Class<?> fieldType = versionCodeField.getType(); | ||
+ | ||
+ if (fieldType.equals(Integer.class)) { | ||
+ int sdkVersion = (Integer) versionCodeField.get(null); | ||
+ maxSdkVersion = Math.max(maxSdkVersion, sdkVersion); | ||
+ } | ||
+ } catch (IllegalAccessException e) { | ||
+ throw new RuntimeException(e); | ||
+ } | ||
+ } | ||
+ | ||
+ return maxSdkVersion; | ||
+ } | ||
+} |
29
storio-test-common/src/test/java/com/pushtorefresh/storio/test/UtilsTest.java
@@ -0,0 +1,29 @@ | ||
+package com.pushtorefresh.storio.test; | ||
+ | ||
+import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker; | ||
+ | ||
+import org.junit.Test; | ||
+ | ||
+import static org.assertj.core.api.Assertions.assertThat; | ||
+ | ||
+public class UtilsTest { | ||
+ | ||
+ @Test | ||
+ public void constructorShouldBePrivateAndThrowException() { | ||
+ PrivateConstructorChecker | ||
+ .forClass(Utils.class) | ||
+ .expectedTypeOfException(IllegalStateException.class) | ||
+ .expectedExceptionMessage("No instances please!") | ||
+ .check(); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public void maxSdkVersionShouldBeAtLeast23() { | ||
+ assertThat(Utils.MAX_SDK_VERSION).isGreaterThanOrEqualTo(23); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public void minSdkVersionShouldBe14() { | ||
+ assertThat(Utils.MIN_SDK_VERSION).isEqualTo(14); | ||
+ } | ||
+} |
0 comments on commit
149c2dc