1414import static org .mockito .Mockito .when ;
1515
1616import android .app .Activity ;
17- import android .content .Context ;
1817import android .graphics .drawable .Drawable ;
1918import android .os .Build ;
20- import android .view .Display ;
2119import android .view .View ;
2220import android .view .View .OnAttachStateChangeListener ;
2321import android .view .ViewGroup ;
2422import android .view .ViewGroup .LayoutParams ;
2523import android .view .ViewTreeObserver ;
26- import android .view .WindowManager ;
2724import android .widget .FrameLayout ;
2825import android .widget .LinearLayout ;
2926import androidx .annotation .NonNull ;
3027import androidx .annotation .Nullable ;
31- import androidx .test .core .app .ApplicationProvider ;
3228import com .bumptech .glide .request .Request ;
3329import com .bumptech .glide .request .transition .Transition ;
34- import com .bumptech .glide .util .Preconditions ;
3530import com .google .common .truth .Truth ;
3631import java .util .concurrent .atomic .AtomicInteger ;
3732import org .junit .After ;
4338import org .mockito .MockitoAnnotations ;
4439import org .robolectric .Robolectric ;
4540import org .robolectric .RobolectricTestRunner ;
46- import org .robolectric .Shadows ;
4741import org .robolectric .android .controller .ActivityController ;
4842import org .robolectric .annotation .Config ;
4943import 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