jenkins-bot has submitted this change and it was merged.
Change subject: Fix bug in Namespace to legacy string conversion
......................................................................
Fix bug in Namespace to legacy string conversion
Fix capitalization bug in Namespace to legacy string conversion and add
test. When converting a non-main Namespace to a legacy string, the
expected result is sentence case with underscores. For example, "Talk"
or "Gadget_definition". Fix a state bug causing the result to be fully
capitalized like "TALK" or "GADGET_DEFINITION".
Change-Id: I383f5728cfb551181d0ba9e41657863ce7cda9f4
---
M app/src/main/java/org/wikipedia/page/Namespace.java
A app/src/test/java/org/wikipedia/page/NamespaceTest.java
2 files changed, 94 insertions(+), 1 deletion(-)
Approvals:
Dbrant: Looks good to me, approved
jenkins-bot: Verified
diff --git a/app/src/main/java/org/wikipedia/page/Namespace.java
b/app/src/main/java/org/wikipedia/page/Namespace.java
index c8eacec..21ee1ba 100644
--- a/app/src/main/java/org/wikipedia/page/Namespace.java
+++ b/app/src/main/java/org/wikipedia/page/Namespace.java
@@ -78,7 +78,7 @@
public String toLegacyString() {
String string = this == MAIN ? null : this.name();
if (string != null) {
- StringUtil.capitalizeFirstChar(string.toLowerCase());
+ string = StringUtil.capitalizeFirstChar(string.toLowerCase());
}
return string;
}
diff --git a/app/src/test/java/org/wikipedia/page/NamespaceTest.java
b/app/src/test/java/org/wikipedia/page/NamespaceTest.java
new file mode 100644
index 0000000..733cf1d
--- /dev/null
+++ b/app/src/test/java/org/wikipedia/page/NamespaceTest.java
@@ -0,0 +1,93 @@
+package org.wikipedia.page;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.wikipedia.dataclient.WikiSite;
+import org.wikipedia.test.TestRunner;
+
+import java.util.Locale;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.wikipedia.page.Namespace.FILE;
+import static org.wikipedia.page.Namespace.MAIN;
+import static org.wikipedia.page.Namespace.MEDIA;
+import static org.wikipedia.page.Namespace.SPECIAL;
+import static org.wikipedia.page.Namespace.TALK;
+
+@RunWith(TestRunner.class) public class NamespaceTest {
+ private static Locale PREV_DEFAULT_LOCALE;
+
+ @BeforeClass public static void setUp() {
+ PREV_DEFAULT_LOCALE = Locale.getDefault();
+ Locale.setDefault(Locale.ENGLISH);
+ }
+
+ @AfterClass public static void tearDown() {
+ Locale.setDefault(PREV_DEFAULT_LOCALE);
+ }
+
+ @Test public void testOf() {
+ assertThat(Namespace.of(SPECIAL.code()), is(SPECIAL));
+ }
+
+ @Test public void testFromLegacyStringMain() {
+
assertThat(Namespace.fromLegacyString(WikiSite.forLanguageCode("test"), null),
is(MAIN));
+ }
+
+ @Test public void testFromLegacyStringFile() {
+ assertThat(Namespace.fromLegacyString(WikiSite.forLanguageCode("he"),
"קובץ"), is(FILE));
+ }
+
+ @Test public void testFromLegacyStringSpecial() {
+ assertThat(Namespace.fromLegacyString(WikiSite.forLanguageCode("lez"),
"Служебная"), is(SPECIAL));
+ }
+
+ @Test public void testFromLegacyStringTalk() {
+ assertThat(Namespace.fromLegacyString(WikiSite.forLanguageCode("en"),
"stringTalk"), is(TALK));
+ }
+
+ @Test public void testCode() {
+ assertThat(MAIN.code(), is(0));
+ assertThat(TALK.code(), is(1));
+ }
+
+ @Test public void testSpecial() {
+ assertThat(SPECIAL.special(), is(true));
+ assertThat(MAIN.special(), is(false));
+ }
+
+ @Test public void testMain() {
+ assertThat(MAIN.main(), is(true));
+ assertThat(TALK.main(), is(false));
+ }
+
+ @Test public void testFile() {
+ assertThat(FILE.file(), is(true));
+ assertThat(MAIN.file(), is(false));
+ }
+
+ @Test public void testTalkNegative() {
+ assertThat(MEDIA.talk(), is(false));
+ assertThat(SPECIAL.talk(), is(false));
+ }
+
+ @Test public void testTalkZero() {
+ assertThat(MAIN.talk(), is(false));
+ }
+
+ @Test public void testTalkOdd() {
+ assertThat(TALK.talk(), is(true));
+ }
+
+ @Test public void testToLegacyStringMain() {
+ assertThat(MAIN.toLegacyString(), nullValue());
+ }
+
+ @Test public void testToLegacyStringNonMain() {
+ assertThat(TALK.toLegacyString(), is("Talk"));
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/318452
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I383f5728cfb551181d0ba9e41657863ce7cda9f4
Gerrit-PatchSet: 2
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits