Loading src/com/android/documentsui/Model.java +1 −4 Original line number Diff line number Diff line Loading @@ -120,6 +120,7 @@ public class Model { if (result.exception != null) { Log.e(TAG, "Error while loading directory contents", result.exception); reset(); // Resets this model to avoid access to old cursors. notifyUpdateListeners(result.exception); return; } Loading Loading @@ -198,10 +199,6 @@ public class Model { return mCursor; } public boolean isEmpty() { return mCursorCount == 0; } public boolean isLoading() { return mIsLoading; } Loading tests/unit/com/android/documentsui/ModelTest.java +24 −3 Original line number Diff line number Diff line Loading @@ -16,23 +16,31 @@ package com.android.documentsui; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.fail; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MergeCursor; import android.provider.DocumentsContract.Document; import android.support.test.filters.SmallTest; import android.test.AndroidTestCase; import android.support.test.runner.AndroidJUnit4; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.roots.RootCursorWrapper; import com.android.documentsui.testing.TestEventListener; import com.android.documentsui.testing.TestFeatures; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.BitSet; import java.util.Random; @RunWith(AndroidJUnit4.class) @SmallTest public class ModelTest extends AndroidTestCase { public class ModelTest { private static final int ITEM_COUNT = 10; private static final String AUTHORITY = "test_authority"; Loading Loading @@ -64,7 +72,7 @@ public class ModelTest extends AndroidTestCase { private Model model; private TestFeatures features; @Override @Before public void setUp() { features = new TestFeatures(); Loading Loading @@ -94,11 +102,13 @@ public class ModelTest extends AndroidTestCase { } // Tests that the item count is correct. @Test public void testItemCount() { assertEquals(ITEM_COUNT, model.getItemCount()); } // Tests multiple authorities with clashing document IDs. @Test public void testModelIdIsUnique() { MatrixCursor cIn1 = new MatrixCursor(COLUMNS); MatrixCursor cIn2 = new MatrixCursor(COLUMNS); Loading Loading @@ -151,6 +161,7 @@ public class ModelTest extends AndroidTestCase { } // Tests the base case for Model.getItem. @Test public void testGetItem() { String[] ids = model.getModelIds(); assertEquals(ITEM_COUNT, ids.length); Loading @@ -159,4 +170,14 @@ public class ModelTest extends AndroidTestCase { assertEquals(i, c.getPosition()); } } @Test public void testResetAfterGettingException() { DirectoryResult result = new DirectoryResult(); result.exception = new Exception(); model.update(result); assertEquals(0, model.getItemCount()); } } Loading
src/com/android/documentsui/Model.java +1 −4 Original line number Diff line number Diff line Loading @@ -120,6 +120,7 @@ public class Model { if (result.exception != null) { Log.e(TAG, "Error while loading directory contents", result.exception); reset(); // Resets this model to avoid access to old cursors. notifyUpdateListeners(result.exception); return; } Loading Loading @@ -198,10 +199,6 @@ public class Model { return mCursor; } public boolean isEmpty() { return mCursorCount == 0; } public boolean isLoading() { return mIsLoading; } Loading
tests/unit/com/android/documentsui/ModelTest.java +24 −3 Original line number Diff line number Diff line Loading @@ -16,23 +16,31 @@ package com.android.documentsui; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.fail; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MergeCursor; import android.provider.DocumentsContract.Document; import android.support.test.filters.SmallTest; import android.test.AndroidTestCase; import android.support.test.runner.AndroidJUnit4; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.roots.RootCursorWrapper; import com.android.documentsui.testing.TestEventListener; import com.android.documentsui.testing.TestFeatures; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.BitSet; import java.util.Random; @RunWith(AndroidJUnit4.class) @SmallTest public class ModelTest extends AndroidTestCase { public class ModelTest { private static final int ITEM_COUNT = 10; private static final String AUTHORITY = "test_authority"; Loading Loading @@ -64,7 +72,7 @@ public class ModelTest extends AndroidTestCase { private Model model; private TestFeatures features; @Override @Before public void setUp() { features = new TestFeatures(); Loading Loading @@ -94,11 +102,13 @@ public class ModelTest extends AndroidTestCase { } // Tests that the item count is correct. @Test public void testItemCount() { assertEquals(ITEM_COUNT, model.getItemCount()); } // Tests multiple authorities with clashing document IDs. @Test public void testModelIdIsUnique() { MatrixCursor cIn1 = new MatrixCursor(COLUMNS); MatrixCursor cIn2 = new MatrixCursor(COLUMNS); Loading Loading @@ -151,6 +161,7 @@ public class ModelTest extends AndroidTestCase { } // Tests the base case for Model.getItem. @Test public void testGetItem() { String[] ids = model.getModelIds(); assertEquals(ITEM_COUNT, ids.length); Loading @@ -159,4 +170,14 @@ public class ModelTest extends AndroidTestCase { assertEquals(i, c.getPosition()); } } @Test public void testResetAfterGettingException() { DirectoryResult result = new DirectoryResult(); result.exception = new Exception(); model.update(result); assertEquals(0, model.getItemCount()); } }