
You will learn about detail features of an object-oriented programming like: data encapsulation, inheritance and polymorphism as we go on. It has braking, accelerating, changing gears etc.It has current gear, two wheels, number of gear etc.You can turn on and turn off lamp (behavior).In object-oriented style of programming, you can divide a complex problem into smaller sets by creating objects. This article will focus on object-oriented style of programming in Kotlin. You will learn about these concept in later chapters. Kotlin supports features such as higher-order functions, function types and lambdas which makes it a great choice for working in functional programming style.

If the library is reasonably popular, it is very likely that there is already a Kotlin alternative or companion library that will help you.Kotlin supports both functional and object-oriented programming. 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.
