提交 229cb11e 编写于 作者: C christianw 提交者: Sam Judd

[third_party] Avoid saving Robolectric shadow instances; instead, save the...

[third_party] Avoid saving Robolectric shadow instances; instead, save the real framework object, and get its shadow when needed using Shadows.shadowOf(). Call Android framework methods directly on the framework object instead of its shadow whenever possible.

LSC: []
Additional details: []

Cleanup change automatically generated by javacflume/refactory
Refactoring: //third_party/java_src/robolectric/errorprone:ShadowUsageCheck

Tested:
    TAP --sample for global presubmit queue
    []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204784445
上级 c4b08d46
......@@ -17,6 +17,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.util.Pools;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Key;
......@@ -229,14 +230,14 @@ public class EngineJobTest {
@Test
public void testReleasesResourceIfCancelledOnReady() {
ShadowLooper shadowLooper = Shadows.shadowOf(harness.mainHandler.getLooper());
shadowLooper.pause();
Looper looper = harness.mainHandler.getLooper();
Shadows.shadowOf(looper).pause();
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
job.cancel();
shadowLooper.runOneTask();
Shadows.shadowOf(looper).runOneTask();
verify(harness.resource).recycle();
}
......
......@@ -9,7 +9,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBitmap;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 18)
......@@ -29,7 +28,7 @@ public class AttributeStrategyTest {
@Test
public void testICanAddAndGetABitmapOfTheSameSizeAndDimensions() {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertEquals(bitmap,
strategy.get(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888));
......@@ -37,44 +36,44 @@ public class AttributeStrategyTest {
@Test
public void testICantGetABitmapOfTheSameDimensionsButDifferentConfigs() {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertNull(strategy.get(100, 100, Bitmap.Config.RGB_565));
}
@Test
public void testICantGetABitmapOfTheSameDimensionsAndSizeButDifferentConfigs() {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444);
strategy.put(bitmap);
assertNull(strategy.get(100, 100, Bitmap.Config.RGB_565));
}
@Test
public void testICantGetABitmapOfDifferentWidths() {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertNull(strategy.get(99, 100, Bitmap.Config.ARGB_8888));
}
@Test
public void testICantGetABitmapOfDifferentHeights() {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertNull(strategy.get(100, 99, Bitmap.Config.ARGB_8888));
}
@Test
public void testICantGetABitmapOfDifferentDimensionsButTheSameSize() {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertNull(strategy.get(50, 200, Bitmap.Config.ARGB_8888));
}
@Test
public void testMultipleBitmapsOfDifferentAttributesCanBeAddedAtOnce() {
Bitmap first = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
Bitmap second = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap third = ShadowBitmap.createBitmap(120, 120, Bitmap.Config.RGB_565);
Bitmap first = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
Bitmap second = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap third = Bitmap.createBitmap(120, 120, Bitmap.Config.RGB_565);
strategy.put(first);
strategy.put(second);
......@@ -87,9 +86,9 @@ public class AttributeStrategyTest {
@Test
public void testLeastRecentlyUsedAttributeSetIsRemovedFirst() {
final Bitmap leastRecentlyUsed = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8);
final Bitmap other = ShadowBitmap.createBitmap(1000, 1000, Bitmap.Config.RGB_565);
final Bitmap mostRecentlyUsed = ShadowBitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
final Bitmap leastRecentlyUsed = Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8);
final Bitmap other = Bitmap.createBitmap(1000, 1000, Bitmap.Config.RGB_565);
final Bitmap mostRecentlyUsed = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.get(100, 100, Bitmap.Config.ALPHA_8);
strategy.get(1000, 1000, Bitmap.Config.RGB_565);
......
......@@ -25,7 +25,6 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBitmap;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 18)
......@@ -239,7 +238,7 @@ public class LruBitmapPoolTest {
}
private Bitmap createMutableBitmap(Bitmap.Config config) {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, config);
Bitmap bitmap = Bitmap.createBitmap(100, 100, config);
Shadows.shadowOf(bitmap).setMutable(true);
return bitmap;
......
......@@ -20,6 +20,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Display;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewGroup;
......@@ -44,7 +45,6 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDisplay;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 19)
......@@ -456,14 +456,13 @@ public class CustomViewTargetTest {
private void setDisplayDimens(Integer width, Integer height) {
WindowManager windowManager =
(WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE);
ShadowDisplay shadowDisplay =
Shadows.shadowOf(Preconditions.checkNotNull(windowManager).getDefaultDisplay());
Display display = Preconditions.checkNotNull(windowManager).getDefaultDisplay();
if (width != null) {
shadowDisplay.setWidth(width);
Shadows.shadowOf(display).setWidth(width);
}
if (height != null) {
shadowDisplay.setHeight(height);
Shadows.shadowOf(display).setHeight(height);
}
}
......
......@@ -19,6 +19,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Display;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewTreeObserver;
......@@ -46,7 +47,6 @@ import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowDisplay;
import org.robolectric.shadows.ShadowView;
@RunWith(RobolectricTestRunner.class)
......@@ -470,14 +470,13 @@ public class ViewTargetTest {
private void setDisplayDimens(Integer width, Integer height) {
WindowManager windowManager =
(WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE);
ShadowDisplay shadowDisplay =
Shadows.shadowOf(Preconditions.checkNotNull(windowManager).getDefaultDisplay());
Display display = Preconditions.checkNotNull(windowManager).getDefaultDisplay();
if (width != null) {
shadowDisplay.setWidth(width);
Shadows.shadowOf(display).setWidth(width);
}
if (height != null) {
shadowDisplay.setHeight(height);
Shadows.shadowOf(display).setHeight(height);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册