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.documentsui.testing;
18 
19 import static org.mockito.Mockito.never;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22 
23 import com.android.documentsui.DrawerController;
24 
25 import org.mockito.Mockito;
26 
27 /**
28  * We use abstract so we don't have to implement all the necessary methods from the interface.
29  * To get an instance, use {@link #create()}.
30  */
31 public abstract class TestDrawerController extends DrawerController {
32 
create()33     public static TestDrawerController create() {
34         TestDrawerController drawController = Mockito.mock(
35                 TestDrawerController.class);
36         Mockito.doCallRealMethod().when(drawController).openDrawer(Mockito.anyBoolean());
37         Mockito.doCallRealMethod().when(drawController).assertWasOpened();
38         Mockito.doCallRealMethod().when(drawController).assertWasClosed();
39 
40         return drawController;
41     }
42 
openDrawer(boolean open)43     public void openDrawer(boolean open) {
44         when(isPresent()).thenReturn(open);
45         when(isOpen()).thenReturn(open);
46     }
47 
assertWasOpened()48     public void assertWasOpened() {
49         verify(this).setOpen(false);
50     }
51 
assertWasClosed()52     public void assertWasClosed() {
53         verify(this, never()).setOpen(false);
54     }
55 }