Skip to content

Commit dba1668

Browse files
committed
Add tests to test the equals & hashCode of Proxy.
1 parent b7e0d36 commit dba1668

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

webmagic-core/src/test/java/us/codecraft/webmagic/proxy/ProxyTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
import java.util.List;
99

1010
import org.apache.http.HttpHost;
11-
import org.junit.BeforeClass;
12-
import org.junit.Test;
11+
import org.junit.jupiter.api.BeforeAll;
12+
import org.junit.jupiter.api.Test;
1313

1414
/**
1515
* @author yxssfxwzy@sina.com May 30, 2014
16-
*
16+
*
1717
*/
1818
public class ProxyTest {
1919

2020
private static List<String[]> httpProxyList = new ArrayList<String[]>();
2121

22-
@BeforeClass
22+
@BeforeAll
2323
public static void before() {
2424
// String[] source = { "0.0.0.1:0", "0.0.0.2:0", "0.0.0.3:0",
2525
// "0.0.0.4:0" };
@@ -48,7 +48,7 @@ public void run() {
4848
}
4949

5050
@Test
51-
public void testCreate() {
51+
void testCreate() {
5252
Proxy proxy = Proxy.create(URI.create("//127.0.0.1:8080"));
5353
assertNull(proxy.getScheme());
5454
assertNull(proxy.getUsername());
@@ -86,7 +86,15 @@ public void testCreate() {
8686
}
8787

8888
@Test
89-
public void testToString() {
89+
void testEqualsHashCode() {
90+
var proxy0 = new Proxy("::1", 1080);
91+
var proxy1 = new Proxy("::1", 1080);
92+
assertEquals(proxy0, proxy1);
93+
assertEquals(proxy0.hashCode(), proxy1.hashCode());
94+
}
95+
96+
@Test
97+
void testToString() {
9098
assertEquals("//127.0.0.1:8080", new Proxy("127.0.0.1", 8080).toString());
9199
assertEquals("http://127.0.0.1:8080", new Proxy("127.0.0.1", 8080, "http").toString());
92100
assertEquals("//username:password@127.0.0.1:8080", new Proxy("127.0.0.1", 8080, "username", "password").toString());

0 commit comments

Comments
 (0)