1/* 2 * Copyright (C) 2015 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 17package com.android.documentsui.dirlist; 18 19import android.app.PendingIntent; 20import android.content.Context; 21import android.database.Cursor; 22import android.support.test.filters.MediumTest; 23import android.test.AndroidTestCase; 24 25import com.android.documentsui.ActionHandler; 26import com.android.documentsui.Model; 27import com.android.documentsui.base.Features; 28import com.android.documentsui.base.State; 29import com.android.documentsui.testing.TestActionHandler; 30import com.android.documentsui.testing.TestEnv; 31 32@MediumTest 33public class ModelBackedDocumentsAdapterTest extends AndroidTestCase { 34 35 private static final String AUTHORITY = "test_authority"; 36 37 private TestEnv mEnv; 38 private ActionHandler mActionHandler; 39 private ModelBackedDocumentsAdapter mAdapter; 40 41 public void setUp() { 42 43 final Context testContext = TestContext.createStorageTestContext(getContext(), AUTHORITY); 44 mEnv = TestEnv.create(AUTHORITY); 45 mActionHandler = new TestActionHandler(); 46 47 DocumentsAdapter.Environment env = new TestEnvironment(testContext); 48 49 mAdapter = new ModelBackedDocumentsAdapter( 50 env, new IconHelper(testContext, State.MODE_GRID)); 51 mAdapter.getModelUpdateListener().accept(Model.Update.UPDATE); 52 } 53 54 // Tests that the item count is correct. 55 public void testItemCount() { 56 assertEquals(mEnv.model.getItemCount(), mAdapter.getItemCount()); 57 } 58 59 private final class TestEnvironment implements DocumentsAdapter.Environment { 60 private final Context testContext; 61 62 @Override 63 public Features getFeatures() { 64 return mEnv.features; 65 } 66 67 @Override 68 public ActionHandler getActionHandler() { return mActionHandler; } 69 70 private TestEnvironment(Context testContext) { 71 this.testContext = testContext; 72 } 73 74 @Override 75 public boolean isSelected(String id) { 76 return false; 77 } 78 79 @Override 80 public boolean isDocumentEnabled(String mimeType, int flags) { 81 return true; 82 } 83 84 @Override 85 public void initDocumentHolder(DocumentHolder holder) {} 86 87 @Override 88 public Model getModel() { 89 return mEnv.model; 90 } 91 92 @Override 93 public State getDisplayState() { 94 return null; 95 } 96 97 @Override 98 public boolean isInSearchMode() { 99 return false; 100 } 101 102 @Override 103 public Context getContext() { 104 return testContext; 105 } 106 107 @Override 108 public int getColumnCount() { 109 return 4; 110 } 111 112 @Override 113 public void onBindDocumentHolder(DocumentHolder holder, Cursor cursor) {} 114 } 115} 116