StatefullMockPage testPage = new StatefullMockPage();
testPage.state = oldState;
// storing test page
TestMapperContext mapperContext = new TestMapperContext();
mapperContext.getPageManager().touchPage(testPage);
mapperContext.getPageManager().commitRequest();
// by cleaning session cache we make sure of not being testing the same in-memory instance
mapperContext.cleanSessionCache();
PageProvider pageProvider = mapperContext.new TestPageProvider(testPage.getPageId(), 0);
// simulation an test call to isNewPageInstance
boolean isNewPageInstance = pageProvider.isNewPageInstance();
assertFalse("test page is already stored", isNewPageInstance);
// changing some sate
StatefullMockPage providedPage = (StatefullMockPage)pageProvider.getPageInstance();
providedPage.state = newState;
mapperContext.getPageManager().touchPage(providedPage);
mapperContext.getPageManager().commitRequest();
mapperContext.cleanSessionCache();
StatefullMockPage restauredPageAfterStateChage = (StatefullMockPage)mapperContext.getPageInstance(testPage.getPageId());
// OK, if the correct page got touched/stores its change will be visible now
assertEquals(newState, restauredPageAfterStateChage.state);
}