michael-o commented on a change in pull request #147: Time values
URL: 
https://github.com/apache/httpcomponents-core/pull/147#discussion_r322014100
 
 

 ##########
 File path: httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
 ##########
 @@ -262,4 +263,43 @@ public void testFromString() throws ParseException {
         Assert.assertEquals(TimeValue.ofMilliseconds(1), TimeValue.parse("1 
MILLISECOND"));
     }
 
+    @Test
+    public void testEqualsAndHashCode() throws ParseException {
+        final TimeValue tv1 = TimeValue.ofMilliseconds(1000L);
+        final TimeValue tv2 = TimeValue.ofMilliseconds(1001L);
+        final TimeValue tv3 = TimeValue.ofMilliseconds(1000L);
+        final TimeValue tv4 = TimeValue.ofSeconds(1L);
+        final TimeValue tv5 = TimeValue.ofSeconds(1000L);
+
+        Assert.assertThat(tv1.equals(tv1), CoreMatchers.equalTo(true));
+        Assert.assertThat(tv1.equals(null), CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.equals(tv2), CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.equals(tv3), CoreMatchers.equalTo(true));
+        Assert.assertThat(tv1.equals(tv4), CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.equals(tv5), CoreMatchers.equalTo(false));
+
+        Assert.assertThat(tv1.hashCode() == tv2.hashCode(), 
CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.hashCode() == tv3.hashCode(), 
CoreMatchers.equalTo(true));
+        Assert.assertThat(tv1.hashCode() == tv4.hashCode(), 
CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.hashCode() == tv5.hashCode(), 
CoreMatchers.equalTo(false));
+    }
+
+    @Test
+    public void testCompareTo() throws ParseException {
+        final TimeValue tv1 = TimeValue.ofMilliseconds(1000L);
+        final TimeValue tv2 = TimeValue.ofMilliseconds(1001L);
+        final TimeValue tv3 = TimeValue.ofMilliseconds(1000L);
+        final TimeValue tv4 = TimeValue.ofSeconds(1L);
+        final TimeValue tv5 = TimeValue.ofSeconds(60L);
+        final TimeValue tv6 = TimeValue.ofMinutes(1L);
+
+        Assert.assertThat(tv1.compareTo(tv1) == 0, CoreMatchers.equalTo(true));
 
 Review comment:
   I think the documented NPE should be tested as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to