Sou novo no assunto e até consegui fazer outro teste em outro aplicativo, chamado Tipster.
Mas, seguinte: Alguém poderia me dar uma luz de como testar o método onLocationChanged na classe LocationChange
. Vou colocar as duas classes, a classe principal e a classe teste que fiz para me ajudarem, se possível.
**Classe LocationChange:**
package com.osmlocation;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
public class LocationChange extends Activity implements LocationListener {
private LocationManager myLocationManager;
private MapView mapView;
private MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapview);
mapController = this.mapView.getController();
mapController.setZoom(15);
myLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100, this);
GeoPoint mapCenter = new GeoPoint(53554070, -2959520);
mapController.setCenter(mapCenter);
System.out.println("Passou aqui 1");
}
@Override
public void onLocationChanged(Location location) {
int latitude = (int) (location.getLatitude() * 1E6);
int longitude = (int) (location.getLongitude() * 1E6);
GeoPoint geopoint = new GeoPoint(latitude, longitude);
mapController.setCenter(geopoint);
mapView.invalidate();
System.out.println("Passou aqui 2");
}
public void setLocation(Location location) {
int latitude = (int) (location.getLatitude() * 1E6);
int longitude = (int) (location.getLongitude() * 1E6);
GeoPoint geopoint = new GeoPoint(latitude, longitude);
mapController.setCenter(geopoint);
mapView.invalidate();
System.out.println("Passou aqui 2");
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
}
**Classe LocationChangeTest:**
package com.osmlocation;
import android.annotation.TargetApi;
import android.os.Build;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import org.osmdroid.util.GeoPoint;
/**
* Created by miche on 31/03/2017.
*/
public class LocationChangeTest extends ActivityInstrumentationTestCase2<LocationChange> {
@TargetApi(Build.VERSION_CODES.FROYO)
public LocationChangeTest() {
super(LocationChange.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
public void testOnLocationChanged() {
LocationChange activity = getActivity();
final int latitude = 100;
final int longitude = 50;
final GeoPoint geopoint = new GeoPoint(latitude, longitude);
final View mapview = activity.findViewById(R.id.mapview);
// Definindo os campos na tela do usuário
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
mapview.setOnClickListener((View.OnClickListener) geopoint);
}
});
getInstrumentation().waitForIdleSync();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
}