### Question:
AttributesUtil { public static String getAttributesXml( Map<String, Map<String, String>> attributesMap ) { return getAttributesXml( attributesMap, XML_TAG ); }  static String getAttributesXml( Map<String, Map<String, String>> attributesMap ); static String getAttributesXml( Map<String, Map<String, String>> attributesMap, String xmlTag ); static Map<String, Map<String, String>> loadAttributes( Node attributesNode ); static final String XML_TAG; static final String XML_TAG_GROUP; static final String XML_TAG_ATTRIBUTE; }### Answer:
@Test public void testGetAttributesXml_DefaultTag() { PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ) ) ).thenCallRealMethod(); PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ), anyString() ) ).thenCallRealMethod(); Map<String, String> attributesGroup = new HashMap<>(); Map<String, Map<String, String>> attributesMap = new HashMap<>(); attributesGroup.put( A_KEY, A_VALUE ); attributesMap.put( A_GROUP, attributesGroup ); String attributesXml = AttributesUtil.getAttributesXml( attributesMap ); assertNotNull( attributesXml ); assertTrue( attributesXml.contains( AttributesUtil.XML_TAG ) ); assertTrue( attributesXml.contains( A_GROUP ) ); assertTrue( attributesXml.contains( A_KEY ) ); assertTrue( attributesXml.contains( A_VALUE ) ); PowerMockito.verifyStatic( AttributesUtil.class ); AttributesUtil.getAttributesXml( attributesMap, AttributesUtil.XML_TAG ); }
@Test public void testGetAttributesXml_CustomTag() { PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ), anyString() ) ).thenCallRealMethod(); Map<String, String> attributesGroup = new HashMap<>(); Map<String, Map<String, String>> attributesMap = new HashMap<>(); attributesGroup.put( A_KEY, A_VALUE ); attributesMap.put( A_GROUP, attributesGroup ); String attributesXml = AttributesUtil.getAttributesXml( attributesMap, CUSTOM_TAG ); assertNotNull( attributesXml ); assertTrue( attributesXml.contains( CUSTOM_TAG ) ); assertTrue( attributesXml.contains( A_GROUP ) ); assertTrue( attributesXml.contains( A_KEY ) ); assertTrue( attributesXml.contains( A_VALUE ) ); }
@Test public void testGetAttributesXml_DefaultTag_NullParameter() { PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ) ) ).thenCallRealMethod(); PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ), anyString() ) ).thenCallRealMethod(); String attributesXml = AttributesUtil.getAttributesXml( null ); assertNotNull( attributesXml ); assertTrue( attributesXml.contains( AttributesUtil.XML_TAG ) ); }
@Test public void testGetAttributesXml_CustomTag_NullParameter() { PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ), anyString() ) ).thenCallRealMethod(); String attributesXml = AttributesUtil.getAttributesXml( null, CUSTOM_TAG ); assertNotNull( attributesXml ); assertTrue( attributesXml.contains( CUSTOM_TAG ) ); }
@Test public void testGetAttributesXml_DefaultTag_EmptyMap() { PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ) ) ).thenCallRealMethod(); PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ), anyString() ) ).thenCallRealMethod(); Map<String, Map<String, String>> attributesMap = new HashMap<>(); String attributesXml = AttributesUtil.getAttributesXml( attributesMap ); assertNotNull( attributesXml ); assertTrue( attributesXml.contains( AttributesUtil.XML_TAG ) ); }
@Test public void testGetAttributesXml_CustomTag_EmptyMap() { PowerMockito.when( AttributesUtil.getAttributesXml( any( Map.class ), anyString() ) ).thenCallRealMethod(); Map<String, Map<String, String>> attributesMap = new HashMap<>(); String attributesXml = AttributesUtil.getAttributesXml( attributesMap, CUSTOM_TAG ); assertNotNull( attributesXml ); assertTrue( attributesXml.contains( CUSTOM_TAG ) ); }