JUnit Testing - Decimal to hexadecimal code
10:44 19 Mar 2018

I need to do JUnit tests for a project in my school, but I don't recall know how to do a test for the following code (It just converts a decimal number into a hexadecimal one).

Any help would be appreciated!

import java.util.Scanner;

public class DecToHexa {

    public static void main (String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("Enter a decimal number: ");
        int decimal = input.nextInt();

        String hex = "";

        while (decimal != 0) {
            int hexValue = decimal % 16;

            char hexDigit = (hexValue <= 9 && hexValue > 0) ? (char) (hexValue + '0')
                    : (char) (hexValue - 10 + 'A');

            hex = hexDigit + hex;

            decimal = decimal / 16;
        }
        System.out.println("The hex number is " + hex);
    }
}
java testing junit