1 /*
2  * Copyright (C) 2018 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 com.android.server.wm;
18 
19 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
20 import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq;
21 import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
22 import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
23 import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
24 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
25 
26 import android.content.Intent;
27 import android.platform.test.annotations.Presubmit;
28 
29 import androidx.test.filters.SmallTest;
30 
31 import com.android.server.wm.ActivityStarter.Factory;
32 
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 
37 /**
38  * Tests for the {@link ActivityStartController} class.
39  *
40  * Build/Install/Run:
41  *  atest WmTests:ActivityStartControllerTests
42  */
43 @SmallTest
44 @Presubmit
45 @RunWith(WindowTestRunner.class)
46 public class ActivityStartControllerTests extends WindowTestsBase {
47     private ActivityStartController mController;
48     private Factory mFactory;
49     private ActivityStarter mStarter;
50 
51     @Before
setUp()52     public void setUp() throws Exception {
53         mFactory = mock(Factory.class);
54         mController = new ActivityStartController(mAtm, mAtm.mTaskSupervisor, mFactory);
55         mStarter = spy(new ActivityStarter(mController, mAtm,
56                 mAtm.mTaskSupervisor, mock(ActivityStartInterceptor.class)));
57         doReturn(mStarter).when(mFactory).obtain();
58     }
59 
60     /**
61      * Ensures instances are recycled after execution.
62      */
63     @Test
testRecycling()64     public void testRecycling() {
65         final Intent intent = new Intent();
66         final ActivityStarter optionStarter = new ActivityStarter(mController, mAtm,
67                 mAtm.mTaskSupervisor, mock(ActivityStartInterceptor.class));
68         optionStarter
69                 .setIntent(intent)
70                 .setReason("Test")
71                 .execute();
72         verify(mFactory, times(1)).recycle(eq(optionStarter));
73     }
74 }
75