Using assertNull() and assertNotNull() methods together
This lesson demonstrates how to use assertNull() and assertNotNull() methods together in JUnit 5 to assert test conditions.
We'll cover the following...
Demo
Step 1 - Create a Java class in Eclipse as discussed in previous lessons.
Step 2 - Give it a name as, StringUtils.`
package com.hubberspot.junit5.assertions;public class StringUtils {public static String reverse(String input) {if(input == null) {return null;}if(input.length() == 0) {return "";}char[] charArray = input.toCharArray();int start = 0;int end = input.length() - 1;while(start < end) {char temp = charArray[start];charArray[start] = charArray[end];charArray[end] = temp;start++;end--;}return new String(charArray);}}
Class Under Test - StringUtils
StringUtils is our class under test. It has one method as, reverse()
. This method takes in a String and returns reverse of it.
For example -
-
If we provide input String as, “ABCD”, it returns back “DCBA”.
-
If we provide input String as, “Student”, it returns back “tnedutS”. ...
Access this course and 1400+ top-rated courses and projects.