@SuppressWarnings({ "unchecked" })
@Test
public void createResourceWithType() throws Exception {
//tell the method story as it happens: mock or create dependencies and configure
//those dependencies to get the method under test to completion.
CreateResourceReport mockReport = mock(CreateResourceReport.class);
Configuration mockConfiguration = mock(Configuration.class);
when(mockReport.getResourceConfiguration()).thenReturn(mockConfiguration);
PropertySimple typePropertySimple = new PropertySimple("__type", "xyz");
when(mockConfiguration.get(eq("__type"))).thenReturn(typePropertySimple);
ResourceType mockResourceType = mock(ResourceType.class);
when(mockReport.getResourceType()).thenReturn(mockResourceType);
ConfigurationDefinition mockConfigurationDefinition = mock(ConfigurationDefinition.class);
when(mockResourceType.getResourceConfigurationDefinition()).thenReturn(mockConfigurationDefinition);
Map<String, PropertyDefinition> mockMap = (Map<String, PropertyDefinition>) mock(Map.class);
when(mockConfigurationDefinition.getPropertyDefinitions()).thenReturn(mockMap);
CreateResourceDelegate mockCreateResourceDelegate = mock(CreateResourceDelegate.class);
PowerMockito.whenNew(CreateResourceDelegate.class)
.withParameterTypes(ConfigurationDefinition.class, ASConnection.class, Address.class)
.withArguments(any(ConfigurationDefinition.class), any(ASConnection.class), any(Address.class))
.thenReturn(mockCreateResourceDelegate);
when(mockReport.getResourceConfiguration()).thenReturn(mockConfiguration);
when(mockReport.getPluginConfiguration()).thenReturn(mockConfiguration);
PropertySimple pathPropertySimple = new PropertySimple("path", "xyz");
PowerMockito.whenNew(PropertySimple.class).withParameterTypes(String.class, Object.class)
.withArguments(eq("path"), eq("xyz")).thenReturn(pathPropertySimple);
when(mockCreateResourceDelegate.createResource(eq(mockReport))).thenReturn(mockReport);
ASConnection mockASConnection = mock(ASConnection.class);
//create object to test and inject required dependencies
TemplatedSubResourcesComponent objectUnderTest = new TemplatedSubResourcesComponent();
objectUnderTest.testConnection = mockASConnection;
//run code under test
CreateResourceReport result = objectUnderTest.createResource(mockReport);
//verify the results (Assert and mock verification)
Assert.assertEquals(result, mockReport);
verify(mockMap, times(1)).remove(eq("__type"));