Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af73f02e authored by Steve McKay's avatar Steve McKay
Browse files

Fix tests broken by switch to javac compiler.

There was some non-standard business relating to asserts. The switch
to javac wasn't able to emulate the behavior of jack so we needed to update
our code to use Preconditions and for our tests to check for those.
In the process we uncovered (and fixed) a broken test pattern in DragStartListenerTests.

Bug: 64312632
Test: Updated and passing w/ both jack and javac.
Change-Id: Icdccc2bc8eeb340f45b763b9f8745f0479fe0dcb
parent 61662f28
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.documentsui.base;

import static com.android.documentsui.base.Shared.DEBUG;
import static com.android.internal.util.Preconditions.checkArgument;

import android.content.ContentResolver;
import android.database.Cursor;
@@ -123,14 +124,11 @@ public class DocumentStack implements Durable, Parcelable {
    }

    public void push(DocumentInfo info) {
        boolean alreadyInStack = mList.contains(info);
        assert (!alreadyInStack);
        if (!alreadyInStack) {
        checkArgument(!mList.contains(info));
        if (DEBUG) Log.d(TAG, "Adding doc to stack: " + info);
        mList.addLast(info);
        mStackTouched = true;
    }
    }

    public DocumentInfo pop() {
        if (DEBUG) Log.d(TAG, "Popping doc off stack.");
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.documentsui.dirlist;

import static com.android.documentsui.base.Shared.DEBUG;
import static com.android.internal.util.Preconditions.checkArgument;

import android.net.Uri;
import android.support.annotation.VisibleForTesting;
@@ -98,7 +99,7 @@ interface DragStartListener {

        @Override
        public final boolean onMouseDragEvent(InputEvent event) {
            assert(Events.isMouseDragEvent(event));
            checkArgument(Events.isMouseDragEvent(event));
            return startDrag(mViewFinder.findView(event.getX(), event.getY()), event);
        }

+8 −4
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@

package com.android.documentsui.services;

import static com.android.documentsui.services.FileOperationService.OPERATION_COPY;
import static com.android.documentsui.services.FileOperationService.OPERATION_COMPRESS;
import static com.android.documentsui.services.FileOperationService.OPERATION_EXTRACT;
import static com.android.documentsui.services.FileOperationService.OPERATION_COPY;
import static com.android.documentsui.services.FileOperationService.OPERATION_DELETE;
import static com.android.documentsui.services.FileOperationService.OPERATION_EXTRACT;
import static com.android.documentsui.services.FileOperationService.OPERATION_MOVE;
import static com.android.documentsui.services.FileOperationService.OPERATION_UNKNOWN;
import static com.android.internal.util.Preconditions.checkArgument;

import android.content.Context;
import android.net.Uri;
@@ -57,8 +58,8 @@ public abstract class FileOperation implements Parcelable {

    @VisibleForTesting
    FileOperation(@OpType int opType, UrisSupplier srcs, DocumentStack destination) {
        assert(opType != OPERATION_UNKNOWN);
        assert(srcs.getItemCount() > 0);
        checkArgument(opType != OPERATION_UNKNOWN);
        checkArgument(srcs.getItemCount() > 0);

        mOpType = opType;
        mSrcs = srcs;
@@ -133,6 +134,7 @@ public abstract class FileOperation implements Parcelable {
            return builder.toString();
        }

        @Override
        CopyJob createJob(Context service, Job.Listener listener, String id, Features features) {
            return new CopyJob(
                    service, listener, id, getDestination(), getSrc(), getMessenger(), features);
@@ -173,6 +175,7 @@ public abstract class FileOperation implements Parcelable {
            return builder.toString();
        }

        @Override
        CopyJob createJob(Context service, Job.Listener listener, String id, Features features) {
            return new CompressJob(service, listener, id, getDestination(), getSrc(),
                    getMessenger(), features);
@@ -214,6 +217,7 @@ public abstract class FileOperation implements Parcelable {
        }

        // TODO: Replace CopyJob with ExtractJob.
        @Override
        CopyJob createJob(Context service, Job.Listener listener, String id, Features features) {
            return new CopyJob(
                    service, listener, id, getDestination(), getSrc(), getMessenger(), features);
+4 −6
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.documentsui;

import static junit.framework.Assert.assertTrue;

import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;

import android.content.Intent;
@@ -179,15 +179,13 @@ public class AbstractActionHandlerTest {
    }

    @Test
    public void testOpensDocument_AssertionErrorIfAlreadyInStack() throws Exception {
    public void testOpensDocument_ExceptionIfAlreadyInStack() throws Exception {
        mEnv.populateStack();
        boolean threw = false;
        try {
            mEnv.state.stack.push(TestEnv.FOLDER_0);
        } catch (AssertionError e) {
            threw = true;
            fail("Should have thrown IllegalArgumentException.");
        } catch (IllegalArgumentException expected) {
        }
        assertTrue(threw);
    }

    @Test
+9 −9
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.documentsui.dirlist;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.fail;
import static junit.framework.Assert.fail;

import android.provider.DocumentsContract;
import android.support.test.filters.SmallTest;
@@ -26,18 +26,17 @@ import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent;
import android.view.View;

import com.android.documentsui.MenuManager;
import com.android.documentsui.MenuManager.SelectionDetails;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.Events.InputEvent;
import com.android.documentsui.base.Providers;
import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.DragStartListener.ActiveListener;
import com.android.documentsui.base.Events.InputEvent;
import com.android.documentsui.selection.SelectionManager;
import com.android.documentsui.selection.Selection;
import com.android.documentsui.selection.SelectionManager;
import com.android.documentsui.testing.SelectionManagers;
import com.android.documentsui.testing.TestDragAndDropManager;
import com.android.documentsui.testing.TestEvent;
import com.android.documentsui.testing.SelectionManagers;
import com.android.documentsui.testing.TestSelectionDetails;
import com.android.documentsui.testing.Views;

@@ -86,7 +85,7 @@ public class DragStartListenerTest {
                },
                // docInfo Converter
                (Selection selection) -> {
                    return new ArrayList<DocumentInfo>();
                    return new ArrayList<>();
                },
                mManager);

@@ -123,7 +122,8 @@ public class DragStartListenerTest {

    @Test
    public void testThrows_OnNonPrimaryMove() {
        assertThrows(mEvent.pressButton(MotionEvent.BUTTON_PRIMARY).build());
        mEvent.releaseButton(MotionEvent.BUTTON_PRIMARY);
        assertThrows(mEvent.pressButton(MotionEvent.BUTTON_SECONDARY).build());
    }

    @Test
@@ -187,8 +187,8 @@ public class DragStartListenerTest {

    private void assertThrows(InputEvent e) {
        try {
            assertFalse(mListener.onMouseDragEvent(e));
            mListener.onMouseDragEvent(e);
            fail();
        } catch (AssertionError expected) {}
        } catch (IllegalArgumentException expected) {}
    }
}
Loading