How to write JUnit test code in Java for the function of checking whether a given number is ArmStrong number or not?

This is the JUnit 5 solution to cover all kinds of inputs provided to check whether a given number is ArmStrong number or not. This Unit test executes tests for the ‘RdInput’ function available in the class ‘ArmstrongNumberJ8’.

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

	ArmStrongNumber_Using_String ANUS;
	ArmStrongNumber_Using_CoreLogic ANUCL;
	ArmStrongNumber_Using_Stream ANUStream;

	@BeforeEach
	void setUp() throws Exception {

		ANUS = new ArmStrongNumber_Using_String();
		ANUCL = new ArmStrongNumber_Using_CoreLogic();
		ANUStream = new ArmStrongNumber_Using_Stream();
	}

	@Test
	@DisplayName("Positive inputs - Exp value and Actual matches")
	void test1() {

		Assertions.assertTrue(ANUS.RdInput(153));
		Assertions.assertTrue(ANUCL.RdInput(407));
		Assertions.assertTrue(ANUStream.RdInput(371));
	}

	@Test
	@DisplayName("Negative inputs - Exp value and Actual not matches")
	void test2() {

		Assertions.assertFalse(ANUS.RdInput(628));
		Assertions.assertFalse(ANUCL.RdInput(941));
		Assertions.assertFalse(ANUStream.RdInput(5936));
	}

	@Test
	@DisplayName("Null inputs")
	void test3() {

		Assertions.assertFalse(ANUS.RdInput(null));
		Assertions.assertFalse(ANUCL.RdInput(null));
		Assertions.assertFalse(ANUStream.RdInput(null));
	}
}
Output:
Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_String RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_String'
The given number is 153
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: The provided Input validated Successfully
The number 153 is ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_CoreLogic RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_CoreLogic'
The given number is 407
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: The provided Input validated Successfully
The number 407 is ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_Stream RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_Stream'
The given number is 371
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: The provided Input validated Successfully
The number 371 is ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_String RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_String'
The given number is 628
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: The provided Input validated Successfully
The number 628 is Not ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_CoreLogic RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_CoreLogic'
The given number is 941
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: The provided Input validated Successfully
The number 941 is Not ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_Stream RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_Stream'
The given number is 5936
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: The provided Input validated Successfully
The number 5936 is Not ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_String RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_String'
Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_String RdInput
INFO: The given Input number is null
The number null is Not ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_CoreLogic RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_CoreLogic'
Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_CoreLogic RdInput
INFO: The given Input number is null
The number null is Not ArmStrong Number

Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_Stream RdInput
INFO: This method 'RdInput' called from the Class 'pack1.JUnitTestArmStrongNumberJ8'
Apr 03, 2023 3:38:16 PM pack1.InputTheNumber validateInputs
INFO: This method 'validateInputs()' called from the Class 'pack1.ArmStrongNumber_Using_Stream'
Apr 03, 2023 3:38:16 PM pack1.ArmStrongNumber_Using_Stream RdInput
INFO: The given Input number is null
The number null is Not ArmStrong Number