/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.examples.todolist.validator;

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

import static org.spine3.examples.todolist.validator.ValidatorHelper.isEmpty;
import static org.spine3.examples.todolist.validator.ValidatorHelper.isNull;

/**
 * Serves as validator class for the task due date input.
 *
 * <p>Validation will be passed when:
 *    <li>input is not {@code null};
 *    <li>input is not empty;
 *    <li>input has correct format according to the {@code DATE_FORMAT}.
 * <p>
 *
 * @author Illia Shepilov
 */
public class DueDateValidator implements Validator {

    private static final String DUE_DATE_IS_NULL = "The due date cannot be null.";
    private static final String DUE_DATE_IS_EMPTY = "The due date cannot be empty.";
    private static final String DATE_FORMAT = "yyyy-MM-dd";
    private static final String INCORRECT_DUE_DATE = "Incorrect due date format. Correct format: " + DATE_FORMAT + '.';
    private static final Locale locale = Locale.getDefault();
    private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT, locale);
    private String message;

    @Override
    public boolean validate(String input) {
        final boolean isNull = isNull(input);

        if (isNull) {
            message = DUE_DATE_IS_NULL;
            return false;
        }

        final boolean empty = isEmpty(input);
        if (empty) {
            message = DUE_DATE_IS_EMPTY;
            return false;
        }

        final boolean result = isCorrectFormat(input);
        return result;
    }

    private boolean isCorrectFormat(String input) {
        try {
            SIMPLE_DATE_FORMAT.parse(input);
        } catch (ParseException ignored) {
            message = INCORRECT_DUE_DATE;
            return false;
        }
        return true;
    }

    public static SimpleDateFormat getDateFormat() {
        return SIMPLE_DATE_FORMAT;
    }

    /**
     * Returns the message is indicated incorrect input by user.
     *
     * @return the warning message
     */
    public String getMessage() {
        return message;
    }
}

@@ -1130,33 +1130,8 @@
 mat;
-%0Aimport java.util.Locale;
 %0A%0Aim
@@ -1785,24 +1785,25 @@
 be empty.%22;%0A
+%0A
     private 
@@ -1806,54 +1806,41 @@
 ate 
-static final String DATE_FORMAT = %22yyyy-MM-dd%22
+final SimpleDateFormat dateFormat
 ;%0A  
@@ -1841,39 +1841,32 @@
 at;%0A    private 
-static 
 final String INC
@@ -1866,291 +1866,279 @@
 ing 
-INCORRECT_DUE_DATE = %22Incorrect due date format. Correct format: %22 + DATE_FORMAT + '.';%0A    private static final Locale locale = Locale.getDefault();%0A    private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateF
+incorrectDueDateMsg;%0A    private String message;%0A%0A    public DueDateValidator(SimpleDateFormat dateFormat) %7B%0A        this.dateFormat = dateFormat;%0A        incorrectDueDateMsg = %22Incorrect due date f
 ormat
-(DATE_FORMAT, locale);%0A    private String message;
+. Correct format: %22 + dateFormat.getDateFormatSymbols() + '.';%0A    %7D
 %0A%0A  
@@ -2647,34 +2647,26 @@
         
-SIMPLE_DATE_FORMAT
+dateFormat
 .parse(i
@@ -2741,26 +2741,27 @@
 e = 
-INCORRECT_DUE_DATE
+incorrectDueDateMsg
 ;%0A  
@@ -2826,103 +2826,8 @@
  %7D%0A%0A
-    public static SimpleDateFormat getDateFormat() %7B%0A        return SIMPLE_DATE_FORMAT;%0A    %7D%0A%0A
     

Rework `DueDateValidator`.