String json = sut.convertBackgroundToJSON(background).toString();
StringRepresentation jsonRep = new StringRepresentation(json);
final Background bg = new Background(new Person());
bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION);
bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR);
bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST);
bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL);
context.checking(new Expectations()
{
{
oneOf(mapper).findOrCreatePersonBackground(with(uuid));
will(returnValue(bg));
oneOf(mapper).flush(uuid);
}
});
// precondition, the background is empty
assertEquals(0, bg.getBackgroundItems(BackgroundItemType.AFFILIATION).size());
assertEquals(0, bg.getBackgroundItems(BackgroundItemType.HONOR).size());
assertEquals(0, bg.getBackgroundItems(BackgroundItemType.INTEREST).size());
assertEquals(0, bg.getBackgroundItems(BackgroundItemType.SKILL).size());
// perform the action to be tested
sut.storeRepresentation(jsonRep);
// post condition, make sure mapper was called and items were set
context.assertIsSatisfied();
assertEquals(3, bg.getBackgroundItems(BackgroundItemType.AFFILIATION).size());
assertEquals(3, bg.getBackgroundItems(BackgroundItemType.HONOR).size());
assertEquals(3, bg.getBackgroundItems(BackgroundItemType.INTEREST).size());
assertEquals(3, bg.getBackgroundItems(BackgroundItemType.SKILL).size());
assertEquals("a", bg.getBackgroundItems(BackgroundItemType.AFFILIATION).get(0).toString());
assertEquals("d", bg.getBackgroundItems(BackgroundItemType.HONOR).get(0).toString());
assertEquals("1", bg.getBackgroundItems(BackgroundItemType.INTEREST).get(0).toString());
assertEquals("4", bg.getBackgroundItems(BackgroundItemType.SKILL).get(0).toString());
}