0

I have a @Service annotated service class method createShiftPlan(int numberOfEmployees, int startingMonth, int year) inside which I am using SimpleDateFormat class's parse() method.

How can I test for parse exceptions with integer inputs here?

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
Anupam Pandey
  • 51
  • 2
  • 9

1 Answers1

1

Set SimpleDateFormat.setLenient(false) to disable lenient parsing and supply a non-existing date e.g. 35th of April. With lenient disabled this will throw a ParseException instead of silently fixing the date.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111