1 /* 2 * Copyright 2014 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 * Copyright (C) 2014 The Android Open Source Project 18 * 19 * Licensed under the Apache License, Version 2.0 (the "License"); 20 * you may not use this file except in compliance with the License. 21 * You may obtain a copy of the License at 22 * 23 * http://www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, software 26 * distributed under the License is distributed on an "AS IS" BASIS, 27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 * See the License for the specific language governing permissions and 29 * limitations under the License. 30 */ 31 package com.example.android.directoryselection; 32 33 import android.test.ActivityInstrumentationTestCase2; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 /** 39 * Tests for {@link DirectorySelectionFragment}. 40 */ 41 public class DirectoryEntryAdapterTest 42 extends ActivityInstrumentationTestCase2<DirectorySelectionActivity> { 43 44 private static final String FILE1 = "file1"; 45 private static final String MIME_TYPE1 = "text/appliaction"; 46 private static final String DIRECTORY1 = "directory1"; 47 48 private DirectorySelectionActivity mTestActivity; 49 private DirectorySelectionFragment mTestFragment; 50 private DirectoryEntryAdapter mAdapter; 51 private List<DirectoryEntry> mDirectoryEntries; 52 53 public DirectoryEntryAdapterTest() { 54 super(DirectorySelectionActivity.class); 55 } 56 57 @Override 58 protected void setUp() throws Exception { 59 super.setUp(); 60 61 mTestActivity = getActivity(); 62 mTestFragment = (DirectorySelectionFragment) 63 mTestActivity.getSupportFragmentManager().getFragments().get(0); 64 mDirectoryEntries = new ArrayList<>(); 65 66 DirectoryEntry file = new DirectoryEntry(); 67 file.fileName = FILE1; 68 file.mimeType = MIME_TYPE1; 69 mDirectoryEntries.add(file); 70 71 DirectoryEntry directory = new DirectoryEntry(); 72 directory.fileName = DIRECTORY1; 73 directory.mimeType = DirectoryEntryAdapter.DIRECTORY_MIME_TYPE; 74 mDirectoryEntries.add(directory); 75 } 76 77 public void testGetItemCount() { 78 mTestFragment.mAdapter.setDirectoryEntries(mDirectoryEntries); 79 80 assertEquals(2, mTestFragment.mAdapter.getItemCount()); 81 } 82 } 83