Set parameters of android.location.Location object from JUnit unit test

I'm trying to make unit test for a function which receive android.location.Location object. But i blocked because i don't have possibility to set up parameters for Location object.

@Test
public void testLocation() {
    Location location = new Location("gps");
    location.setAccuracy(25F);
    location.setTime(5123L);
    System.out.println("Accuracy: " + location.getAccuracy());
    System.out.println("Time: " + location.getTime());
}

Output:

Accuracy: 0.0
Time: 0

Process finished with exit code 0

Location accuracy and time are zero but the values were set in code above. It's not an Intrumentation test, i'm running it as simple unit test under jvm (Test Artifact: Unit Tests).

Using JUnit 4.12

Answers


After adding @RunWith(RobolectricTestRunner.class) - it works as expected.


Need Your Help

Link ArrayLists and save data on file

java arraylist

I am working on a Java app for a school project where we have to enter user information: Name, Student ID and their points. How can I store all the data for each user on an ArrayList (or an Array or

jQuery - convert text to google maps link

javascript jquery google-maps

I need to get address from table and create link from it. I want to replace text inside th element with mapaLink.