"<Require feature=\"requiredview2\" views=\"view2\"/>" +
"</ModulePrefs>" +
"<Content views=\"view1, default\" type=\"html\"/>" +
"<Content views=\"view2\" type=\"html\"/>" +
"</Module>";
FeatureRegistry registry = mock(FeatureRegistry.class, true);
Gadget gadget = new Gadget()
.setContext(context)
.setGadgetFeatureRegistry(registry)
.setSpec(new GadgetSpec(Uri.parse(SPEC_URL), xml));
List<Element> viewEles = Lists.newArrayList();
gadget.setCurrentView(new View("view2", viewEles, null));
Collection<String> needed = Lists.newArrayList(gadget.getSpec().getModulePrefs().getViewFeatures("view2").keySet());
List<String> returned = Lists.newArrayList(needed);
// Call should only happen once, and be cached from there on out.
expect(registry.getFeatures(eq(needed))).andReturn(returned).anyTimes();
replay();
List<String> requiredFeatures = Lists.newArrayList(gadget.getViewFeatures().keySet());
assertEquals(returned, requiredFeatures);
assertEquals(3, requiredFeatures.size());
assertTrue(!requiredFeatures.contains("requiredview1"));