From 0a1fb190526283e70963d4433780b626808eee0c Mon Sep 17 00:00:00 2001 From: "yihua.huang" Date: Sat, 11 Mar 2017 10:56:31 +0800 Subject: [PATCH] add tests #483 --- .../us/codecraft/webmagic/RequestTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 webmagic-core/src/test/java/us/codecraft/webmagic/RequestTest.java diff --git a/webmagic-core/src/test/java/us/codecraft/webmagic/RequestTest.java b/webmagic-core/src/test/java/us/codecraft/webmagic/RequestTest.java new file mode 100644 index 0000000..c7e4943 --- /dev/null +++ b/webmagic-core/src/test/java/us/codecraft/webmagic/RequestTest.java @@ -0,0 +1,25 @@ +package us.codecraft.webmagic; + +import org.junit.Test; +import us.codecraft.webmagic.utils.HttpConstant; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author code4crafter@gmail.com + * Date: 17/3/11 + */ +public class RequestTest { + + @Test + public void testEqualsAndHashCode() throws Exception { + Request requestA = new Request("http://www.google.com/"); + Request requestB = new Request("http://www.google.com/"); + assertThat(requestA.hashCode()).isEqualTo(requestB.hashCode()); + assertThat(requestA).isEqualTo(requestB); + requestA.setMethod(HttpConstant.Method.GET); + requestA.setMethod(HttpConstant.Method.POST); + assertThat(requestA).isNotEqualTo(requestB); + assertThat(requestA.hashCode()).isNotEqualTo(requestB.hashCode()); + } +}