Inspector extends View { @Override public boolean setHousedViewManifestation(ViewInfo viewInfo) { AbstractComponent ac = view.getManifestedComponent(); if (!ac.isStale() && ac.isDirty()) { if (!commitOrAbortPendingChanges()) { return false; } } refreshInspector(viewInfo); preferredViewType = viewInfo.getType(); return true; } Inspector(AbstractComponent ac, ViewInfo vi); AbstractComponent getCurrentlyShowingComponent(); void refreshCurrentlyShowingView(); @Override View getHousedViewManifestation(); @Override void enterLockedState(); @Override void exitLockedState(); @Override boolean setHousedViewManifestation(ViewInfo viewInfo); static final String DEFAULT_INSPECTOR_VIEW_PROP_KEY; }
@Test (dataProvider="generateSetCases") public void testSetHousedViewManifestation(boolean stale, boolean dirty, final boolean save, boolean expectPrompt, boolean expectChange, boolean expectSave) { inspectorPropertyChangeListener.propertyChange(mockPropertyEvent); ViewInfo newViewInfo = Mockito.mock(ViewInfo.class); @SuppressWarnings("serial") View newView = new View(mockComponent, newViewInfo) {}; Mockito.when(mockComponent.isStale()).thenReturn(stale); Mockito.when(mockComponent.isDirty()).thenReturn(dirty); Mockito.when(newViewInfo.createView(mockComponent)).thenReturn(newView); Mockito.when(newViewInfo.getType()).thenReturn("new"); Mockito.when(mockWindowManager.showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any())).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] options = (Object[]) invocation.getArguments()[2]; return save ? options[0] : options[1]; } }); inspector.setHousedViewManifestation(newViewInfo); Mockito.verify(mockWindowManager, Mockito.times(expectPrompt ? 1 : 0)) .showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any()); Assert.assertEquals(inspector.getHousedViewManifestation(), expectChange ? newView : view); Mockito.verify(mockPersistence, Mockito.times(expectSave ? 1 : 0)).persist(Mockito.<Collection<AbstractComponent>>argThat(new ArgumentMatcher<Collection<AbstractComponent>>() { @Override public boolean matches(Object argument) { return argument instanceof Collection && ((Collection)argument).contains(mockComponent); } })); }