/*
 * 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 io.spine.examples.todolist.validator;

import javax.annotation.Nullable;

import static io.spine.examples.todolist.validator.ValidatorHelper.isEmpty;
import static io.spine.examples.todolist.validator.ValidatorHelper.isNull;

/**
 * Serves as a validator for the user approve answer.
 *
 * <p>Validation will be passed when:
 * <li>input is `y`;
 * <li>input is `n`.
 * <p>In other cases validation will be failed.
 *
 * @author Illia Shepilov
 */
public class ApproveAnswerValidator implements Validator<String> {

    private static final String INVALID_INPUT = "Invalid input. Valid values: 'y' or 'n'";
    private static final String NEGATIVE_ANSWER = "n";
    private static final String POSITIVE_ANSWER = "y";
    private String message;

    @Override
    public boolean validate(String input) {

        final boolean isNegativeOrPositiveAns =
                NEGATIVE_ANSWER.equals(input) || POSITIVE_ANSWER.equals(input);
        final boolean invalidInput = isNull(input) || isEmpty(input) || !isNegativeOrPositiveAns;

        if (invalidInput) {
            this.message = INVALID_INPUT;
            return false;
        }
        return true;
    }

    @Override
    @Nullable
    public String getMessage() {
        return message;
    }
}

@@ -1110,143 +1110,52 @@
 tic 
-io.spine.examples.todolist.validator.ValidatorHelper.isEmpty;%0Aimport static io.spine.examples.todolist.validator.ValidatorHelper.isNull
+com.google.common.base.Strings.isNullOrEmpty
 ;%0A%0A/
@@ -1447,99 +1447,8 @@
  %7B%0A%0A
-    private static final String INVALID_INPUT = %22Invalid input. Valid values: 'y' or 'n'%22;%0A
     
@@ -1553,16 +1553,169 @@
  = %22y%22;%0A
+    private static final String INVALID_INPUT_MSG =%0A            %22Invalid input. Valid values: '%22 + POSITIVE_ANSWER + %22' or '%22 + NEGATIVE_ANSWER + %22'.%22;%0A%0A
     priv
@@ -1792,16 +1792,88 @@
 input) %7B
+%0A        if (isNullOrEmpty(input)) %7B%0A            return false;%0A        %7D
 %0A%0A      
@@ -2006,123 +2006,36 @@
     
-final boolean invalidInput = isNull(input) %7C%7C isEmpty(input) %7C%7C !isNegativeOrPositiveAns;%0A%0A        if (invalidInput
+if (!isNegativeOrPositiveAns
 ) %7B%0A
@@ -2074,16 +2074,20 @@
 ID_INPUT
+_MSG
 ;%0A      
@@ -2098,32 +2098,32 @@
   return false;%0A
-
         %7D%0A      
@@ -2116,16 +2116,17 @@
       %7D%0A
+%0A
         

Clean up `ApproveAnswerValidator`