public static VisualItem createVisualItem(String visualItemId,
ResourceSet resources) {
final AtomicReference<Object> displayObjectBuffer = new AtomicReference<Object>();
VisualItem visualItem = mock(VisualItem.class);
when(visualItem.getResources()).thenReturn(resources);
when(visualItem.getId()).thenReturn(visualItemId);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
displayObjectBuffer.set(invocation.getArguments()[0]);
return null;
}
}).when(visualItem).setDisplayObject(any(Object.class));
when(visualItem.getDisplayObject()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return displayObjectBuffer.get();
}
});