// setup the list of mocked gadgets
// ----------------
// -- Gadget #0 - zone 0, index 0
Gadget gadget0 = context.mock(Gadget.class, "gadget0");
exactly(1).of(gadget0).getZoneNumber();
will(returnValue(0));
// should never have to ask this gadget for its zone index
never(gadget0).getZoneIndex();
// ----------------
// ----------------
// -- Gadget #1 - <LAST ZONE>, index 0
Gadget gadget1 = context.mock(Gadget.class, "gadget1");
exactly(1).of(gadget1).getZoneNumber();
will(returnValue(tabLayout.getNumberOfZones() - 1));
// ----------------
// -- Gadget #2 - <LAST ZONE>, index 1
Gadget gadget2 = context.mock(Gadget.class, "gadget2");
// set the zone number - it MUST be requested once
exactly(1).of(gadget2).getZoneNumber();
will(returnValue(tabLayout.getNumberOfZones() - 1));
// add the gadgets to the collection
gadgets.add(gadget0);
gadgets.add(gadget1);
gadgets.add(gadget2);
oneOf(gadget0).getZoneIndex();
will(returnValue(0));
oneOf(gadget0).setZoneIndex(1);
oneOf(person).getId();
will(returnValue(0L));
// when asked for the gadgets, return the mocked list
atLeast(1).of(tab).getGadgets();
will(returnValue(gadgets));
allowing(actionContext).getPrincipal();
will(returnValue(principal));
allowing(principal).getAccountId();
will(returnValue("username"));
// action has to load the tab by ID
allowing(personMapper).findByAccountId("username");
will(returnValue(person));
oneOf(person).getTabs(TabGroupType.START);
will(returnValue(tabList));
// will need a flush() when all done
exactly(1).of(tabMapper).flush();
allowing(deleteCacheKeysMapper).execute(with(any(Set.class)));
}
});
Gadget actual = (Gadget) sut.execute(actionContext);
// make sure the new gadget is of the type passed in
assertEquals(gadgetDefinitionId, (Long) actual.getGadgetDefinition().getId());
// make sure the gadget is in the right zone and index
assertEquals(0, actual.getZoneIndex());
assertEquals(0, actual.getZoneNumber());
context.assertIsSatisfied();
}