com.htmlhifive.pitalium.core.model.TestResult.java Source code

Java tutorial

Introduction

Here is the source code for com.htmlhifive.pitalium.core.model.TestResult.java

Source

/*
 * Copyright (C) 2015-2016 NS Solutions Corporation
 *
 * 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.htmlhifive.pitalium.core.model;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.htmlhifive.pitalium.common.util.JSONUtils;

/**
 * ?????
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TestResult implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * ???ID
     */
    private String resultId;
    /**
     * ?????
     */
    private ExecResult result;
    /**
     * {@link com.htmlhifive.pitalium.core.rules.AssertionView#assertView(String, String, List, List)}??
     * {@link com.htmlhifive.pitalium.core.rules.AssertionView#assertScreenshot(String, ScreenshotResult)}????
     */
    private List<ScreenshotResult> screenshotResults;

    /**
     * ??????
     */
    public TestResult() {
    }

    /**
     * ?????
     * 
     * @param resultId ?ID
     * @param result ?
     * @param screenshotResults ??
     */
    public TestResult(String resultId, ExecResult result, List<ScreenshotResult> screenshotResults) {
        this.resultId = resultId;
        this.result = result;

        setScreenshotResults(screenshotResults);
    }

    /**
     * ???ID???????????????
     * 
     * @param screenshotResults 1??ID???
     */
    void setScreenshotResults(List<ScreenshotResult> screenshotResults) {
        if (screenshotResults == null || screenshotResults.isEmpty()) {
            this.screenshotResults = Collections.emptyList();
            return;
        }

        this.screenshotResults = Collections.unmodifiableList(screenshotResults);
    }

    /**
     * ?ID????
     * 
     * @return ?ID
     */
    public String getResultId() {
        return resultId;
    }

    /**
     * ?????????
     * 
     * @return ???true
     */
    public ExecResult getResult() {
        return result;
    }

    /**
     * {@link com.htmlhifive.pitalium.core.rules.AssertionView#assertView(String, String, List, List)}??
     * {@link com.htmlhifive.pitalium.core.rules.AssertionView#assertScreenshot(String, ScreenshotResult)}??????
     * 
     * @return ???
     */
    public List<ScreenshotResult> getScreenshotResults() {
        return screenshotResults;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        TestResult result1 = (TestResult) o;

        if (resultId != null ? !resultId.equals(result1.resultId) : result1.resultId != null) {
            return false;
        }
        if (result != result1.result) {
            return false;
        }
        return !(screenshotResults != null ? !screenshotResults.equals(result1.screenshotResults)
                : result1.screenshotResults != null);

    }

    @Override
    public int hashCode() {
        int result1 = resultId != null ? resultId.hashCode() : 0;
        final int hashPrime = 31;
        result1 = hashPrime * result1 + (result != null ? result.hashCode() : 0);
        result1 = hashPrime * result1 + (screenshotResults != null ? screenshotResults.hashCode() : 0);
        return result1;
    }

    @Override
    public String toString() {
        return JSONUtils.toString(this);
    }

}