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

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

Merge "Fix ModelFile.isPreferredTo method"

parents 93b06370 9d209618
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -251,6 +251,9 @@ public final class ModelFileManager {
            if (!mLanguageIndependent && model.mLanguageIndependent) {
                return true;
            }
            if (mLanguageIndependent && !model.mLanguageIndependent) {
                return false;
            }

            // A higher-version model is preferred.
            if (mVersion > model.getVersion()) {
+22 −0
Original line number Diff line number Diff line
@@ -202,6 +202,28 @@ public class ModelFileManagerTest {
        assertThat(bestModelFile).isEqualTo(matchButOlderModel);
    }

    @Test
    public void findBestModel_languageIsMoreImportantThanVersion_bestModelComesFirst() {
        ModelFileManager.ModelFile matchLocaleModel =
                new ModelFileManager.ModelFile(
                        new File("/path/b"), 1,
                        Collections.singletonList(Locale.forLanguageTag("ja")), false);

        ModelFileManager.ModelFile languageIndependentModel =
                new ModelFileManager.ModelFile(
                        new File("/path/a"), 2,
                        Collections.emptyList(), true);
        when(mModelFileSupplier.get())
                .thenReturn(
                        Arrays.asList(matchLocaleModel, languageIndependentModel));

        ModelFileManager.ModelFile bestModelFile =
                mModelFileManager.findBestModelFile(
                        LocaleList.forLanguageTags("ja"));

        assertThat(bestModelFile).isEqualTo(matchLocaleModel);
    }

    @Test
    public void modelFileEquals() {
        ModelFileManager.ModelFile modelA =