Skip to content

Commit 8a23b1e

Browse files
falhassenglide-copybara-robot
authored andcommitted
Update test to set display size at config time, rather than during the test.
PiperOrigin-RevId: 766726383
1 parent fa199a8 commit 8a23b1e

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

library/src/test/java/com/bumptech/glide/request/target/CustomViewTargetTest.java

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,19 @@
1414
import static org.mockito.Mockito.when;
1515

1616
import android.app.Activity;
17-
import android.content.Context;
1817
import android.graphics.drawable.Drawable;
1918
import android.os.Build;
20-
import android.view.Display;
2119
import android.view.View;
2220
import android.view.View.OnAttachStateChangeListener;
2321
import android.view.ViewGroup;
2422
import android.view.ViewGroup.LayoutParams;
2523
import android.view.ViewTreeObserver;
26-
import android.view.WindowManager;
2724
import android.widget.FrameLayout;
2825
import android.widget.LinearLayout;
2926
import androidx.annotation.NonNull;
3027
import androidx.annotation.Nullable;
31-
import androidx.test.core.app.ApplicationProvider;
3228
import com.bumptech.glide.request.Request;
3329
import com.bumptech.glide.request.transition.Transition;
34-
import com.bumptech.glide.util.Preconditions;
3530
import com.google.common.truth.Truth;
3631
import java.util.concurrent.atomic.AtomicInteger;
3732
import org.junit.After;
@@ -43,7 +38,6 @@
4338
import org.mockito.MockitoAnnotations;
4439
import org.robolectric.Robolectric;
4540
import org.robolectric.RobolectricTestRunner;
46-
import org.robolectric.Shadows;
4741
import org.robolectric.android.controller.ActivityController;
4842
import org.robolectric.annotation.Config;
4943
import org.robolectric.util.ReflectionHelpers;
@@ -146,14 +140,13 @@ public void testSizeCallbackIsCalledSynchronouslyIfLayoutParamsConcreteSizeSet()
146140
verify(cb).onSizeReady(eq(dimens), eq(dimens));
147141
}
148142

143+
@Config(qualifiers = "w200dp-h300dp")
149144
@Test
150145
public void getSize_withBothWrapContent_usesDisplayDimens() {
151146
LayoutParams layoutParams =
152147
new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
153148
view.setLayoutParams(layoutParams);
154149

155-
setDisplayDimens(200, 300);
156-
157150
activity.visible();
158151
view.layout(0, 0, 0, 0);
159152

@@ -162,14 +155,13 @@ public void getSize_withBothWrapContent_usesDisplayDimens() {
162155
verify(cb).onSizeReady(300, 300);
163156
}
164157

158+
@Config(qualifiers = "w100dp-h200dp")
165159
@Test
166160
public void getSize_withWrapContentWidthAndValidHeight_usesDisplayDimenAndValidHeight() {
167161
int height = 100;
168162
LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, height);
169163
view.setLayoutParams(params);
170164

171-
setDisplayDimens(100, 200);
172-
173165
activity.visible();
174166
view.setRight(0);
175167

@@ -178,12 +170,12 @@ public void getSize_withWrapContentWidthAndValidHeight_usesDisplayDimenAndValidH
178170
verify(cb).onSizeReady(200, height);
179171
}
180172

173+
@Config(qualifiers = "w200dp-h100dp")
181174
@Test
182175
public void getSize_withWrapContentHeightAndValidWidth_returnsWidthAndDisplayDimen() {
183176
int width = 100;
184177
LayoutParams params = new FrameLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT);
185178
view.setLayoutParams(params);
186-
setDisplayDimens(200, 100);
187179
parent.getLayoutParams().height = 200;
188180

189181
activity.visible();
@@ -193,14 +185,13 @@ public void getSize_withWrapContentHeightAndValidWidth_returnsWidthAndDisplayDim
193185
verify(cb).onSizeReady(width, 200);
194186
}
195187

188+
@Config(qualifiers = "w500dp-h600dp")
196189
@Test
197190
public void getSize_withWrapContentWidthAndMatchParentHeight_usesDisplayDimenWidthAndHeight() {
198191
LayoutParams params =
199192
new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
200193
view.setLayoutParams(params);
201194

202-
setDisplayDimens(500, 600);
203-
204195
target.getSize(cb);
205196

206197
verify(cb, never()).onSizeReady(anyInt(), anyInt());
@@ -214,14 +205,13 @@ public void getSize_withWrapContentWidthAndMatchParentHeight_usesDisplayDimenWid
214205
verify(cb).onSizeReady(500, height);
215206
}
216207

208+
@Config(qualifiers = "w300dp-h400dp")
217209
@Test
218210
public void getSize_withMatchParentWidthAndWrapContentHeight_usesWidthAndDisplayDimenHeight() {
219211
LayoutParams params =
220212
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
221213
view.setLayoutParams(params);
222214

223-
setDisplayDimens(300, 400);
224-
225215
target.getSize(cb);
226216

227217
verify(cb, never()).onSizeReady(anyInt(), anyInt());
@@ -470,20 +460,6 @@ public void getSize_withWidthAndHeightEqualToPadding_doesNotCallSizeReady() {
470460
verify(cb, never()).onSizeReady(anyInt(), anyInt());
471461
}
472462

473-
private void setDisplayDimens(Integer width, Integer height) {
474-
WindowManager windowManager =
475-
(WindowManager)
476-
ApplicationProvider.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
477-
Display display = Preconditions.checkNotNull(windowManager).getDefaultDisplay();
478-
if (width != null) {
479-
Shadows.shadowOf(display).setWidth(width);
480-
}
481-
482-
if (height != null) {
483-
Shadows.shadowOf(display).setHeight(height);
484-
}
485-
}
486-
487463
@Test
488464
public void clearOnDetach_onDetach_withNullRequest_doesNothing() {
489465
attachStateTarget.clearOnDetach();

0 commit comments

Comments
 (0)