PhysicalResourceLoader { private List<Attribute> buildPortAttributes(JsonNode attributes) { List<Attribute> attributeList = new ArrayList<Attribute>(); for (int i = 0; i < attributes.size(); i++) { log.debug("build physical port attribute execution body."); JsonNode portAttribute = attributes.get(i); Attribute attribute = buildPortAttribute(portAttribute); if (attribute != null) { attributeList.add(attribute); } } return attributeList; } PhysicalResourceLoader(DataBroker dataBroker); void close(); final static String NODE_PROPERTY; final static String LINK_PROPERTY; final static String EXTERNAL_NETWORK_PROPERTY; final static String HOST_PROPERTY; }
@Test public void testBuildPortAttributes()throws Exception{ Class<PhysicalResourceLoader>class1 = PhysicalResourceLoader.class; Method method = class1.getDeclaredMethod("buildPortAttributes",new Class[]{JsonNode.class}); method.setAccessible(true); List<Attribute> attributeList; JsonNode attributes = mock(JsonNode.class); JsonNode portAttribute = mock(JsonNode.class); JsonNode jsonNode_temp = mock(JsonNode.class); when(attributes.size()).thenReturn(1); when(attributes.get(any(Integer.class))).thenReturn(portAttribute); when(portAttribute.path(any(String.class))).thenReturn(jsonNode_temp); when(jsonNode_temp.asText()) .thenReturn(new String("")) .thenReturn(new String("zm")); attributeList = (List<Attribute>)method.invoke(physicalResourceLoader,attributes); Assert.assertTrue(attributeList.size() == 0); attributeList = (List<Attribute>)method.invoke(physicalResourceLoader,attributes); Assert.assertTrue(attributeList.size() == 1); verify(portAttribute,times(3)).path(any(String.class)); verify(jsonNode_temp,times(3)).asText(); }