File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -61,4 +61,20 @@ public boolean equals(Object obj) {
6161 return true ;
6262 }
6363
64+ /**
65+ * Returns a string representation in the form <code>host:port</code>,
66+ * adding square brackets if needed
67+ */
68+ @ Override
69+ public String toString () {
70+ // "[]:12345" requires 8 extra bytes.
71+ StringBuilder builder = new StringBuilder (host .length () + 8 );
72+ if (host .indexOf (':' ) >= 0 ) {
73+ builder .append ('[' ).append (host ).append (']' );
74+ } else {
75+ builder .append (host );
76+ }
77+ builder .append (':' ).append (port );
78+ return builder .toString ();
79+ }
6480}
Original file line number Diff line number Diff line change 1+ package com .arangodb ;
2+
3+ import static org .hamcrest .CoreMatchers .is ;
4+ import static org .junit .Assert .assertThat ;
5+
6+ import org .junit .Test ;
7+
8+ /**
9+ * @author Anton Sarov - initial contribution
10+ *
11+ */
12+ public class ArangoHostTest {
13+
14+ @ Test
15+ public void testToString () {
16+ ArangoHost arangoHost = new ArangoHost ("127.0.0.1" , 8529 );
17+ assertThat (arangoHost .toString (), is ("127.0.0.1:8529" ));
18+ }
19+
20+ @ Test
21+ public void testToStringIPv6 () {
22+ ArangoHost arangoHost = new ArangoHost ("2001:db8:1f70::999:de8:7648:6e8" , 8529 );
23+ assertThat (arangoHost .toString (), is ("[2001:db8:1f70::999:de8:7648:6e8]:8529" ));
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments