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.mock;
20 import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
21 import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
22 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
23 
24 import android.app.IApplicationThread;
25 import android.app.servertransaction.ClientTransaction;
26 import android.os.Binder;
27 import android.platform.test.annotations.Presubmit;
28 
29 import androidx.test.filters.SmallTest;
30 
31 import org.junit.Test;
32 
33 /**
34  * Build/Install/Run:
35  *  atest WmTests:ClientLifecycleManagerTests
36  */
37 @SmallTest
38 @Presubmit
39 public class ClientLifecycleManagerTests {
40 
41     @Test
testScheduleAndRecycleBinderClientTransaction()42     public void testScheduleAndRecycleBinderClientTransaction() throws Exception {
43         ClientTransaction item = spy(ClientTransaction.obtain(mock(IApplicationThread.class),
44                 new Binder()));
45 
46         ClientLifecycleManager clientLifecycleManager = new ClientLifecycleManager();
47         clientLifecycleManager.scheduleTransaction(item);
48 
49         verify(item, times(1)).recycle();
50     }
51 
52     @Test
testScheduleNoRecycleNonBinderClientTransaction()53     public void testScheduleNoRecycleNonBinderClientTransaction() throws Exception {
54         ClientTransaction item = spy(ClientTransaction.obtain(mock(IApplicationThread.Stub.class),
55                 new Binder()));
56 
57         ClientLifecycleManager clientLifecycleManager = new ClientLifecycleManager();
58         clientLifecycleManager.scheduleTransaction(item);
59 
60         verify(item, times(0)).recycle();
61     }
62 }
63