mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Moved 2 other tests over to use robolectric.
This commit is contained in:
parent
58013ef10c
commit
1f1a2822e8
5 changed files with 79 additions and 90 deletions
|
|
@ -1,23 +0,0 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
// TODO: use Robolectric and make it runnable without a connected device
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class MediaTest {
|
||||
@Test public void displayTitleShouldStripExtension() {
|
||||
Media m = new Media("File:Example.jpg");
|
||||
Assert.assertThat(m.getDisplayTitle(), is("Example"));
|
||||
}
|
||||
|
||||
@Test public void displayTitleShouldUseSpaceForUnderscore() {
|
||||
Media m = new Media("File:Example 1_2.jpg");
|
||||
Assert.assertThat(m.getDisplayTitle(), is("Example 1 2"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||
import fr.free.nrw.commons.nearby.NearbyController;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NearbyControllerTest {
|
||||
private Context instrumentationContext;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
instrumentationContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@Test public void testNullAttractions() {
|
||||
LatLng location = new LatLng(0, 0, 0);
|
||||
|
||||
List<NearbyBaseMarker> options =
|
||||
NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
null,
|
||||
instrumentationContext
|
||||
);
|
||||
|
||||
Assert.assertThat(options.size(), is(0));
|
||||
}
|
||||
|
||||
@Test public void testEmptyList() {
|
||||
LatLng location = new LatLng(0, 0, 0);
|
||||
List<Place> emptyList = new ArrayList<>();
|
||||
|
||||
List<NearbyBaseMarker> options =
|
||||
NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
emptyList,
|
||||
instrumentationContext
|
||||
);
|
||||
|
||||
Assert.assertThat(options.size(), is(0));
|
||||
}
|
||||
}
|
||||
25
app/src/test/java/fr/free/nrw/commons/MediaTest.java
Normal file
25
app/src/test/java/fr/free/nrw/commons/MediaTest.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21)
|
||||
public class MediaTest {
|
||||
@Test
|
||||
public void displayTitleShouldStripExtension() {
|
||||
Media m = new Media("File:Example.jpg");
|
||||
assertThat(m.getDisplayTitle(), is("Example"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayTitleShouldUseSpaceForUnderscore() {
|
||||
Media m = new Media("File:Example 1_2.jpg");
|
||||
assertThat(m.getDisplayTitle(), is("Example 1 2"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
|
||||
import static fr.free.nrw.commons.nearby.NearbyController.loadAttractionsFromLocationToBaseMarkerOptions;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21)
|
||||
public class NearbyControllerTest {
|
||||
|
||||
@Test
|
||||
public void testNullAttractions() {
|
||||
LatLng location = new LatLng(0, 0, 0);
|
||||
|
||||
List<NearbyBaseMarker> options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, null, RuntimeEnvironment.application);
|
||||
|
||||
assertThat(options.size(), is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyList() {
|
||||
LatLng location = new LatLng(0, 0, 0);
|
||||
List<Place> emptyList = new ArrayList<>();
|
||||
|
||||
List<NearbyBaseMarker> options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, emptyList, RuntimeEnvironment.application);
|
||||
|
||||
assertThat(options.size(), is(0));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
|
@ -9,62 +8,63 @@ import org.robolectric.annotation.Config;
|
|||
import java.net.URLEncoder;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21)
|
||||
public class PageTitleTest {
|
||||
@Test
|
||||
public void displayTextShouldNotBeUnderscored() {
|
||||
Assert.assertThat(new PageTitle("Ex_1 ").getDisplayText(),
|
||||
assertThat(new PageTitle("Ex_1 ").getDisplayText(),
|
||||
is("Ex 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreThanTwoColons() {
|
||||
Assert.assertThat(new PageTitle("File:sample:a.jpg").getPrefixedText(),
|
||||
assertThat(new PageTitle("File:sample:a.jpg").getPrefixedText(),
|
||||
is("File:Sample:a.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTextShouldReturnWithoutNamespace() {
|
||||
Assert.assertThat(new PageTitle("File:sample.jpg").getText(),
|
||||
assertThat(new PageTitle("File:sample.jpg").getText(),
|
||||
is("Sample.jpg"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void capitalizeNameAfterNamespace() {
|
||||
Assert.assertThat(new PageTitle("File:sample.jpg").getPrefixedText(),
|
||||
assertThat(new PageTitle("File:sample.jpg").getPrefixedText(),
|
||||
is("File:Sample.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prefixedTextShouldBeUnderscored() {
|
||||
Assert.assertThat(new PageTitle("Ex 1 ").getPrefixedText(),
|
||||
assertThat(new PageTitle("Ex 1 ").getPrefixedText(),
|
||||
is("Ex_1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMobileUriForTest() {
|
||||
Assert.assertThat(new PageTitle("Test").getMobileUri().toString(),
|
||||
assertThat(new PageTitle("Test").getMobileUri().toString(),
|
||||
is(BuildConfig.MOBILE_HOME_URL + "Test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spaceBecomesUnderscoreInUri() {
|
||||
Assert.assertThat(new PageTitle("File:Ex 1.jpg").getCanonicalUri().toString(),
|
||||
assertThat(new PageTitle("File:Ex 1.jpg").getCanonicalUri().toString(),
|
||||
is(BuildConfig.HOME_URL + "File:Ex_1.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leaveSubpageNamesUncapitalizedInUri() {
|
||||
Assert.assertThat(new PageTitle("User:Ex/subpage").getCanonicalUri().toString(),
|
||||
assertThat(new PageTitle("User:Ex/subpage").getCanonicalUri().toString(),
|
||||
is(BuildConfig.HOME_URL + "User:Ex/subpage"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicodeUri() throws Throwable {
|
||||
Assert.assertThat(new PageTitle("User:例").getCanonicalUri().toString(),
|
||||
assertThat(new PageTitle("User:例").getCanonicalUri().toString(),
|
||||
is(BuildConfig.HOME_URL + "User:" + URLEncoder.encode("例", "utf-8")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue