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

Assertions using Supplier interface

In this post under JUnit 5, I will show with example, the new version of assert method which takes a Supplier interface implementation as an argument. In previous versions of JUnit, we have seen variety of assert methods, which takes the below arguments.1) The expected value (optional)2) The actual value (required)3) String message when the…… Continue reading Assertions using Supplier interface