1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.car.cluster;
17 
18 import static org.junit.Assert.assertEquals;
19 
20 import android.graphics.Bitmap;
21 import android.graphics.Point;
22 import android.net.Uri;
23 
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.robolectric.RobolectricTestRunner;
28 import org.robolectric.annotation.internal.DoNotInstrument;
29 
30 @RunWith(RobolectricTestRunner.class)
31 @DoNotInstrument
32 public class ImageResolverTest {
33     private ImageResolver mImageResolver;
34 
35     @Before
setup()36     public void setup() {
37         mImageResolver = new ImageResolver(new ImageResolver.BitmapFetcher() {
38             @Override
39             public Bitmap getBitmap(Uri uri, int width, int height) {
40                 return null;
41             }
42 
43             @Override
44             public Bitmap getBitmap(Uri uri, int width, int height, float offLanesAlpha) {
45                 return null;
46             }
47         });
48     }
49 
50     @Test
adjustedSize_widerImageInSquareBox()51     public void adjustedSize_widerImageInSquareBox() {
52         assertEquals(new Point(20, 10), mImageResolver.getAdjustedSize(2, 20, 20));
53     }
54 
55     @Test
adjustedSize_tallerImageInSquareBox()56     public void adjustedSize_tallerImageInSquareBox() {
57         assertEquals(new Point(10, 20), mImageResolver.getAdjustedSize(0.5, 20, 20));
58     }
59 
60     @Test
adjustedSize_narrowerImageInSquareBox()61     public void adjustedSize_narrowerImageInSquareBox() {
62         assertEquals(new Point(10, 20), mImageResolver.getAdjustedSize(0.5, 20, 20));
63     }
64 
65     @Test
adjustedSize_shorterImageInSquareBox()66     public void adjustedSize_shorterImageInSquareBox() {
67         assertEquals(new Point(20, 8), mImageResolver.getAdjustedSize(2.5, 20, 20));
68     }
69 
70     @Test
adjustedSize_widerImageInTallRectangle()71     public void adjustedSize_widerImageInTallRectangle() {
72         assertEquals(new Point(20, 10), mImageResolver.getAdjustedSize(2, 20, 40));
73     }
74 
75     @Test
adjustedSize_tallerImageInTallRectangle()76     public void adjustedSize_tallerImageInTallRectangle() {
77         assertEquals(new Point(20, 40), mImageResolver.getAdjustedSize(0.5, 20, 40));
78     }
79 
80     @Test
adjustedSize_widerImageInWideRectangle()81     public void adjustedSize_widerImageInWideRectangle() {
82         assertEquals(new Point(40, 20), mImageResolver.getAdjustedSize(2, 40, 20));
83     }
84 
85     @Test
adjustedSize_tallerImageInWideRectangle()86     public void adjustedSize_tallerImageInWideRectangle() {
87         assertEquals(new Point(10, 20), mImageResolver.getAdjustedSize(0.5, 40, 20));
88     }
89 
90     @Test(expected = IllegalArgumentException.class)
adjustedSize_exceptionIfRequestedWidthAndHeightNoProvided()91     public void adjustedSize_exceptionIfRequestedWidthAndHeightNoProvided() {
92         assertEquals(null, mImageResolver.getAdjustedSize(0.5, 0, 0));
93     }
94 
95     @Test
adjustedSize_flexibleWidth()96     public void adjustedSize_flexibleWidth() {
97         assertEquals(new Point(20, 30), mImageResolver.getAdjustedSize(0.66667, 0, 30));
98     }
99 
100     @Test
adjustedSize_flexibleHeight()101     public void adjustedSize_flexibleHeight() {
102         assertEquals(new Point(20, 20), mImageResolver.getAdjustedSize(1, 20, 0));
103     }
104 }
105