Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public void setPort(int port) {

@Override
public String toString() {
return "Endpoint{" + "protocol=" + protocol + ", host='" + host + ", port=" + port + '}';
return "Endpoint{" + "protocol=" + protocol + ", host='" + host + '\'' + ", port=" + port + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.alibaba.csp.sentinel.transport.endpoint;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class EndpointTest {
@Test
public void testToStringIPv4() {
Endpoint e = new Endpoint(Protocol.HTTP, "127.0.0.1", 8080);
assertEquals("Endpoint{protocol=HTTP, host='127.0.0.1', port=8080}", e.toString());
}

@Test
public void testToStringIPv6() {
Endpoint e = new Endpoint(Protocol.HTTP, "fe80::1", 8080);
// Endpoint#toString doesn't modify the host, so IPv6 remains unbracketed
assertEquals("Endpoint{protocol=HTTP, host='fe80::1', port=8080}", e.toString());
}

@Test
public void testToStringAlreadyBracketed() {
Endpoint e = new Endpoint(Protocol.HTTPS, "[fe80::2]", 443);
assertEquals("Endpoint{protocol=HTTPS, host='[fe80::2]', port=443}", e.toString());
}

@Test
public void testToStringNullHost() {
Endpoint e = new Endpoint(Protocol.HTTP, null, 0);
assertEquals("Endpoint{protocol=HTTP, host='null', port=0}", e.toString());
}
}
Loading