* is or is not a leaf.
*/
@SuppressWarnings("rawtypes")
@Test
public void testExecute() {
ExecutionResult result = null;
AbstractComponent mockComp = Mockito.mock(AbstractComponent.class);
ViewInfo mockViewInfo = Mockito.mock(ViewInfo.class);
/*
* From (the below two lines), calling getProperty with the key 'PolicyContext.PropertyName.TARGET_COMPONENT.getName()'
* returns our mocked component. Similarly calling getProperty with the key
* 'PolicyContext.PropertyName.TARGET_VIEW_INFO.getName()' returns our mocked viewInfo.
*/
context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockComp);
context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), mockViewInfo);
//Now we test:
/*Two tests (for leaf and non-leaf components) when the ViewInfo is from the MultiColView class*/
Mockito.when((Class)mockViewInfo.getViewClass()).thenReturn(MultiColView.class);
//(1) Test for leaf-components:
Mockito.when(mockComp.isLeaf()).thenReturn(true); //mocked component is a leaf
result = policy.execute(context); //context is: the component is a leaf, and the viewInfo is from MultiColView
Assert.assertEquals(result.getStatus(), false); //components which are leaves may not be viewed wrt MultiColView
//---end test on leaf-components
//(2) Test for non-leaf components:
Mockito.when(mockComp.isLeaf()).thenReturn(false); //mocked component is not a leaf
result = policy.execute(context); //context is: the component is a leaf, and the viewInfo is from MultiColView
Assert.assertEquals(result.getStatus(), true); //components which are leaves are viewable wrt MultiColView
//---end test on non-leaf components
/*Two tests (for leaf and non-leaf components) when the ViewInfo is not from the MultiColView class*/
Mockito.when((Class)mockViewInfo.getViewClass()).thenReturn(OnStiltsView.class);
//(1) Test for leaf-components:
Mockito.when(mockComp.isLeaf()).thenReturn(true); //mocked component is a leaf
result = policy.execute(context); //context is: the component is a leaf, and the viewInfo is not from MultiColView
Assert.assertEquals(result.getStatus(), true); //policy should return true for views that are not MultiCol views
//---end test on leaf-components
//(2) Test for non-leaf components:
Mockito.when(mockComp.isLeaf()).thenReturn(false); //mocked component is not a leaf
result = policy.execute(context); //context is: the component is a leaf, and the viewInfo is not from MultiColView
Assert.assertEquals(result.getStatus(), true); //policy should return true for views that are not MultiCol views
//---end test on non-leaf components
}