1 /* 2 * Copyright (c) 2017 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockitousage.bugs; 6 7 import org.junit.Test; 8 import org.mockito.ArgumentMatcher; 9 import org.mockito.internal.matchers.EqualsWithDelta; 10 11 import static org.assertj.core.api.Assertions.assertThat; 12 13 public class EqualsWithDeltaTest { 14 15 @Test testEqualsWithDelta_NullExpected()16 public void testEqualsWithDelta_NullExpected() throws Exception { 17 ArgumentMatcher<Number> matcher = equalsWithDelta(null); 18 assertThat(matcher.matches(1.0)).isFalse(); 19 } 20 21 @Test testEqualsWithDelta_NullActual()22 public void testEqualsWithDelta_NullActual() throws Exception { 23 ArgumentMatcher<Number> matcher = equalsWithDelta(1.0); 24 assertThat(matcher.matches(null)).isFalse(); 25 } 26 27 @Test testEqualsWithDelta_NullActualAndExpected()28 public void testEqualsWithDelta_NullActualAndExpected() throws Exception { 29 ArgumentMatcher<Number> matcher = equalsWithDelta(null); 30 assertThat(matcher.matches(null)).isTrue(); 31 } 32 33 @Test testEqualsWithDelta_WhenActualAndExpectedAreTheSameObject()34 public void testEqualsWithDelta_WhenActualAndExpectedAreTheSameObject() throws Exception { 35 Double expected = 1.0; 36 Double actual = expected; 37 ArgumentMatcher<Number> matcher = equalsWithDelta(expected); 38 assertThat(matcher.matches(actual)).isTrue(); 39 } 40 equalsWithDelta(final Double expected)41 public ArgumentMatcher<Number> equalsWithDelta(final Double expected) { 42 return new EqualsWithDelta(expected, .000001); 43 } 44 } 45