//   Copyright 2012 Georg-August-Universität Göttingen, Germany
//
//   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 de.ugoe.cs.autoquest.assertions;

import de.ugoe.cs.autoquest.IReplayDecorator;
import de.ugoe.cs.autoquest.eventcore.IReplayable;
import de.ugoe.cs.util.StringTools;

/**
 * <p>
 * This class defines the replay for file equals assertions.
 * </p>
 * 
 * @author Jeffrey Hall, Steffen Herbold
 * @version 2.0
 */
public class FileEqualsReplay implements IReplayable {

    /**
     * <p>
     * The file that should be equal to expectedFile.
     * </p>
     */
    protected final String actualFile;

    /**
     * <p>
     * The file that is used as the reference.
     * </p>
     */
    protected final String expectedFile;

    /**
     * <p>
     * Id for object serialization.
     * </p>
     */
    private static final long serialVersionUID = 1L;

    /**
     * <p>
     * Constructor. Creates a new FileEqualsReplay.
     * </p>
     * 
     * @param expectedFile
     *            name and path of the expected file
     * @param actualFile
     *            name and path of the actual file
     * @throws IllegalArgumentException
     *             thrown if expectedFile or actualFile are null
     */
    public FileEqualsReplay(String expectedFile, String actualFile) {
        if (expectedFile == null) {
            throw new IllegalArgumentException("expected file must not be null");
        }
        if (actualFile == null) {
            throw new IllegalArgumentException("actual file must not be null");
        }
        this.expectedFile = expectedFile;
        this.actualFile = actualFile;
    }

    /*
     * (non-Javadoc)
     * 
     * @see de.ugoe.cs.autoquest.eventcore.IReplayable#getReplay()
     */
    public String getReplay() {

        String actualFileTmp = StringTools.xmlEntityReplacement(actualFile);
        String expectedFileTmp = StringTools.xmlEntityReplacement(expectedFile);

        StringBuilder currentMsgStr = new StringBuilder(800);
        currentMsgStr.append("  <fileEquals ");
        currentMsgStr.append("actualFile=\"" + actualFileTmp + "\" ");
        currentMsgStr.append("expectedFile=\"" + expectedFileTmp + "\"/>");
        currentMsgStr.append(StringTools.ENDLINE);
        return currentMsgStr.toString();
    }

    /*
     * (non-Javadoc)
     * 
     * @see de.ugoe.cs.autoquest.eventcore.IReplayable#getDecorator()
     */
    @Override
    public IReplayDecorator getDecorator() {
        return null;
    }

}
