rahmandon / mockito

Automatically exported from code.google.com/p/mockito
1 stars 0 forks source link

EqualsWithDelta not null safe #335

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem? See test below.

What is the expected output? What do you see instead?
I would expect null checks and comparison in the matches method. If wanted is 
null and actual is not, return false. If actual is null and wanted is not, 
return false. If wanted and actual are null, return true. I am aware of the 
nullValue matcher, but sometimes the wanted value may be null and not known 
until runtime, or a common method is used for asserting objects where 
properties in the objects may or may not be null.

What version of the product are you using? On what operating system?
1.9.0

Please provide any additional information below.

public class EqualsWithDeltaTest {

    @Test
    public void testEqualsWithDelta_NullExpected() throws Exception {
        Matcher<Number> matcher = equalsWithDelta(null);
        assertThat(matcher.matches(1.0), is(false)); // throws NPE
    }

    @Test
    public void testEqualsWithDelta_NullActual() throws Exception {
        Matcher<Number> matcher = equalsWithDelta(1.0);
        assertThat(matcher.matches(null), is(false)); // throws NPE
    }

    public Matcher<Number> equalsWithDelta(final Double expected) {
        return new EqualsWithDelta(expected, .000001);
    }
}

Original issue reported on code.google.com by jus...@wesleyhome.com on 23 Apr 2012 at 3:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 20 Jul 2012 at 10:34

GoogleCodeExporter commented 9 years ago
Issue 341 has been merged into this issue.

Original comment by brice.du...@gmail.com on 20 Jul 2012 at 10:42

GoogleCodeExporter commented 9 years ago
Hi Brice,
I pushed a fix on my repo. You can see it here:
http://code.google.com/r/ludochane-mockito/source/list

Ludovic

Original comment by ludoch...@gmail.com on 21 Jul 2012 at 8:06

GoogleCodeExporter commented 9 years ago
Fixed in rev e2201641e6fa77901c7dd6ab41257628f8899e50
Thx Ludovic

Original comment by brice.du...@gmail.com on 21 Jul 2012 at 9:27

GoogleCodeExporter commented 9 years ago
revision e2201641e6fa77901c7dd6ab41257628f8899e50

Original comment by brice.du...@gmail.com on 21 Jul 2012 at 9:27

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 16 Aug 2014 at 2:43

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 24 Aug 2014 at 3:14

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 24 Aug 2014 at 3:50