AssertInstanceOf Example

In this post under JUnit 5, I will show with example, the purpose and how to use “assertInstanceOf” method. The assertInstanceOf method from JUnit 5 can be used to verify whether an object is actually an instance of the specified class or not. If an object is actually an instance of passed in Class, then…… Continue reading AssertInstanceOf Example

AssertSame Example

In this post under JUnit, I will show with example the purpose of AssertSame assertion method. JUnit 5 has added new assertion method “assertSame” that checks for Object reference equality. How “assertSame” is different from “assertEquals” assertion method is that latter check for Object value equality whereas former checks for Object reference equality. Object value…… Continue reading AssertSame Example

AssertDoesNotThrow Example

In this post under JUnit, I will explain with example what is the purpose and how to use “AssertDoesNotThrow” assertion method. AssertDoesNotThrow takes an executable code and assert that the method doesn’t throw any exception during execution. Below is the javadoc of “assertDoesNotThrow” exception public static void assertDoesNotThrow​(Executable executable) Where “Executable” is a functional interface…… Continue reading AssertDoesNotThrow Example

assertTrue and assertFalse with Supplier Interface

In this post under JUnit 5, I will introduce you to a new overloaded version of “assertTrue” and “assertFalse” methods. In the earlier versions, we used to stored the result of a comparison in local variable of type boolean and when calling assertTrue or assertFalse, we used to pass that local variable as an argument…… Continue reading assertTrue and assertFalse with Supplier Interface