[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Fix potential NPE & hygiene in DescriptionEditView
jenkins-bot has submitted this change and it was merged. Change subject: Fix potential NPE & hygiene in DescriptionEditView .. Fix potential NPE & hygiene in DescriptionEditView • Allow for an original null description and add an @Nullable annotation • Update test save button logic and refactor lightly • Rename editText to pageDescriptionText Bug: T148203 Change-Id: I73f6bc98f8b6bf3a1b82d16ea55ce7ac8583ca0e --- M app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java M app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java M app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java 3 files changed, 35 insertions(+), 29 deletions(-) Approvals: Dbrant: Looks good to me, approved jenkins-bot: Verified diff --git a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java index 54e1630..7cce7bc 100644 --- a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java +++ b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java @@ -75,7 +75,7 @@ assertThat(subject.getDescription(), is(expected.getDescription())); } -// todo: resolve why the button doesn't show up yet here or in the actual screenshots above +// todo: resolve why the button doesn't show // @Theory public void testSetSaveState(@TestedOnBool final boolean saving) { // defaultSetUp(); // subject.setSaveState(saving); @@ -100,7 +100,7 @@ defaultSetUp(); String expected = nul ? null : "text"; subject.setDescription(expected); -assertThat(subject.editText.getText().toString(), is(emptyIfNull(expected))); +assertThat(subject.pageDescriptionText.getText().toString(), is(emptyIfNull(expected))); } private void defaultSetUp() { @@ -117,5 +117,9 @@ subject.setTitle(str(title)); subject.setDescription(str(description)); subject.setSaveState(saving); + +// todo: resolve why the button doesn't show deterministically. the button appears either +// correctly or in the upper left +subject.saveButton.hide(); } -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java b/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java index 43f3910..5681fbd 100644 --- a/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java +++ b/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java @@ -124,11 +124,11 @@ .build(); } -protected String str(@NonNull TestStr str, Object... formatArgs) { +protected String str(@NonNull TestStr str, @Nullable Object... formatArgs) { return str(str.id(), formatArgs); } -protected String str(@StringRes int id, Object... formatArgs) { +protected String str(@StringRes int id, @Nullable Object... formatArgs) { return id == 0 ? null : ctx().getString(id, formatArgs); } @@ -140,18 +140,21 @@ Configuration cfg = new Configuration(ctx.getResources().getConfiguration()); cfg.screenWidthDp = widthDp; cfg.fontScale = fontScale.multiplier(); - -if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { -cfg.setLocales(new LocaleList(locale)); -} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { -cfg.setLocale(locale); -cfg.setLayoutDirection(locale); -} else { -//noinspection deprecation -cfg.locale = locale; -} +setConfigLocale(cfg, locale); ctx.getResources().updateConfiguration(cfg, null); +} + +private void setConfigLocale(@NonNull Configuration config, @NonNull Locale locale) { +if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { +config.setLocales(new LocaleList(locale)); +} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { +config.setLocale(locale); +config.setLayoutDirection(locale); +} else { +//noinspection deprecation +config.locale = locale; +} } // todo: identify method name by @Theory / @Test annotation instead of depth and remove repeated @@ -167,4 +170,4 @@ return name; } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java index 3e36696..0fcbbef 100644 --- a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java +++ b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java @@ -10,7 +10,6 @@ import
[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Fix potential NPE & hygiene in DescriptionEditView
Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/320311 Change subject: Fix potential NPE & hygiene in DescriptionEditView .. Fix potential NPE & hygiene in DescriptionEditView • Allow for an original null description and add an @Nullable annotation • Update test save button logic and refactor lightly • Rename editText to pageDescriptionText Bug: T148203 Change-Id: I73f6bc98f8b6bf3a1b82d16ea55ce7ac8583ca0e --- M app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java M app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java M app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java 3 files changed, 35 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/11/320311/1 diff --git a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java index 54e1630..7cce7bc 100644 --- a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java +++ b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java @@ -75,7 +75,7 @@ assertThat(subject.getDescription(), is(expected.getDescription())); } -// todo: resolve why the button doesn't show up yet here or in the actual screenshots above +// todo: resolve why the button doesn't show // @Theory public void testSetSaveState(@TestedOnBool final boolean saving) { // defaultSetUp(); // subject.setSaveState(saving); @@ -100,7 +100,7 @@ defaultSetUp(); String expected = nul ? null : "text"; subject.setDescription(expected); -assertThat(subject.editText.getText().toString(), is(emptyIfNull(expected))); +assertThat(subject.pageDescriptionText.getText().toString(), is(emptyIfNull(expected))); } private void defaultSetUp() { @@ -117,5 +117,9 @@ subject.setTitle(str(title)); subject.setDescription(str(description)); subject.setSaveState(saving); + +// todo: resolve why the button doesn't show deterministically. the button appears either +// correctly or in the upper left +subject.saveButton.hide(); } -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java b/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java index 43f3910..5681fbd 100644 --- a/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java +++ b/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java @@ -124,11 +124,11 @@ .build(); } -protected String str(@NonNull TestStr str, Object... formatArgs) { +protected String str(@NonNull TestStr str, @Nullable Object... formatArgs) { return str(str.id(), formatArgs); } -protected String str(@StringRes int id, Object... formatArgs) { +protected String str(@StringRes int id, @Nullable Object... formatArgs) { return id == 0 ? null : ctx().getString(id, formatArgs); } @@ -140,18 +140,21 @@ Configuration cfg = new Configuration(ctx.getResources().getConfiguration()); cfg.screenWidthDp = widthDp; cfg.fontScale = fontScale.multiplier(); - -if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { -cfg.setLocales(new LocaleList(locale)); -} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { -cfg.setLocale(locale); -cfg.setLayoutDirection(locale); -} else { -//noinspection deprecation -cfg.locale = locale; -} +setConfigLocale(cfg, locale); ctx.getResources().updateConfiguration(cfg, null); +} + +private void setConfigLocale(@NonNull Configuration config, @NonNull Locale locale) { +if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { +config.setLocales(new LocaleList(locale)); +} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { +config.setLocale(locale); +config.setLayoutDirection(locale); +} else { +//noinspection deprecation +config.locale = locale; +} } // todo: identify method name by @Theory / @Test annotation instead of depth and remove repeated @@ -167,4 +170,4 @@ return name; } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java index 3e36696..0fcbbef 100644 --- a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java +++ b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java @@ -10,7