1 /*
2  * Copyright (C) 2017 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 junit.framework.Assert.assertFalse;
20 import static junit.framework.Assert.assertSame;
21 import static junit.framework.Assert.assertTrue;
22 
23 import android.app.Activity;
24 
25 import com.android.documentsui.base.DocumentStack;
26 import com.android.documentsui.base.State;
27 import com.android.documentsui.picker.LastAccessedStorage;
28 import com.android.documentsui.roots.ProvidersAccess;
29 
30 import javax.annotation.Nullable;
31 
32 /**
33  * A test double of {@link LastAccessedStorage}.
34  */
35 public class TestLastAccessedStorage implements LastAccessedStorage {
36 
37     private DocumentStack mLastAccessedStack;
38     private boolean mIsExternal = false;
39 
40     @Override
getLastAccessed(Activity activity, ProvidersAccess roots, State state)41     public @Nullable DocumentStack getLastAccessed(Activity activity, ProvidersAccess roots, State state) {
42         return mLastAccessedStack;
43     }
44 
45     @Override
setLastAccessed(Activity activity, DocumentStack stack)46     public void setLastAccessed(Activity activity, DocumentStack stack) {
47         mLastAccessedStack = stack;
48         mIsExternal = false;
49     }
50 
51     @Override
setLastAccessedToExternalApp(Activity activity)52     public void setLastAccessedToExternalApp(Activity activity) {
53         mIsExternal = true;
54     }
55 
assertSameStack(DocumentStack expected)56     public void assertSameStack(DocumentStack expected) {
57         assertSame(expected, mLastAccessedStack);
58     }
59 
assertExternal()60     public void assertExternal() {
61         assertTrue(mIsExternal);
62     }
63 
assertNotExternal()64     public void assertNotExternal() {
65         assertFalse(mIsExternal);
66     }
67 }
68