Mockito doesn't like me

Discussion in 'Plugin Development' started by oaschi, May 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    oaschi

    I'm trying to do a unit test but mocking doesn't work as I want.

    Here's the method to be tested:
    Code:java
    1. public double distance(Player player) {
    2. return player.getLocation().distance(getLocation());
    3. }


    And here's the test:
    Code:java
    1. [USER=36465]test[/USER]
    2. public void testDistance() {
    3. World world = mock(World.class);
    4.  
    5. AbstractWarp warp = mock(AbstractWarp.class);
    6. Location loc = new Location(world, 0, 0, 0);
    7. when(warp.getLocation()).thenReturn(loc);
    8.  
    9.  
    10. Player player = mock(Player.class);
    11. Location loc2 = new Location(world, 100, 0, 0);
    12. when(player.getLocation()).thenReturn(loc2);
    13.  
    14. assertEquals(100, warp.distance(player), .1);
    15. }


    The assertion fails:
    java.lang.AssertionError: expected:<100.0> but was:<0.0>

    I know this is rather a general question than a bukkit question but I've made good experience on here.
    Any ideas?
     
  2. Offline

    Esophose

    oaschi
    Full error? It should tell what you line it is on in the error.
     
  3. Offline

    oaschi

    It's the assertion that fails, line 14.
     
  4. Offline

    TGRHavoc

    oaschi
    Change the ".1" to "100" at assertEquals(100, warp.distance(player), .1);
     
  5. Offline

    oaschi

    TGRHavoc
    Ah, thanks but that's not exactly what I wanted :D

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page