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 
17 package android.service.resolver.cts;
18 
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.junit.Assert.assertThat;
21 
22 import android.os.Parcel;
23 import android.service.resolver.ResolverTarget;
24 
25 import androidx.test.runner.AndroidJUnit4;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 /**
31  * Tests {@link ResolverTarget}.
32  */
33 @RunWith(AndroidJUnit4.class)
34 public class ResolverTargetTest {
35 
36     @Test
sanityCheckDataConsistency()37     public void sanityCheckDataConsistency() throws Exception {
38         ResolverTarget target = new ResolverTarget();
39 
40         target.setChooserScore(1.0f);
41         assertThat(target.getChooserScore(), is(1.0f));
42 
43         target.setLaunchScore(0.5f);
44         assertThat(target.getLaunchScore(), is(0.5f));
45 
46         target.setRecencyScore(0.3f);
47         assertThat(target.getRecencyScore(), is(0.3f));
48 
49         target.setSelectProbability(0.2f);
50         assertThat(target.getSelectProbability(), is(0.2f));
51 
52         target.setTimeSpentScore(0.1f);
53         assertThat(target.getTimeSpentScore(), is(0.1f));
54     }
55 
56     @Test
sanityCheckParcelability()57     public void sanityCheckParcelability() throws Exception {
58         ResolverTarget target = new ResolverTarget();
59 
60         target.setChooserScore(1.0f);
61         target.setLaunchScore(0.5f);
62         target.setRecencyScore(0.3f);
63         target.setSelectProbability(0.2f);
64         target.setTimeSpentScore(0.1f);
65 
66         Parcel parcel = Parcel.obtain();
67         target.writeToParcel(parcel, 0 /*flags*/);
68         parcel.setDataPosition(0);
69         ResolverTarget fromParcel = ResolverTarget.CREATOR.createFromParcel(parcel);
70 
71         assertThat(fromParcel.getChooserScore(), is(1.0f));
72         assertThat(fromParcel.getLaunchScore(), is(0.5f));
73         assertThat(fromParcel.getRecencyScore(), is(0.3f));
74         assertThat(fromParcel.getSelectProbability(), is(0.2f));
75         assertThat(fromParcel.getTimeSpentScore(), is(0.1f));
76     }
77 }
78