1414
1515package org .httprpc .xml ;
1616
17+ import org .httprpc .beans .BeanAdapter ;
1718import org .junit .jupiter .api .Test ;
1819import org .w3c .dom .Document ;
1920import org .xml .sax .SAXException ;
3031
3132public class ElementAdapterTest {
3233 @ Test
33- @ SuppressWarnings ("unchecked" )
3434 public void testElementAdapter () throws ParserConfigurationException , SAXException , IOException {
3535 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory .newInstance ();
3636
@@ -46,6 +46,12 @@ public void testElementAdapter() throws ParserConfigurationException, SAXExcepti
4646
4747 ElementAdapter elementAdapter = new ElementAdapter (document .getDocumentElement ());
4848
49+ testUntypedAccess (elementAdapter );
50+ testTypedAccess (elementAdapter );
51+ }
52+
53+ @ SuppressWarnings ("unchecked" )
54+ private void testUntypedAccess (ElementAdapter elementAdapter ) {
4955 assertEquals ("A" , elementAdapter .get ("@a" ));
5056
5157 Map <String , ?> map = (Map <String , ?>)elementAdapter .get ("map" );
@@ -75,7 +81,36 @@ public void testElementAdapter() throws ParserConfigurationException, SAXExcepti
7581
7682 assertEquals ("3" , item3 .get ("@d" ));
7783 assertEquals ("ghi" , item3 .toString ());
84+ }
85+
86+ private void testTypedAccess (ElementAdapter elementAdapter ) {
87+ TestInterface testInterface = BeanAdapter .adapt (elementAdapter , TestInterface .class );
88+
89+ assertEquals ("A" , testInterface .getA ());
90+
91+ TestInterface .MapInterface map = testInterface .getMap ();
92+
93+ assertEquals ("B" , map .getB1 ());
94+ assertEquals ("two" , map .getB2 ());
95+
96+ TestInterface .MapInterface .ListInterface list = map .getList ();
97+
98+ assertEquals ("C" , list .getC ());
99+
100+ List <String > stringItems = list .getStringItems ();
101+
102+ assertEquals (3 , stringItems .size ());
103+
104+ assertEquals ("abc" , stringItems .get (0 ));
105+ assertEquals ("déf" , stringItems .get (1 ));
106+ assertEquals ("ghi" , stringItems .get (2 ));
107+
108+ List <Map <String , ?>> mapItems = list .getMapItems ();
109+
110+ assertEquals (3 , mapItems .size ());
78111
79- // TODO Test interface binding
112+ assertEquals ("1" , mapItems .get (0 ).get ("@d" ));
113+ assertEquals ("2" , mapItems .get (1 ).get ("@d" ));
114+ assertEquals ("3" , mapItems .get (2 ).get ("@d" ));
80115 }
81116}
0 commit comments