How to write JUnit test code in Java to test the Substrings of a give String?

This is the JUnit 5 solution to cover all kinds of inputs and outputs of the Substrings of given String. This Unit test executes tests for the ‘ParseTheWord’ function available in the class ‘SubstrsJ8’.

package pack1;

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 SubstrsJ8Junit5 {
	
		Substrs_Using_String SubUStr;
		Substrs_WithoutUsing_SubstringMethod SubUStrWithout;
		Substrs_Using_Lambda SubUStrUL;

	@BeforeEach
	void setUp() throws Exception {
		 SubUStr = new Substrs_Using_String();
		 SubUStrWithout = new Substrs_WithoutUsing_SubstringMethod();
		 SubUStrUL = new Substrs_Using_Lambda();
	}

	@Test
	@DisplayName("Positive inputs - Exp value and Actual matches")
	void test() {
		Assertions.assertEquals("[AVE, A, DAVE, D, E, AV, V, DAV, DA, VE]",SubUStr.ParseTheWord("DAVE").toString());
		Assertions.assertEquals("[JOH, OHN, JO, HN, H, OH, JOHN, J, N, O]",SubUStrWithout.ParseTheWord("JOHN").toString());
		Assertions.assertEquals("[IK, IKE, MIKE, E, I, KE, K, MI, M, MIK]",SubUStrUL.ParseTheWord("MIKE").toString());
	}

	@Test
	@DisplayName("Negative inputs  - Exp value and Actual does not matches")
	void test2() {
		Assertions.assertNotEquals("[AV, V, DAV, DA, VE]",SubUStr.ParseTheWord("DAVE").toString());
		Assertions.assertNotEquals("[JOH, OHN, , N, O]",SubUStrWithout.ParseTheWord("JOHN").toString());
		Assertions.assertNotEquals("[IK, IKE, MIKE, E]",SubUStrUL.ParseTheWord("MIKE").toString());
	}
	
	@Test
	@DisplayName("Null inputs")
	void test3() {
		Assertions.assertEquals("[]", SubUStr.ParseTheWord(null).toString());
		Assertions.assertEquals("[]", SubUStrWithout.ParseTheWord(null).toString());
		Assertions.assertEquals("[]", SubUStrUL.ParseTheWord(null).toString());
	}
	
	@Test
	@DisplayName("Empty inputs")
	void test4() {
		Assertions.assertEquals("[]", SubUStr.ParseTheWord("").toString());
		Assertions.assertEquals("[]", SubUStrWithout.ParseTheWord("").toString());
		Assertions.assertEquals("[]", SubUStrUL.ParseTheWord("").toString());
	}
	
	@Test
	@DisplayName("Alphanumeric inputs - Exp value and Actual matches")
	void test5() {
		Assertions.assertEquals("[*J, %, *, J, K, K%3*J, %3, 3, 3*J, K%3*, 3*, K%3, K%, %3*, %3*J]",SubUStr.ParseTheWord("K%3*J").toString());
		Assertions.assertEquals("[89, 89#, !)sw, 89#!, 89#!), 9#, 89#!)s, #!), !)s, )sw, 89#!)sw, #!)sw, 9#!, 9#!)sw, #!)s, #!, !, #, sw, !), 9#!), ), )s, 9#!)s, s, w, 8, 9]",SubUStrWithout.ParseTheWord("89#!)sw").toString());
		Assertions.assertEquals("[@, Gy4, 48, &, G, @G, &@G, &@Gy48, @Gy48, Gy, @Gy, 4, Gy48, 8, y, &@, y4, y48, @Gy4, &@Gy4, &@Gy]",SubUStrUL.ParseTheWord("&@Gy48").toString());
	}
}
Output:
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_String ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_String'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=DAVE are below
[AVE, A, DAVE, D, E, AV, V, DAV, DA, VE]
Jun 11, 2023 3:51:43 PM pack1.Substrs_WithoutUsing_SubstringMethod ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_WithoutUsing_SubstringMethod'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=JOHN are below
[JOH, OHN, JO, HN, H, OH, JOHN, J, N, O]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_Lambda ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_Lambda'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=MIKE are below
[IK, IKE, MIKE, E, I, KE, K, MI, M, MIK]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_String ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_String'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=DAVE are below
[AVE, A, DAVE, D, E, AV, V, DAV, DA, VE]
Jun 11, 2023 3:51:43 PM pack1.Substrs_WithoutUsing_SubstringMethod ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_WithoutUsing_SubstringMethod'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=JOHN are below
[JOH, OHN, JO, HN, H, OH, JOHN, J, N, O]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_Lambda ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_Lambda'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=MIKE are below
[IK, IKE, MIKE, E, I, KE, K, MI, M, MIK]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_String ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_String'
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_String ParseTheWord
INFO: The given Input String is null
All the unique substrings from the given String=null are below
[]
Jun 11, 2023 3:51:43 PM pack1.Substrs_WithoutUsing_SubstringMethod ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_WithoutUsing_SubstringMethod'
Jun 11, 2023 3:51:43 PM pack1.Substrs_WithoutUsing_SubstringMethod ParseTheWord
INFO: The given Input String is null
All the unique substrings from the given String=null are below
[]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_Lambda ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_Lambda'
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_Lambda ParseTheWord
INFO: The given Input String is null
All the unique substrings from the given String=null are below
[]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_String ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_String'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String= are below
[]
Jun 11, 2023 3:51:43 PM pack1.Substrs_WithoutUsing_SubstringMethod ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_WithoutUsing_SubstringMethod'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String= are below
[]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_Lambda ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_Lambda'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String= are below
[]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_String ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_String'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=K%3*J are below
[*J, %, *, J, K, K%3*J, %3, 3, 3*J, K%3*, 3*, K%3, K%, %3*, %3*J]
Jun 11, 2023 3:51:43 PM pack1.Substrs_WithoutUsing_SubstringMethod ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_WithoutUsing_SubstringMethod'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=89#!)sw are below
[89, 89#, !)sw, 89#!, 89#!), 9#, 89#!)s, #!), !)s, )sw, 89#!)sw, #!)sw, 9#!, 9#!)sw, #!)s, #!, !, #, sw, !), 9#!), ), )s, 9#!)s, s, w, 8, 9]
Jun 11, 2023 3:51:43 PM pack1.Substrs_Using_Lambda ParseTheWord
INFO: This method 'ParseTheWord' called from the Class 'pack1.SubstrsJ8Junit5'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.Substrs_Using_Lambda'
Jun 11, 2023 3:51:43 PM pack1.StringInput validateInputs
INFO: The provided Input validated Successfully
All the unique substrings from the given String=&@Gy48 are below
[@, Gy4, 48, &, G, @G, &@G, &@Gy48, @Gy48, Gy, @Gy, 4, Gy48, 8, y, &@, y4, y48, @Gy4, &@Gy4, &@Gy]