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

Commit 13fa4652 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make SelectTest append selectTest argument from extended class"

parents 97cba33f 9648d4b0
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -19,7 +19,10 @@ java_library {


    srcs: ["java/**/*.java"],
    srcs: ["java/**/*.java"],


    static_libs: ["junit"],
    static_libs: [
        "junit",
        "hamcrest-library",
    ],


    libs: [
    libs: [
        "android.test.runner",
        "android.test.runner",
+11 −2
Original line number Original line Diff line number Diff line
@@ -26,10 +26,12 @@ import com.android.internal.annotations.VisibleForTesting;
import org.junit.runner.Description;
import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.Filter;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Set;
import java.util.Set;
import java.util.StringJoiner;
import java.util.StringJoiner;
@@ -131,7 +133,8 @@ public class SelectTest extends Filter {
     *
     *
     * @param testArgs instrumentation test arguments.
     * @param testArgs instrumentation test arguments.
     * @param selectTests array of class name to be selected to run.
     * @param selectTests array of class name to be selected to run.
     * @return modified instrumentation test arguments.
     * @return modified instrumentation test arguments. if {@link #OPTION_SELECT_TEST} argument
     *      already exists in {@code testArgs}, those are prepended before {@code selectTests}.
     */
     */
    @NonNull
    @NonNull
    protected static Bundle addSelectTest(
    protected static Bundle addSelectTest(
@@ -139,7 +142,13 @@ public class SelectTest extends Filter {
        if (selectTests.length == 0) {
        if (selectTests.length == 0) {
            return testArgs;
            return testArgs;
        }
        }
        testArgs.putString(OPTION_SELECT_TEST, join(Arrays.asList(selectTests)));
        final List<String> selectedTestList = new ArrayList<>();
        final String selectTestArgs = testArgs.getString(OPTION_SELECT_TEST);
        if (selectTestArgs != null) {
            selectedTestList.addAll(Arrays.asList(selectTestArgs.split(ARGUMENT_ITEM_SEPARATOR)));
        }
        selectedTestList.addAll(Arrays.asList(selectTests));
        testArgs.putString(OPTION_SELECT_TEST, join(selectedTestList));
        return testArgs;
        return testArgs;
    }
    }


+43 −0
Original line number Original line Diff line number Diff line
@@ -19,7 +19,11 @@ package com.android.test.filters;
import static com.android.test.filters.SelectTest.OPTION_SELECT_TEST;
import static com.android.test.filters.SelectTest.OPTION_SELECT_TEST;
import static com.android.test.filters.SelectTest.OPTION_SELECT_TEST_VERBOSE;
import static com.android.test.filters.SelectTest.OPTION_SELECT_TEST_VERBOSE;


import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;


import android.os.Bundle;
import android.os.Bundle;
@@ -145,6 +149,45 @@ public class SelectTestTests {
        }
        }
    }
    }


    @Test
    public void testAddSelectTest() {
        final Bundle testArgs = new Bundle();

        final Bundle modifiedTestArgs =
                SelectTest.addSelectTest(testArgs, PACKAGE_A, CLASS_B3, METHOD_C5X);
        assertSame(testArgs, modifiedTestArgs);

        final String selectTestArgs = modifiedTestArgs.getString(OPTION_SELECT_TEST);
        assertNotNull(selectTestArgs);
        final String[] selectedTests = selectTestArgs.split(",");
        assertThat(selectedTests, hasItemInArray(PACKAGE_A));
        assertThat(selectedTests, hasItemInArray(CLASS_B3));
        assertThat(selectedTests, hasItemInArray(METHOD_C5X));
    }

    @Test
    public void testAddSelectTest_prependExistingTestArg() {
        final Bundle testArgs = new Bundle();
        testArgs.putString(OPTION_SELECT_TEST, new StringJoiner(",")
                .add(PACKAGE_A)
                .add(CLASS_B3)
                .add(METHOD_C5X)
                .toString());

        final Bundle modifiedTestArgs =
                SelectTest.addSelectTest(testArgs, PACKAGE_B, CLASS_B4, METHOD_C6Y);

        final String selectTestArgs = modifiedTestArgs.getString(OPTION_SELECT_TEST);
        assertNotNull(selectTestArgs);
        final String[] selectedTests = selectTestArgs.split(",");
        assertThat(selectedTests, hasItemInArray(PACKAGE_A));
        assertThat(selectedTests, hasItemInArray(CLASS_B3));
        assertThat(selectedTests, hasItemInArray(METHOD_C5X));
        assertThat(selectedTests, hasItemInArray(PACKAGE_B));
        assertThat(selectedTests, hasItemInArray(CLASS_B4));
        assertThat(selectedTests, hasItemInArray(METHOD_C6Y));
    }

    @Test
    @Test
    public void testFilterDisabled() {
    public void testFilterDisabled() {
        final Filter filter = mBuilder.build();
        final Filter filter = mBuilder.build();