1 /* 2 * Copyright (C) 2016 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; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 import com.android.documentsui.model.DocumentInfo; 23 24 @SmallTest 25 public class StateTest extends AndroidTestCase { 26 27 private static final DocumentInfo DIR_1; 28 private static final DocumentInfo DIR_2; 29 30 private State mState; 31 32 static { 33 DIR_1 = new DocumentInfo(); 34 DIR_1.displayName = "firstDirectory"; 35 DIR_2 = new DocumentInfo(); 36 DIR_2.displayName = "secondDirectory"; 37 } 38 39 @Override 40 protected void setUp() throws Exception { 41 mState = new State(); 42 } 43 44 public void testInitialStateEmpty() { 45 assertFalse(mState.hasLocationChanged()); 46 } 47 48 public void testPushDocument_ChangesLocation() { 49 mState.pushDocument(DIR_1); 50 mState.pushDocument(DIR_2); 51 assertTrue(mState.hasLocationChanged()); 52 } 53 54 public void testPushDocument_ModifiesStack() { 55 mState.pushDocument(DIR_1); 56 mState.pushDocument(DIR_2); 57 assertEquals(DIR_2, mState.stack.getFirst()); 58 } 59 60 public void testPopDocument_ModifiesStack() { 61 mState.pushDocument(DIR_1); 62 mState.pushDocument(DIR_2); 63 mState.popDocument(); 64 assertEquals(DIR_1, mState.stack.getFirst()); 65 } 66 } 67