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