How to write JUnit test code in Java for the Sum Of Digits in an Alphanumeric function ?

This is the JUnit 5 solution to cover all kinds of inputs provided to find the duplicate words function. This Unit test executes tests for the ‘ParseAlphanumeric’ function available in the class ‘SumofDgtsInAlphanumericJ8’.

package pack1;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class JunitTestSumofDgtsInAlphanumericJ8 {
	
	SumDgtsInAlphanumeric_Using_String SDUStr;
	SumDgtsInAlphanumeric_Using_Lamdba SDULambda;
	SumDgtsInAlphanumeric_Using_Stream SDUStream;
	
	@BeforeEach
	void setUp() throws Exception {
		
		SDUStr = new SumDgtsInAlphanumeric_Using_String();
		SDULambda = new SumDgtsInAlphanumeric_Using_Lamdba();
		SDUStream = new SumDgtsInAlphanumeric_Using_Stream();
	}
	@AfterEach
	void tearDown() throws Exception {
	}
	
	@Test
	@DisplayName("Positive Inputs")
	void test1() {
		Assertions.assertEquals(15.0, SDUStr.ParseAlphanumeric("Java25Python35Yaers"));
		Assertions.assertEquals(16.0, SDULambda.ParseAlphanumeric("Tomcat35Jboss20Weblogic15Years"));
		Assertions.assertEquals(0.0, SDUStream.ParseAlphanumeric(""));
	}
	
	@Test
	@DisplayName("Negative Inputs")
	void test2() {
		Assertions.assertNotEquals(52.0, SDUStr.ParseAlphanumeric("C50C++35Years"));
		Assertions.assertNotEquals(36.0, SDULambda.ParseAlphanumeric("Lisp35Prolog20Fortran55Years"));
		Assertions.assertNotEquals(10.0, SDUStream.ParseAlphanumeric(""));
	}
	
	@Test
	@DisplayName("Empty Inputs")
	void test3() {
		Assertions.assertEquals(0.0, SDUStr.ParseAlphanumeric(""));
		Assertions.assertEquals(0.0, SDULambda.ParseAlphanumeric(""));
		Assertions.assertEquals(0.0, SDUStream.ParseAlphanumeric(""));
	}
	
	@Test
	@DisplayName("null Inputs")
	void test4() {
		Assertions.assertEquals(0.0, SDUStr.ParseAlphanumeric(null));
		Assertions.assertEquals(0.0, SDULambda.ParseAlphanumeric(null));
		Assertions.assertEquals(0.0, SDUStream.ParseAlphanumeric(null));
	}
	
	@Test
	@DisplayName("Positive Inputs - with No Digits")
	void test5() {
		Assertions.assertEquals(0.0, SDUStr.ParseAlphanumeric("No Digits here"));
		Assertions.assertEquals(0.0, SDULambda.ParseAlphanumeric("J&r@$(E"));
		Assertions.assertEquals(0.0, SDUStream.ParseAlphanumeric("W@!yp*#x"));
	}
}
Output:
Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_String ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_String'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input alphaNumeric value is = 'Java25Python35Yaers'
The sum of digits in the given string 'Java25Python35Yaers' is 15.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Lamdba ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Lamdba'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input sentence is = 'Tomcat35Jboss20Weblogic15Years'
The sum of digits in the given string 'Tomcat35Jboss20Weblogic15Years' is 16.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Stream ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Stream'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given Alphanumeric is = ''
The list of Characters are= []
The sum of digits in the given string '' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_String ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_String'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input alphaNumeric value is = 'C50C++35Years'
The sum of digits in the given string 'C50C++35Years' is 13.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Lamdba ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Lamdba'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input sentence is = 'Lisp35Prolog20Fortran55Years'
The sum of digits in the given string 'Lisp35Prolog20Fortran55Years' is 20.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Stream ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Stream'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given Alphanumeric is = ''
The list of Characters are= []
The sum of digits in the given string '' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_String ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_String'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input alphaNumeric value is = ''
The sum of digits in the given string '' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Lamdba ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Lamdba'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input sentence is = ''
The sum of digits in the given string '' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Stream ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Stream'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given Alphanumeric is = ''
The list of Characters are= []
The sum of digits in the given string '' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_String ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_String'
Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_String ParseAlphanumeric
INFO: The given Input Alphanumeric is null
The sum of digits in the given string 'null' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Lamdba ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Lamdba'
Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Lamdba ParseAlphanumeric
INFO: The given Input Alphanumeric is null
The sum of digits in the given string 'null' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Stream ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Stream'
Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Stream ParseAlphanumeric
INFO: The given Input Alphanumeric is null
The sum of digits in the given string 'null' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_String ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_String'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input alphaNumeric value is = 'No Digits here'
The sum of digits in the given string 'No Digits here' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Lamdba ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Lamdba'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given input sentence is = 'J&r@$(E'
The sum of digits in the given string 'J&r@$(E' is 0.0


Jan 27, 2023 3:39:04 PM pack1.SumDgtsInAlphanumeric_Using_Stream ParseAlphanumeric
INFO: This method 'ParseAlphanumeric' called from the Class 'pack1.JunitTestSumofDgtsInAlphanumericJ8'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.SumDgtsInAlphanumeric_Using_Stream'
Jan 27, 2023 3:39:04 PM pack1.InputAlphanumeric validateInputs
INFO: The provided Input validated Successfully
The given Alphanumeric is = 'W@!yp*#x'
The list of Characters are= [W, @, !, y, p, *, #, x]
The sum of digits in the given string 'W@!yp*#x' is 0.0