I have this code:

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package se211.dz14;

import java.util.Scanner;

 * @author Boris
public class Month {

     * @param args the command line arguments

       public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            System.out.println("Please specify the number of times you want to enter a month:");
            int times = scan.nextInt();
            for (int i = 0; i < times; i++) {
            System.out.println("Please enter a month number:");
            int month = scan.nextInt();

        switch (month) {
            case 1:  System.out.println("January"); break;
            case 2:  System.out.println("February"); break;
            case 3:  System.out.println("March"); break;
            case 4:  System.out.println("April"); break;
            case 5:  System.out.println("May"); break;
            case 6:  System.out.println("June"); break;
            case 7:  System.out.println("July"); break;
            case 8:  System.out.println("August"); break;
            case 9:  System.out.println("September"); break;
            case 10: System.out.println("October"); break;
            case 11: System.out.println("November"); break;
            case 12: System.out.println("December"); break;
            default: System.out.println("Not a month!"); break;


and I need to make JUnit tests for it. I've tried making JUnit tests for this code directly, but it obviously makes JUnit tests for the main method, which I don't want. I need this code in another method, which accepts month as a user entered variable and test all that in JUnit tests. I'm pretty sure I have to put all this code into another method or something like that, and probably call it from within the main method. Correct me if I'm wrong. That's what I thought would be right...

Since I'm a newbie in Java, I'd be glad if someone helped me with this. This code works on it's own, but I need it to be inside another method (as I've understood) and then tested in JUnit tests. If it works from within another method which is called later, I'll post the code for JUnit tests so you see where I came to.

Thanks again.

And yeah, I forgot. I don't need this for loop anyway. Just added it for fun. There can even be the switch code only, too, without the for loop.

This article has been dead for over six months. Start a new discussion instead.