@Test(dataProvider = "InvalidDateProvider", dependsOnMethods="ValidDateTest") public void InValidDateTest(String date) { boolean valid = DateValidator.validate(date); System.out.println("Date is valid : " + date + " , " + valid); Assert.assertEquals(valid, false); }
public static boolean validate(final String date) { Matcher matcher = pattern.matcher(date); if (matcher.matches()) { matcher.reset(); if (matcher.find()) { int year = Integer.parseInt(matcher.group(1)); String month = matcher.group(2); String day = matcher.group(3); if (day.equals("31") && (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11") || month.equals("04") || month.equals("06") || month .equals("09"))) { return false; } else if (month.equals("2") || month.equals("02")) { if (year % 4 == 0) { if (day.equals("30") || day.equals("31")) { return false; } else { return true; } } else { if (day.equals("29") || day.equals("30") || day.equals("31")) { return false; } else { return true; } } } else { return true; } } else { return false; } } else { return false; } }
DateValidator { public static boolean validate(final String date) { Matcher matcher = pattern.matcher(date); if (matcher.matches()) { matcher.reset(); if (matcher.find()) { int year = Integer.parseInt(matcher.group(1)); String month = matcher.group(2); String day = matcher.group(3); if (day.equals("31") && (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11") || month.equals("04") || month.equals("06") || month .equals("09"))) { return false; } else if (month.equals("2") || month.equals("02")) { if (year % 4 == 0) { if (day.equals("30") || day.equals("31")) { return false; } else { return true; } } else { if (day.equals("29") || day.equals("30") || day.equals("31")) { return false; } else { return true; } } } else { return true; } } else { return false; } } else { return false; } } }
DateValidator { public static boolean validate(final String date) { Matcher matcher = pattern.matcher(date); if (matcher.matches()) { matcher.reset(); if (matcher.find()) { int year = Integer.parseInt(matcher.group(1)); String month = matcher.group(2); String day = matcher.group(3); if (day.equals("31") && (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11") || month.equals("04") || month.equals("06") || month .equals("09"))) { return false; } else if (month.equals("2") || month.equals("02")) { if (year % 4 == 0) { if (day.equals("30") || day.equals("31")) { return false; } else { return true; } } else { if (day.equals("29") || day.equals("30") || day.equals("31")) { return false; } else { return true; } } } else { return true; } } else { return false; } } else { return false; } }  }
DateValidator { public static boolean validate(final String date) { Matcher matcher = pattern.matcher(date); if (matcher.matches()) { matcher.reset(); if (matcher.find()) { int year = Integer.parseInt(matcher.group(1)); String month = matcher.group(2); String day = matcher.group(3); if (day.equals("31") && (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11") || month.equals("04") || month.equals("06") || month .equals("09"))) { return false; } else if (month.equals("2") || month.equals("02")) { if (year % 4 == 0) { if (day.equals("30") || day.equals("31")) { return false; } else { return true; } } else { if (day.equals("29") || day.equals("30") || day.equals("31")) { return false; } else { return true; } } } else { return true; } } else { return false; } } else { return false; } }  static boolean validate(final String date); }
DateValidator { public static boolean validate(final String date) { Matcher matcher = pattern.matcher(date); if (matcher.matches()) { matcher.reset(); if (matcher.find()) { int year = Integer.parseInt(matcher.group(1)); String month = matcher.group(2); String day = matcher.group(3); if (day.equals("31") && (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11") || month.equals("04") || month.equals("06") || month .equals("09"))) { return false; } else if (month.equals("2") || month.equals("02")) { if (year % 4 == 0) { if (day.equals("30") || day.equals("31")) { return false; } else { return true; } } else { if (day.equals("29") || day.equals("30") || day.equals("31")) { return false; } else { return true; } } } else { return true; } } else { return false; } } else { return false; } }  static boolean validate(final String date);  }