mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Merge pull request #1101 from whym/tests
Add assertions to ensure nearby places appear in the list
This commit is contained in:
		
						commit
						f99dd34a78
					
				
					 1 changed files with 26 additions and 3 deletions
				
			
		|  | @ -1,5 +1,8 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.content.Context; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.support.v7.widget.RecyclerView; | ||||
| import android.view.MenuItem; | ||||
| 
 | ||||
| import org.junit.Before; | ||||
|  | @ -12,6 +15,7 @@ import org.robolectric.Robolectric; | |||
| import org.robolectric.RobolectricTestRunner; | ||||
| import org.robolectric.annotation.Config; | ||||
| 
 | ||||
| import edu.emory.mathcs.backport.java.util.Collections; | ||||
| import fr.free.nrw.commons.BuildConfig; | ||||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.TestCommonsApplication; | ||||
|  | @ -21,7 +25,9 @@ import io.reactivex.android.plugins.RxAndroidPlugins; | |||
| import io.reactivex.plugins.RxJavaPlugins; | ||||
| import io.reactivex.schedulers.Schedulers; | ||||
| 
 | ||||
| import static junit.framework.Assert.assertNotNull; | ||||
| import static org.junit.Assert.assertNotNull; | ||||
| import static org.junit.Assert.assertNull; | ||||
| import static org.mockito.Matchers.any; | ||||
| import static org.mockito.Mockito.when; | ||||
| import static org.robolectric.Shadows.shadowOf; | ||||
| 
 | ||||
|  | @ -31,10 +37,18 @@ public class NearbyActivityTest { | |||
| 
 | ||||
|     private static final LatLng ST_LOUIS_MO_LAT_LNG | ||||
|             = new LatLng(38.627003, -90.199402, 0); | ||||
|     private static final Place AIRPORT = new Place( | ||||
|             "name", Place.Label.AIRPORT, | ||||
|             "desc", null, | ||||
|             new LatLng(38.6270, -90.1994, 0), | ||||
|             null); | ||||
| 
 | ||||
|     @Mock | ||||
|     private LocationServiceManager locationManager; | ||||
| 
 | ||||
|     @Mock | ||||
|     private NearbyController nearbyController; | ||||
| 
 | ||||
|     @InjectMocks | ||||
|     private NearbyActivity nearbyActivity; | ||||
| 
 | ||||
|  | @ -56,14 +70,23 @@ public class NearbyActivityTest { | |||
|         MockitoAnnotations.initMocks(this); | ||||
|         when(locationManager.getLastLocation()).thenReturn(ST_LOUIS_MO_LAT_LNG); | ||||
|         when(locationManager.isProviderEnabled()).thenReturn(true); | ||||
|         when(nearbyController.loadAttractionsFromLocation(any(LatLng.class), any(Context.class))) | ||||
|                 .thenReturn(Collections.singletonList(AIRPORT)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void pressRefreshAndShowList() { | ||||
|         MenuItem refresh = shadowOf(nearbyActivity).getOptionsMenu().findItem(R.id.action_refresh); | ||||
|         nearbyActivity.onOptionsItemSelected(refresh); | ||||
|         assertNotNull(nearbyActivity.getSupportFragmentManager().findFragmentByTag( | ||||
|                 NearbyListFragment.class.getSimpleName())); | ||||
| 
 | ||||
|         Fragment nearbyListFragment = nearbyActivity.getSupportFragmentManager() | ||||
|                 .findFragmentByTag(NearbyListFragment.class.getSimpleName()); | ||||
|         assertNotNull(nearbyListFragment); | ||||
| 
 | ||||
|         // one element (AIRPORT) exists in the list | ||||
|         RecyclerView view = nearbyListFragment.getView().findViewById(R.id.listView); | ||||
|         assertNotNull(view.findViewHolderForAdapterPosition(0)); | ||||
|         assertNull(view.findViewHolderForAdapterPosition(1)); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vivek Maskara
						Vivek Maskara