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

Commit 96cf4533 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Make SelectTest append selectTest argument from extended class"

parents e9e5017a 172b7a7e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -19,7 +19,10 @@ java_library {

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

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

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
@@ -131,7 +133,8 @@ public class SelectTest extends Filter {
     *
     * @param testArgs instrumentation test arguments.
     * @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
    protected static Bundle addSelectTest(
@@ -139,7 +142,13 @@ public class SelectTest extends Filter {
        if (selectTests.length == 0) {
            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;
    }

+43 −0
Original line number 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_VERBOSE;

import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
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 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
    public void testFilterDisabled() {
        final Filter filter = mBuilder.build();