Merge branch 'master' into dependency-injection

This commit is contained in:
Paul Hawke 2017-11-24 22:12:43 -06:00
commit 02b5b9b680
148 changed files with 1169 additions and 364 deletions

View file

@ -9,7 +9,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class MediaTest {
@Test
public void displayTitleShouldStripExtension() {

View file

@ -18,7 +18,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyControllerTest {
@Test

View file

@ -11,7 +11,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class PageTitleTest {
@Test
public void displayTextShouldNotBeUnderscored() {

View file

@ -0,0 +1,12 @@
package fr.free.nrw.commons;
import com.squareup.leakcanary.RefWatcher;
// This class is automatically discovered by Robolectric
public class TestCommonsApplication extends CommonsApplication {
@Override
protected RefWatcher setupLeakCanary() {
// No leakcanary in unit tests.
return RefWatcher.DISABLED;
}
}

View file

@ -1,32 +0,0 @@
package fr.free.nrw.commons;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
public class UtilsTest {
@Test public void stripLocalizedStringPass() {
Assert.assertThat(Utils.stripLocalizedString("Hello"), is("Hello"));
}
@Test public void stripLocalizedStringJa() {
Assert.assertThat(Utils.stripLocalizedString("\"こんにちは\"@ja"), is("こんにちは"));
}
@Test public void capitalizeLowercase() {
Assert.assertThat(Utils.capitalize("hello"), is("Hello"));
}
@Test public void capitalizeFullCaps() {
Assert.assertThat(Utils.capitalize("HELLO"), is("HELLO"));
}
@Test public void capitalizeNumbersPass() {
Assert.assertThat(Utils.capitalize("12x"), is("12x"));
}
@Test public void capitalizeJaPass() {
Assert.assertThat(Utils.capitalize("こんにちは"), is("こんにちは"));
}
}

View file

@ -17,6 +17,7 @@ import java.util.Map;
import java.util.Set;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.TestCommonsApplication;
import io.reactivex.observers.TestObserver;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
@ -28,7 +29,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class ApacheHttpClientMediaWikiApiTest {
private ApacheHttpClientMediaWikiApi testObject;

View file

@ -20,13 +20,14 @@ import java.util.Collections;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.TestCommonsApplication;
import fr.free.nrw.commons.location.LatLng;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyAdapterFactoryTest {
private static final Place PLACE = new Place("name", Place.Description.AIRPORT,

View file

@ -0,0 +1,31 @@
package fr.free.nrw.commons
import org.junit.Assert
import org.junit.Test
import org.hamcrest.CoreMatchers.`is` as _is
class UtilsTest {
@Test fun `strip nothing from non-localized string`() {
Assert.assertThat(Utils.stripLocalizedString("Hello"), _is("Hello"))
}
@Test fun `strip tag from Japanese string`() {
Assert.assertThat(Utils.stripLocalizedString("\"こんにちは\"@ja"), _is("こんにちは"))
}
@Test fun `capitalize first letter`() {
Assert.assertThat(Utils.capitalize("hello"), _is("Hello"))
}
@Test fun `capitalize - pass all-capital string as it is`() {
Assert.assertThat(Utils.capitalize("HELLO"), _is("HELLO"))
}
@Test fun `capitalize - pass numbers`() {
Assert.assertThat(Utils.capitalize("12x"), _is("12x"))
}
@Test fun `capitalize - pass Japanase characters`() {
Assert.assertThat(Utils.capitalize("こんにちは"), _is("こんにちは"))
}
}