mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Merge branch 'master' into dependency-injection
This commit is contained in:
commit
fb30a34478
41 changed files with 339 additions and 50 deletions
|
|
@ -1,12 +1,182 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v4.util.LruCache;
|
||||
|
||||
import com.squareup.leakcanary.RefWatcher;
|
||||
|
||||
// This class is automatically discovered by Robolectric
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||
import fr.free.nrw.commons.di.CommonsApplicationComponent;
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule;
|
||||
import fr.free.nrw.commons.di.DaggerCommonsApplicationComponent;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
||||
import fr.free.nrw.commons.upload.UploadController;
|
||||
|
||||
public class TestCommonsApplication extends CommonsApplication {
|
||||
|
||||
CommonsApplicationComponent mockApplicationComponent;
|
||||
|
||||
@Mock
|
||||
CommonsApplicationModule commonsApplicationModule;
|
||||
@Mock
|
||||
AccountUtil accountUtil;
|
||||
@Mock
|
||||
SharedPreferences appSharedPreferences;
|
||||
@Mock
|
||||
SharedPreferences defaultSharedPreferences;
|
||||
@Mock
|
||||
SharedPreferences otherSharedPreferences;
|
||||
@Mock
|
||||
UploadController uploadController;
|
||||
@Mock
|
||||
SessionManager sessionManager;
|
||||
@Mock
|
||||
MediaWikiApi mediaWikiApi;
|
||||
@Mock
|
||||
LocationServiceManager locationServiceManager;
|
||||
@Mock
|
||||
CacheController cacheController;
|
||||
@Mock
|
||||
DBOpenHelper dbOpenHelper;
|
||||
@Mock
|
||||
NearbyPlaces nearbyPlaces;
|
||||
@Mock
|
||||
LruCache<String, String> lruCache;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RefWatcher setupLeakCanary() {
|
||||
// No leakcanary in unit tests.
|
||||
return RefWatcher.DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonsApplicationComponent injector() {
|
||||
if (mockApplicationComponent == null) {
|
||||
mockApplicationComponent = DaggerCommonsApplicationComponent.builder()
|
||||
.appModule(new CommonsApplicationModule(this) {
|
||||
@Override
|
||||
public AccountUtil providesAccountUtil() {
|
||||
return accountUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences providesApplicationSharedPreferences() {
|
||||
return appSharedPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences providesDefaultSharedPreferences() {
|
||||
return defaultSharedPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences providesOtherSharedPreferences() {
|
||||
return otherSharedPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadController providesUploadController(SessionManager sessionManager, SharedPreferences sharedPreferences) {
|
||||
return uploadController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionManager providesSessionManager(MediaWikiApi mediaWikiApi) {
|
||||
return sessionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaWikiApi provideMediaWikiApi() {
|
||||
return mediaWikiApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocationServiceManager provideLocationServiceManager() {
|
||||
return locationServiceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheController provideCacheController() {
|
||||
return cacheController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBOpenHelper provideDBOpenHelper() {
|
||||
return dbOpenHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NearbyPlaces provideNearbyPlaces() {
|
||||
return nearbyPlaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LruCache<String, String> provideLruCache() {
|
||||
return lruCache;
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
return mockApplicationComponent;
|
||||
}
|
||||
|
||||
public AccountUtil getAccountUtil() {
|
||||
return accountUtil;
|
||||
}
|
||||
|
||||
public SharedPreferences getAppSharedPreferences() {
|
||||
return appSharedPreferences;
|
||||
}
|
||||
|
||||
public SharedPreferences getDefaultSharedPreferences() {
|
||||
return defaultSharedPreferences;
|
||||
}
|
||||
|
||||
public SharedPreferences getOtherSharedPreferences() {
|
||||
return otherSharedPreferences;
|
||||
}
|
||||
|
||||
public UploadController getUploadController() {
|
||||
return uploadController;
|
||||
}
|
||||
|
||||
public SessionManager getSessionManager() {
|
||||
return sessionManager;
|
||||
}
|
||||
|
||||
public MediaWikiApi getMediaWikiApi() {
|
||||
return mediaWikiApi;
|
||||
}
|
||||
|
||||
public LocationServiceManager getLocationServiceManager() {
|
||||
return locationServiceManager;
|
||||
}
|
||||
|
||||
public CacheController getCacheController() {
|
||||
return cacheController;
|
||||
}
|
||||
|
||||
public DBOpenHelper getDbOpenHelper() {
|
||||
return dbOpenHelper;
|
||||
}
|
||||
|
||||
public NearbyPlaces getNearbyPlaces() {
|
||||
return nearbyPlaces;
|
||||
}
|
||||
|
||||
public LruCache<String, String> getLruCache() {
|
||||
return lruCache;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.TestCommonsApplication;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
|
||||
public class NearbyActivityTest {
|
||||
|
||||
private static final LatLng ST_LOUIS_MO_LAT_LNG = new LatLng(38.627003, -90.199402, 0);
|
||||
|
||||
private ActivityController<NearbyActivity> activityController;
|
||||
private NearbyActivity nearbyActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
TestCommonsApplication application = (TestCommonsApplication) RuntimeEnvironment.application;
|
||||
when(application.getLocationServiceManager().getLastLocation()).thenReturn(ST_LOUIS_MO_LAT_LNG);
|
||||
|
||||
activityController = Robolectric.buildActivity(NearbyActivity.class);
|
||||
nearbyActivity = activityController.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void activityLaunchesAndShowsList() {
|
||||
activityController.create().resume().visible();
|
||||
assertNotNull(nearbyActivity.getSupportFragmentManager().findFragmentByTag("NearbyListFragment"));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue