Skip to content

Commit

Permalink
Introduce a constant for Robolectric tests using sdk = 18.
Browse files Browse the repository at this point in the history
This commit replaces hardcoded instances of 'Config(sdk = 18') with a
constant. The intent is to make it easier to update the value in the
future when Robolectric stops supporting sdk 18.

Tested via gradle test testDebugUnitTest.
  • Loading branch information
brettchabot authored and sjudd committed Jul 7, 2023
1 parent f78da0b commit e9b8758
Show file tree
Hide file tree
Showing 84 changed files with 170 additions and 83 deletions.
3 changes: 2 additions & 1 deletion library/test/src/test/java/com/bumptech/glide/GlideTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.bumptech.glide.request.RequestOptions.decodeTypeOf;
import static com.bumptech.glide.request.RequestOptions.errorOf;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
Expand Down Expand Up @@ -94,7 +95,7 @@
@LooperMode(LEGACY)
@RunWith(RobolectricTestRunner.class)
@Config(
sdk = 18,
sdk = ROBOLECTRIC_SDK,
shadows = {
GlideTest.ShadowFileDescriptorContentResolver.class,
GlideTest.ShadowMediaMetadataRetriever.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK)
public class ListPreloaderTest {

@Mock private RequestBuilder<Object> request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

@SuppressWarnings("unchecked")
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK)
public class RequestBuilderTest {
@Rule public TearDownGlide tearDownGlide = new TearDownGlide();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.bumptech.glide.tests.BackgroundUtil.testInBackground;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -42,7 +43,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class RequestManagerTest {
@Rule public TearDownGlide tearDownGlide = new TearDownGlide();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bumptech.glide;

public class RobolectricConstants {
/** The default SDK used for Robolectric tests */
public static final int ROBOLECTRIC_SDK = 18;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bumptech.glide.load;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;

import androidx.annotation.NonNull;
import com.bumptech.glide.load.Option.CacheKeyUpdater;
import com.bumptech.glide.tests.KeyTester;
Expand All @@ -12,7 +14,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class OptionsTest {
@Rule public final KeyTester keyTester = new KeyTester();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;

import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
Expand All @@ -15,7 +16,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class ExifOrientationStreamTest {
private ArrayPool byteArrayPool;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand All @@ -18,7 +19,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class FileDescriptorAssetPathFetcherTest {

@Mock private AssetManager assetManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -36,7 +37,7 @@
* com.bumptech.glide.load.data.HttpUrlFetcherTest}, response handling should go here.
*/
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 18)
@Config(manifest = Config.NONE, sdk = ROBOLECTRIC_SDK)
public class HttpUrlFetcherServerTest {
private static final String DEFAULT_PATH = "/fakepath";
private static final int TIMEOUT_TIME_MS = 300;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
Expand Down Expand Up @@ -30,7 +31,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class HttpUrlFetcherTest {
@Mock private HttpURLConnection urlConnection;
@Mock private HttpUrlFetcher.HttpUrlConnectionFactory connectionFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand All @@ -23,7 +24,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class LocalUriFetcherTest {
private TestLocalUriFetcher fetcher;
@Mock private DataFetcher.DataCallback<Closeable> callback;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand All @@ -18,7 +19,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class StreamAssetPathFetcherTest {
@Mock private AssetManager assetManager;
@Mock private InputStream expected;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data.mediastore;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;

import android.net.Uri;
Expand All @@ -10,7 +11,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class MediaStoreUtilTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data.mediastore;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -19,7 +20,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class ThumbFetcherTest {

@Mock private ThumbnailStreamOpener opener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data.mediastore;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -36,7 +37,7 @@
import org.robolectric.fakes.RoboCursor;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class ThumbnailStreamOpenerTest {
private Harness harness;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data.resource;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -28,7 +29,7 @@

@RunWith(RobolectricTestRunner.class)
@Config(
sdk = 18,
sdk = ROBOLECTRIC_SDK,
shadows = {ContentResolverShadow.class})
public class FileDescriptorLocalUriFetcherTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.data.resource;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.verify;

Expand All @@ -26,7 +27,7 @@

@RunWith(RobolectricTestRunner.class)
@Config(
sdk = 18,
sdk = ROBOLECTRIC_SDK,
shadows = {ContentResolverShadow.class})
public class StreamLocalUriFetcherTest {
@Mock private DataFetcher.DataCallback<InputStream> callback;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.bumptech.glide.tests.Util.anyResource;
import static com.bumptech.glide.tests.Util.isADataSource;
import static com.bumptech.glide.tests.Util.mockResource;
Expand Down Expand Up @@ -41,7 +42,7 @@
import org.robolectric.shadows.ShadowLooper;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class EngineJobTest {
private EngineJobHarness harness;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.junit.Assert.assertThrows;

import androidx.annotation.NonNull;
Expand All @@ -23,7 +24,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class EngineKeyTest {
@Mock private Transformation<Object> transformation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.bumptech.glide.tests.Util.mockResource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -21,7 +22,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class EngineResourceTest {
private EngineResource<Object> engineResource;
@Mock private EngineResource.ResourceListener listener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.bumptech.glide.tests.Util.anyResource;
import static com.bumptech.glide.tests.Util.isADataSource;
import static com.bumptech.glide.tests.Util.mockResource;
Expand Down Expand Up @@ -44,7 +45,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
@SuppressWarnings("unchecked")
public class EngineTest {
private EngineTestHarness harness;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.bumptech.glide.tests.Util.mockResource;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
Expand All @@ -16,7 +17,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class ResourceRecyclerTest {

private ResourceRecycler recycler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine.bitmap_recycle;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -16,7 +17,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class AttributeStrategyKeyTest {

private AttributeStrategy.KeyPool keyPool;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine.bitmap_recycle;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

Expand All @@ -11,7 +12,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class AttributeStrategyTest {

private AttributeStrategy strategy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine.bitmap_recycle;

import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNull;

Expand All @@ -10,7 +11,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class GroupedLinkedMapTest {

private GroupedLinkedMap<Key, Object> map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN;
import static com.bumptech.glide.RobolectricConstants.ROBOLECTRIC_SDK;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -19,7 +20,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
@Config(sdk = ROBOLECTRIC_SDK)
public class LruArrayPoolTest {
private static final int MAX_SIZE = 10;
private static final int MAX_PUT_SIZE = MAX_SIZE / 2;
Expand Down
Loading

0 comments on commit e9b8758

Please sign in to comment.