/*
 *
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.alibaba.nacos.client.utils;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.concurrent.Callable;

public class TemplateUtilsTest {
    
    @Test
    public void testStringNotEmptyAndThenExecuteSuccess() {
        String word = "run";
        Runnable task = Mockito.mock(Runnable.class);
        TemplateUtils.stringNotEmptyAndThenExecute(word, task);
        Mockito.verify(task, Mockito.times(1)).run();
    }
    
    @Test
    public void testStringNotEmptyAndThenExecuteFail() {
        String word = "";
        Runnable task = Mockito.mock(Runnable.class);
        TemplateUtils.stringNotEmptyAndThenExecute(word, task);
        Mockito.verify(task, Mockito.times(0)).run();
    }
    
    @Test
    public void testStringEmptyAndThenExecuteSuccess() {
        String word = "   ";
        String actual = TemplateUtils.stringEmptyAndThenExecute(word, new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "call";
            }
        });
        Assert.assertEquals("", actual);
    }
    
    @Test
    public void testStringEmptyAndThenExecuteFail() {
        String word = "";
        final String expect = "call";
        String actual = TemplateUtils.stringEmptyAndThenExecute(word, new Callable<String>() {
            @Override
            public String call() throws Exception {
                return expect;
            }
        });
        Assert.assertEquals(expect, actual);
    }
    
    @Test
    public void testStringBlankAndThenExecuteSuccess() {
        String word = "success";
        String actual = TemplateUtils.stringBlankAndThenExecute(word, new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "call";
            }
        });
        Assert.assertEquals(word, actual);
    }
    
    @Test
    public void testStringBlankAndThenExecuteFail() {
        String word = "   ";
        final String expect = "call";
        String actual = TemplateUtils.stringBlankAndThenExecute(word, new Callable<String>() {
            @Override
            public String call() throws Exception {
                return expect;
            }
        });
        Assert.assertEquals(expect, actual);
    }
}
@@ -738,47 +738,8 @@
 o;%0A%0A
-import java.util.concurrent.Callable;%0A%0A
 publ
@@ -1500,161 +1500,20 @@
 rd, 
-new Callable%3CString%3E() %7B%0A            @Override%0A            public String call() throws Exception %7B%0A                return %22call%22;%0A            %7D%0A        %7D
+() -%3E %22call%22
 );%0A 
@@ -1765,161 +1765,20 @@
 rd, 
-new Callable%3CString%3E() %7B%0A            @Override%0A            public String call() throws Exception %7B%0A                return expect;%0A            %7D%0A        %7D
+() -%3E expect
 );%0A 
@@ -2006,161 +2006,20 @@
 rd, 
-new Callable%3CString%3E() %7B%0A            @Override%0A            public String call() throws Exception %7B%0A                return %22call%22;%0A            %7D%0A        %7D
+() -%3E %22call%22
 );%0A 
@@ -2276,161 +2276,20 @@
 rd, 
-new Callable%3CString%3E() %7B%0A            @Override%0A            public String call() throws Exception %7B%0A                return expect;%0A            %7D%0A        %7D
+() -%3E expect
 );%0A 

Replace redundant code with lambda expression (#8074)