• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.mockitousage.bugs;
2 
3 import org.junit.Test;
4 import org.mockito.ArgumentMatcher;
5 import org.mockito.internal.matchers.EqualsWithDelta;
6 
7 import static org.assertj.core.api.Assertions.assertThat;
8 
9 public class EqualsWithDeltaTest {
10 
11     @Test
testEqualsWithDelta_NullExpected()12     public void testEqualsWithDelta_NullExpected() throws Exception {
13         ArgumentMatcher<Number> matcher = equalsWithDelta(null);
14         assertThat(matcher.matches(1.0)).isFalse();
15     }
16 
17     @Test
testEqualsWithDelta_NullActual()18     public void testEqualsWithDelta_NullActual() throws Exception {
19         ArgumentMatcher<Number> matcher = equalsWithDelta(1.0);
20         assertThat(matcher.matches(null)).isFalse();
21     }
22 
23     @Test
testEqualsWithDelta_NullActualAndExpected()24     public void testEqualsWithDelta_NullActualAndExpected() throws Exception {
25         ArgumentMatcher<Number> matcher = equalsWithDelta(null);
26         assertThat(matcher.matches(null)).isTrue();
27     }
28 
29     @Test
testEqualsWithDelta_WhenActualAndExpectedAreTheSameObject()30     public void testEqualsWithDelta_WhenActualAndExpectedAreTheSameObject() throws Exception {
31         Double expected = 1.0;
32         Double actual = expected;
33         ArgumentMatcher<Number> matcher = equalsWithDelta(expected);
34         assertThat(matcher.matches(actual)).isTrue();
35     }
36 
equalsWithDelta(final Double expected)37     public ArgumentMatcher<Number> equalsWithDelta(final Double expected) {
38         return new EqualsWithDelta(expected, .000001);
39     }
40 }
41