Question

Software Quality Assurance and Testing: Many applications include a date-field widget where users can enter a...

Software Quality Assurance and Testing:

Many applications include a date-field widget where users can enter a date in the form MM/DD/YYYY, representing a two-digit month, two-digit day, and four-digit year. Your boss decided to write their own date-field widget, so now you have to test it. The date-field widget is designed to accept only valid dates while rejecting all invalid dates.

You can assume that the validation check is only done when the field is fully-populated with eight numeric digits (0-9), and that you only have to test against the Gregorian calendar.

Was anything unclear about this problem? For any assumptions that you make, state what was unclear, your assumption, and why you believe your assumption is reasonable.

Again, use equivalence classes to analyze this problem, writing your answer as a table with multiple columns. Ensure that your table tests boundary and interior values, but try not to include excessive tests.

Homework Answers

Answer #1

I have created a java class for you which will help you in checking if date is valid or not.

/************************** FILE: CalendarCheck.java **************************************/

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CalendarCheck {

   public static void main(String[] args) {
       System.out.println("Checking last day of Feb in non-leap year");
       checkDateAndPrintResult("02/29/2014");
      
       System.out.println("\nChecking last day of Feb in leap year ");
       checkDateAndPrintResult("02/29/2016");
      
       System.out.println("\nChecking for more than 28 days in Feb in non-leap year");
       checkDateAndPrintResult("02/30/2014");
      
       System.out.println("\nChecking for invalid month");
       checkDateAndPrintResult("31/29/2013");
      
       System.out.println("\nChecking for invalid day");
       checkDateAndPrintResult("06/34/9014");
      
       System.out.println("\nChecking for zero values");
       checkDateAndPrintResult("00/09/2014");
       checkDateAndPrintResult("03/00/2014");
       checkDateAndPrintResult("01/06/0000");

       System.out.println("\nChecking for format MM/DD/YYYY");
       checkDateAndPrintResult("06-09-2014");      
       checkDateAndPrintResult("09\31\2014"); // back slash
       checkDateAndPrintResult("2/29/2014"); // valid date but invalid format
       checkDateAndPrintResult("02/29.2014");
      
   }

   public static void checkDateAndPrintResult(String dateString) {
       Date dateFound = checkIfFormatIsRight(dateString);
       if (dateFound != null) {
           System.out.println(dateString + ": Valid Date");
       } else {
           System.out.println(dateString + ": Invalid Date");
       }
   }

   /*
   * Method to check if a given date String is in valid format of MM/DD/YYYY
   * and whether it has got valid values or not. Returns the Date object if
   * valid dateString is provided, else returns null
   */
   public static Date checkIfFormatIsRight(String dateString) {
       Date dateFound = null;
       try {
           // preparing the format mask
           SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

           // preparing the date
           dateFound = sdf.parse(dateString);

           // matching if prepared date and given date are same
           // otherwise given date is not valid
           if (!dateString.equals(sdf.format(dateFound))) {
               dateFound = null;
           }
       } catch (ParseException ex) {
           // means date is not in proper format
           return null;
       }
       // If no date has been found, dateFound will be null
       return dateFound;      
   }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions