-1

すべてが完璧に見えますが、テスト ケースは失敗し続け、これらすべてに対して Java.lang.nullPointerException が発生します。

ここにテストケースがあります

@Test
    public void validMonths() {
        DayOfWeek dow = new DayOfWeek(1, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("January") == 0);
        dow = new DayOfWeek(2, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("February") == 0);
        dow = new DayOfWeek(3, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("March") == 0);
        dow = new DayOfWeek(4, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("April") == 0);
        dow = new DayOfWeek(5, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("May") == 0);
        dow = new DayOfWeek(6, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("June") == 0);
        dow = new DayOfWeek(7, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("July") == 0);
        dow = new DayOfWeek(8, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("August") == 0);
        dow = new DayOfWeek(9, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("September") == 0);
        dow = new DayOfWeek(10, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("October") == 0);
        dow = new DayOfWeek(11, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("November") == 0);
        dow = new DayOfWeek(12, 1, 1900);
        assertTrue(dow.getMonthString().compareTo("December") == 0);
    }

そして、ここに私の方法があります

public String getMonthString(){
         String[] arrayOfMonths = new String[11];
         arrayOfMonths[0] = "January";
         arrayOfMonths[1] = "February";
         arrayOfMonths[2] = "March";
         arrayOfMonths[3] = "April";
         arrayOfMonths[4] = "May";
         arrayOfMonths[5] = "June";
         arrayOfMonths[6] = "July";
         arrayOfMonths[7] = "August";
         arrayOfMonths[8] = "September";
         arrayOfMonths[9] = "October";
         arrayOfMonths[10] = "November";
         arrayOfMonths[11] = "December";
         if (this.myMonth > 0 && this.myMonth <=12){
             return arrayOfMonths[this.myMonth-1];
         }
         else{
             return "NO_VALUE";
         }
     }

誰が何が起こっているのか知っていますか?

4

1 に答える 1