Kotlin not null12/20/2023 I have been working with Kotlin for quite a bit, and learned about functional programming with Kotlin and tons of other benefits of this programming language, specially if you compare it with Java.īut, a few days ago I found something that could lead to some major problems when working with Kotlin and Spring Boot or Micronaut. Since I knew about this language it became my favorite programming language. If the library is reasonably popular, it is very likely that there is already a Kotlin alternative or companion library that will help you.I love Kotlin. However, you are probably not the first to have this happen. Java libraries can sometimes cause problems in Kotlin. The individual commits show the original code with the failed test, the fix with the alternate matcher, and the final mock setup in Kotlin syntax. You can check the full code in my GitHub repository. In order for this code to compile, you need to add the following imports: import org. The method I was trying to stub was expecting a non-null String as an argument: interface MyDependency doReturn "Hello, World!" The cause was the any() argument matcher in my code to set up the method stub: val myDependencyMock = Mockito. When I ran the test, it failed with a NullPointerException: I recently ran into such a problem when trying to mock a dependency with Mockito. Unfortunately, it can sometimes cause problems when interacting with Java code or libraries. The null safety feature in Kotlin is great for preventing NullPointerExceptions that are thrown at runtime.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |