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

Commit 845df4cf authored by wilsonshih's avatar wilsonshih
Browse files

Fix failing tests in GpsCoordinatesTextClassifierTest

Complete a TODO in testInvalidPatterns.
Fix:69541801
Test: atest DocumentsUITests:GpsCoordinatesTextClassifierTest

Change-Id: I15fd520861fda7afc1acc0ee4189c7ad8b01f26f
parent 80897d8a
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -46,8 +46,21 @@ public class GpsCoordinatesTextClassifierTest {
        PackageManager pm = TestPackageManager.create();
        Context context = InstrumentationRegistry.getTargetContext();

        TextClassifier defaultClassifier =
                context.getSystemService(TextClassificationManager.class).getTextClassifier();
        // The test case assertClassifiedGeo("-90.1, -180.156754", false) failed when full test,
        // but it can pass "atest DocumentsUITests". Which means there might have some corruption
        // when running whole test process.
        // If someone run test case on TextClassificationManager but forgot to reset classifier
        // back to default while teardown, such as cts/TextClassificationManagerTest.java, other
        // test case might be effected. There are two ways to fix this test case, one is to fix
        // at setup method with API setTextClassifier(null), this can ensure our test case is
        // running with default classifier, i.e. systemTextClassifier. Another way is to find all
        // test case which should clean their textClassifier object back to default while teardown,
        // but this would be difficult to maintain than previous method.
        TextClassificationManager manager =
                context.getSystemService(TextClassificationManager.class);
        // Reset classifier to default
        manager.setTextClassifier(null);
        TextClassifier defaultClassifier = manager.getTextClassifier();
        mClassifier = new GpsCoordinatesTextClassifier(pm, defaultClassifier);
    }

@@ -78,10 +91,9 @@ public class GpsCoordinatesTextClassifierTest {
        assertClassifiedGeo("GeoIntent", false);
        assertClassifiedGeo("A.B, C.D", false);
        assertClassifiedGeo("90.165464, 180.1", false);
        // TODO: Failing tests below
        // assertClassifiedGeo("-90.1, -180.156754", false);
        // assertClassifiedGeo("5000, 5000", false);
        // assertClassifiedGeo("500, 500", false);
        assertClassifiedGeo("-90.1, -180.156754", false);
        assertClassifiedGeo("5000, 5000", false);
        assertClassifiedGeo("500, 500", false);
    }

    private void assertClassifiedGeo(CharSequence text, boolean expectClassified) {