MenuRequest extends JsonArrayRequest<RestoMenu> { @NonNull @Override protected String getAPIUrl() { String resto = RestoPreferenceFragment.getRestoEndpoint(context, preferences); return String.format(Locale.ROOT, OVERVIEW_URL, resto); } MenuRequest(Context context); @Override Duration getCacheDuration();  }
@Test public void testDefaultUrlIsUsed() { MenuRequest request = new MenuRequest(context); String defaultResto = RestoPreferenceFragment.getDefaultResto(context); String expected = String.format(MenuRequest.OVERVIEW_URL, defaultResto); Assert.assertEquals(expected, request.getAPIUrl()); }
@Test public void testOtherUrl() { final int random_resto = ThreadLocalRandom.current().nextInt(1, RESTAURANTS.length); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); preferences.edit() .putString(RestoPreferenceFragment.PREF_RESTO_KEY, RESTAURANTS[random_resto]) .apply(); MenuRequest request = new MenuRequest(context); Assert.assertEquals(String.format(MenuRequest.OVERVIEW_URL, RESTAURANTS[random_resto]), request.getAPIUrl()); }