{"action":"closed","issue":{"url":"https://api.github.com/repos/nhaarman/mockito-kotlin/issues/255","repository_url":"https://api.github.com/repos/nhaarman/mockito-kotlin","labels_url":"https://api.github.com/repos/nhaarman/mockito-kotlin/issues/255/labels{/name}","comments_url":"https://api.github.com/repos/nhaarman/mockito-kotlin/issues/255/comments","events_url":"https://api.github.com/repos/nhaarman/mockito-kotlin/issues/255/events","html_url":"https://github.com/nhaarman/mockito-kotlin/issues/255","id":324541469,"node_id":"MDU6SXNzdWUzMjQ1NDE0Njk=","number":255,"title":"Getting a null pointer exception when invoking a method on a mock","user":{"login":"premnirmal","id":1255689,"node_id":"MDQ6VXNlcjEyNTU2ODk=","avatar_url":"https://avatars3.githubusercontent.com/u/1255689?v=4","gravatar_id":"","url":"https://api.github.com/users/premnirmal","html_url":"https://github.com/premnirmal","followers_url":"https://api.github.com/users/premnirmal/followers","following_url":"https://api.github.com/users/premnirmal/following{/other_user}","gists_url":"https://api.github.com/users/premnirmal/gists{/gist_id}","starred_url":"https://api.github.com/users/premnirmal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/premnirmal/subscriptions","organizations_url":"https://api.github.com/users/premnirmal/orgs","repos_url":"https://api.github.com/users/premnirmal/repos","events_url":"https://api.github.com/users/premnirmal/events{/privacy}","received_events_url":"https://api.github.com/users/premnirmal/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-05-18T20:25:57Z","updated_at":"2018-06-12T15:59:02Z","closed_at":"2018-06-12T15:59:02Z","author_association":"NONE","body":"I have a class:\r\n``` kotlin\r\nopen class Foo(private val bar: Bar) {\r\n  fun print(): String {\r\n    return bar.print()\r\n  }\r\n}\r\n```\r\n\r\nWhen I mock this class in java, I get a null pointer exception.\r\n\r\n``` java\r\nFoo foo = Mockito.mock(Foo.class);\r\nwhen(foo.print()).thenReturn(\"value\"); // Null pointer exception saying bar is null.\r\n```\r\n\r\n``` java\r\nFoo foo = Mockito.mock(Foo.class);\r\ndoReturn(\"value\").when(foo).print(); // Null pointer exception saying bar is null.\r\n```\r\n\r\n``` java\r\nFoo foo = Mockito.mock(Foo.class);\r\ndoReturn(\"value\").when(foo.print()); // Null pointer exception saying bar is null.\r\n```\r\n\r\nWith mockito-kotlin:\r\n\r\n``` kotlin\r\nfoo = mock<Foo>()\r\nwhenever(foo.print()).thenReturn(\"value\") // Null pointer exception saying bar is null.\r\n```\r\n\r\nHow do you get around this?"}}
{"actor":{"display_login":"premnirmal"}}