private Gadget mockGadget(String targetUrl, boolean isTypeUrl, String viewStr, String lang,
String country, boolean isDebug, boolean ignoreCache, Map<String, String> specPrefs,
Map<String, String> inPrefs, boolean needsPrefSubst, List<String> features) {
View view = createMock(View.class);
ModulePrefs modulePrefs = createMock(ModulePrefs.class);
GadgetSpec spec = createMock(GadgetSpec.class);
GadgetContext context = createMock(GadgetContext.class);
Gadget gadget = createMock(Gadget.class);
// Base URL/view.
Uri targetUri = Uri.parse(targetUrl);
if (isTypeUrl) {
expect(view.getType()).andReturn(ContentType.URL).anyTimes();
expect(view.getHref()).andReturn(targetUri).anyTimes();
} else {
expect(view.getType()).andReturn(ContentType.HTML).anyTimes();
expect(spec.getUrl()).andReturn(targetUri).anyTimes();
}
expect(view.getName()).andReturn(viewStr).anyTimes();
// Basic context info
Locale locale = new Locale(lang, country);
expect(context.getUrl()).andReturn(SPEC_URI).anyTimes();
expect(context.getContainer()).andReturn(CONTAINER).anyTimes();
expect(context.getLocale()).andReturn(locale).anyTimes();
expect(context.getDebug()).andReturn(isDebug).anyTimes();
expect(context.getIgnoreCache()).andReturn(ignoreCache).anyTimes();
// All Features (doesn't distinguish between transitive and not)
expect(gadget.getAllFeatures()).andReturn(features).anyTimes();
// User prefs
List<UserPref> specPrefList = Lists.newLinkedList();
for (Map.Entry<String, String> specPref : specPrefs.entrySet()) {
UserPref up = createMock(UserPref.class);
expect(up.getName()).andReturn(specPref.getKey()).anyTimes();
expect(up.getDefaultValue()).andReturn(specPref.getValue()).anyTimes();
replay(up);
specPrefList.add(up);
}
expect(spec.getUserPrefs()).andReturn(specPrefList).anyTimes();
UserPrefs ctxPrefs = new UserPrefs(inPrefs);
expect(context.getUserPrefs()).andReturn(ctxPrefs).anyTimes();
expect(view.needsUserPrefSubstitution()).andReturn(needsPrefSubst).anyTimes();
// Link all the mocks together
expect(spec.getModulePrefs()).andReturn(modulePrefs).anyTimes();
expect(gadget.getCurrentView()).andReturn(view).anyTimes();
expect(gadget.getSpec()).andReturn(spec).anyTimes();
expect(gadget.getContext()).andReturn(context).anyTimes();
// Replay all