1414import static org .junit .Assert .assertEquals ;
1515import static org .junit .Assert .assertFalse ;
1616import static org .junit .Assert .assertNotNull ;
17+ import static org .junit .Assert .assertNull ;
1718import static org .junit .Assert .assertSame ;
1819import static org .junit .Assert .assertTrue ;
1920
21+ import java .net .InetSocketAddress ;
2022import com .google .common .collect .ImmutableMap ;
2123import com .tencent .trpc .core .common .Constants ;
2224import org .junit .Test ;
@@ -129,4 +131,43 @@ public void testConfig() {
129131 assertTrue (config .isSetDefault ());
130132 assertSame (serviceConfig , config .getServiceConfig ());
131133 }
134+
135+ @ Test
136+ public void testSocketAddress () {
137+ ProtocolConfig config = new ProtocolConfig ();
138+ config .setIp ("127.0.0.1" );
139+ config .setPort (8080 );
140+ config .setDefault ();
141+ InetSocketAddress socketAddress = config .toInetSocketAddress ();
142+ assertNotNull (socketAddress );
143+ assertEquals ("127.0.0.1" , socketAddress .getHostString ());
144+ assertEquals (8080 , socketAddress .getPort ());
145+ }
146+
147+ @ Test
148+ public void testSocketAddressNull () {
149+ ProtocolConfig config = new ProtocolConfig ();
150+ config .setIp ("192.168.1.1" );
151+ config .setPort (9090 );
152+ InetSocketAddress addr = config .toInetSocketAddress ();
153+ assertNotNull (addr );
154+ assertEquals ("192.168.1.1" , addr .getHostString ());
155+ assertEquals (9090 , addr .getPort ());
156+ }
157+
158+ @ Test
159+ public void testIpBlank () {
160+ ProtocolConfig config = new ProtocolConfig ();
161+ assertNull (config .toInetSocketAddress ());
162+ }
163+
164+ @ Test
165+ public void testToString () {
166+ ProtocolConfig config = new ProtocolConfig ();
167+ config .setIp ("127.0.0.1" );
168+ config .setPort (8080 );
169+ config .setDefault ();
170+ String str = config .toString ();
171+ assertTrue (str .contains ("socketAddress=" ));
172+ }
132173}
0 commit comments