How to write JUnit test code in Java for the function finding Frequency of the numbers from given array of Integers ?

This is the JUnit 5 solution to cover all kinds of inputs and outputs to find the Frequency of the numbers from an array of integers. This Unit test executes tests for the ‘RdInputArray’ function available in the class ‘FrequencyNumsJ8’.

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 JUnitTestFrequencyNumJ8 {

	FrequencyNums_Using_Hashmap FNUH;
	FrequencyNums_Using_Collections FNUC;
	FrequencyNums_Using_LambdaExpression FNULE;

	@BeforeEach
	void setUp() throws Exception {

		FNUH = new FrequencyNums_Using_Hashmap();
		FNUC = new FrequencyNums_Using_Collections();
		FNULE = new FrequencyNums_Using_LambdaExpression();
	}

	@Test
	@DisplayName("Positive inputs - Exp value and Actual matches")
	void test1() {
		Integer [] numArray= {1,3,4,1,6,9,4,3,7,8,3};
		int [] resArray = {2,1};
		Assertions.assertArrayEquals(resArray, FNUH.RdInputArray(numArray));

		Integer [] numArray1= {91,43,54,91,36,91,14,43,17,28,36,54,43};
		int [] resArray1 = {2,2};
		Assertions.assertArrayEquals(resArray1, FNUC.RdInputArray(numArray1));

		Integer [] numArray2= { 9, 6, 1, 3, 8, 4, 1, 6, 9, 4, 3, 7, 8, 3, 6, 9};
		int [] resArray2 = {3,3};
		Assertions.assertArrayEquals(resArray2, FNULE.RdInputArray(numArray2));
	}

	@Test
	@DisplayName("Negative inputs - Exp value and Actual matches")
	void test2() {
		Integer [] numArray= {6,9,4,3,7,8,3};
		int [] resArray = {1,2};
		Assertions.assertNotEquals(resArray, FNUH.RdInputArray(numArray));

		Integer [] numArray1= {36,91,14,43,17,28,36,54,43};
		int [] resArray1 = {3,5};
		Assertions.assertNotEquals(resArray1, FNUC.RdInputArray(numArray1));

		Integer [] numArray2= {8, 4, 1, 6, 9, 4, 3, 7, 8, 3, 6, 9};
		int [] resArray2 = {4,1};
		Assertions.assertNotEquals(resArray2, FNULE.RdInputArray(numArray2));
	}


	@Test
	@DisplayName("Null inputs - Exp value and Actual matches")
	void test3() {
		Integer [] numArray= {};
		int [] resArray = {0,0};
		Assertions.assertNotEquals(resArray, FNUH.RdInputArray(numArray));
		Assertions.assertNotEquals(resArray, FNUC.RdInputArray(numArray));
		Assertions.assertNotEquals(resArray, FNULE.RdInputArray(numArray));
	}

	@Test
	@DisplayName("Null inputs - Exp value and Actual matches")
	void test4() {
		int [] resArray = {0,0};
		Assertions.assertNotEquals(resArray, FNUH.RdInputArray(null));
		Assertions.assertNotEquals(resArray, FNUC.RdInputArray(null));
		Assertions.assertNotEquals(resArray, FNULE.RdInputArray(null));
	}
}
Output:
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Hashmap RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Hashmap'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: The provided Input validated Successfully
Total number of Pairs, available in the given array are = 2
Total number of Triplets, available in the given array are = 1
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Collections RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Total number of Pairs, available in the given array are = 2
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Collections'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: The provided Input validated Successfully
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_LambdaExpression RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_LambdaExpression'
Total number of Triplets, available in the given array are = 2
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: The provided Input validated Successfully
Total number of Pairs, available in the given array are = 3
Total number of Triplets, available in the given array are = 3
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Hashmap RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Hashmap'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: The provided Input validated Successfully
Total number of Pairs, available in the given array are = 1
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Collections RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Collections'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: The provided Input validated Successfully
Total number of Pairs, available in the given array are = 2
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_LambdaExpression RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_LambdaExpression'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: The provided Input validated Successfully
Total number of Pairs, available in the given array are = 5
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Hashmap RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Hashmap'
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Hashmap RdInputArray
INFO: The given Input Array numbers are null
Total number of Pairs, available in the given array are = 0
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Collections RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Collections'
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Collections RdInputArray
INFO: The given Input Array numbers are null
Total number of Pairs, available in the given array are = 0
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_LambdaExpression RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_LambdaExpression'
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_LambdaExpression RdInputArray
INFO: The given Input Array numbers are null
Total number of Pairs, available in the given array are = 0
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Hashmap RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Hashmap'
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Hashmap RdInputArray
INFO: The given Input Array numbers are null
Total number of Pairs, available in the given array are = 0
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Collections RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_Collections'
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_Collections RdInputArray
INFO: The given Input Array numbers are null
Total number of Pairs, available in the given array are = 0
Total number of Triplets, available in the given array are = 0
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_LambdaExpression RdInputArray
INFO: This method 'RdInputArray' called from the Class 'pack1.JUnitTestFrequencyNumJ8'
Jun 26, 2023 10:04:21 PM pack1.ReadInpArrayNums validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.FrequencyNums_Using_LambdaExpression'
Jun 26, 2023 10:04:21 PM pack1.FrequencyNums_Using_LambdaExpression RdInputArray
INFO: The given Input Array numbers are null
Total number of Pairs, available in the given array are = 0
Total number of Triplets, available in the given array are = 0