@Test
public void saveAndRestoreUnmodifiableSet() {
// use string buffer so its modifiable
final StringBuffer id = new StringBuffer();
ResourceSet delegate = createResources(1, 2);
final ResourceSet unmodifiableSet = new UnmodifiableResourceSet(
delegate);
when(windowContent.save(any(ResourceSetCollector.class))).thenAnswer(
new Answer<Memento>() {
@Override
public Memento answer(InvocationOnMock invocation)
throws Throwable {
ResourceSetCollector collector = (ResourceSetCollector) invocation
.getArguments()[0];
id.append(collector.storeResourceSet(unmodifiableSet));
return new Memento();
}
});
when(resourceManager.getByUri(createResource(1).getUri())).thenReturn(
createResource(1));
when(resourceManager.getByUri(createResource(2).getUri())).thenReturn(
createResource(2));
WorkspaceDTO dto = doSave();
doLoad(dto);
// check correct restore -- how
ArgumentCaptor<ResourceSetAccessor> argument = ArgumentCaptor
.forClass(ResourceSetAccessor.class);
verify(restoredView, times(1)).restore(any(Memento.class),
any(PersistableRestorationService.class), argument.capture());
ResourceSet resourceSet = argument.getValue().getResourceSet(
Integer.parseInt(id.toString()));
assertEquals(true, resourceSet instanceof UnmodifiableResourceSet);
assertEquals(
true,
delegate.containsEqualResources(((DelegatingResourceSet) resourceSet)