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
  • 41,216
  • 9
  • 68
  • 101
Anupam Pandey
  • 41
  • 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
  • 41,216
  • 9
  • 68
  • 101