/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.shardingsphere.sql.parser.integrate.asserts;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.ParserResultSetRegistry;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.ParserResultSetRegistryFactory;
import org.apache.shardingsphere.test.sql.SQLCaseType;
import org.apache.shardingsphere.test.sql.loader.SQLCasesLoader;
import org.apache.shardingsphere.test.sql.loader.SQLCasesRegistry;

import java.util.Collections;

/**
 * SQL statement assert message.
 *
 * @author zhangliang
 */
@RequiredArgsConstructor
public final class SQLStatementAssertMessage {
    
    private final String sqlCaseId;
    
    private final SQLCaseType sqlCaseType;
    
    private final SQLCasesLoader sqlCasesLoader = SQLCasesRegistry.getInstance().getSqlCasesLoader();
    
    private final ParserResultSetRegistry parserResultSetRegistry = ParserResultSetRegistryFactory.getInstance().getRegistry();
    
    /**
     * Get message text.
     * 
     * @param assertFailureMessage assert failure message
     * @return message text
     */
    public String getText(final String assertFailureMessage) {
        StringBuilder result = new StringBuilder(System.getProperty("line.separator"));
        result.append("SQL Case ID : ");
        result.append(sqlCaseId);
        result.append(System.getProperty("line.separator"));
        result.append("SQL         : ");
        if (SQLCaseType.Placeholder == sqlCaseType) {
            result.append(sqlCasesLoader.getSQL(sqlCaseId, sqlCaseType, Collections.emptyList()));
            result.append(System.getProperty("line.separator"));
            result.append("SQL Params  : ");
            result.append(parserResultSetRegistry.get(sqlCaseId).getParameters());
            result.append(System.getProperty("line.separator"));
        } else {
            result.append(sqlCasesLoader.getSQL(sqlCaseId, sqlCaseType, parserResultSetRegistry.get(sqlCaseId).getParameters()));
        }
        result.append(System.getProperty("line.separator"));
        result.append(assertFailureMessage);
        result.append(System.getProperty("line.separator"));
        return result.toString();
    }
}

@@ -1821,23 +1821,17 @@
  @param 
-assertF
+f
 ailureMe
@@ -1836,23 +1836,16 @@
 Message 
-assert 
 failure 
@@ -1927,23 +1927,17 @@
  String 
-assertF
+f
 ailureMe
@@ -2033,38 +2033,262 @@
 tor%22));%0A        
-result
+appendSQLCaseId(result);%0A        appendSQL(result);%0A        appendFailureMessage(failureMessage, result);%0A        return result.toString();%0A    %7D%0A    %0A    private void appendSQLCaseId(final StringBuilder builder) %7B%0A        builder
 .append(%22SQL Cas
@@ -2298,38 +2298,39 @@
 D : %22);%0A        
-result
+builder
 .append(sqlCaseI
@@ -2333,38 +2333,39 @@
 aseId);%0A        
-result
+builder
 .append(System.g
@@ -2395,34 +2395,104 @@
 tor%22));%0A    
+%7D%0A
     
-result
+%0A    private void appendSQL(final StringBuilder builder) %7B%0A        builder
 .append(%22SQL
@@ -2564,38 +2564,39 @@
 ) %7B%0A            
-result
+builder
 .append(sqlCases
@@ -2664,38 +2664,39 @@
 ));%0A            
-result
+builder
 .append(System.g
@@ -2730,38 +2730,39 @@
 ));%0A            
-result
+builder
 .append(%22SQL Par
@@ -2776,38 +2776,39 @@
 %22);%0A            
-result
+builder
 .append(parserRe
@@ -2860,38 +2860,39 @@
 ));%0A            
-result
+builder
 .append(System.g
@@ -2943,38 +2943,39 @@
 e %7B%0A            
-result
+builder
 .append(sqlCases
@@ -3080,34 +3080,144 @@
       %7D%0A    
+%7D%0A
     
-result
+%0A    private void appendFailureMessage(final String failureMessage, final StringBuilder builder) %7B%0A        builder
 .append(Syst
@@ -3259,30 +3259,31 @@
         
-result
+builder
 .append(
 assertFa
@@ -3278,15 +3278,9 @@
 end(
-assertF
+f
 ailu
@@ -3299,22 +3299,23 @@
         
-result
+builder
 .append(
@@ -3357,42 +3357,8 @@
 ));%0A
-        return result.toString();%0A
     

refactor SQLStatementAssertMessage