All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aventstack.extentreports.model.context.NamedAttributeContext Maven / Gradle / Ivy

There is a newer version: 5.1.2
Show newest version
package com.aventstack.extentreports.model.context;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.model.NamedAttribute;
import com.aventstack.extentreports.model.Test;
import com.aventstack.extentreports.util.Assert;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class NamedAttributeContext implements Serializable {
    private static final long serialVersionUID = -2671203343283101908L;

    private final List testList = Collections.synchronizedList(new ArrayList<>());
    private T attr;
    private Map statusDist = new HashMap<>();

    public NamedAttributeContext(T attribute, Test test) {
        this.attr = attribute;
        addTest(test);
    }

    public void addTest(Test test) {
    	Assert.notNull(test, "Test must not be null");
        testList.add(test);
        refresh(test);
    }

    private synchronized void refresh(Test test) {
        statusDist.merge(test.getStatus(), 1, Integer::sum);
    }

    public void refresh() {
        statusDist.clear();
        testList.forEach(this::refresh);
    }

    public Integer size() {
        return statusDist.values().stream().reduce(0, Integer::sum);
    }

    public Integer getPassed() {
        return get(Status.PASS);
    }

    private Integer get(Status s) {
        return statusDist.get(s) == null ? 0 : statusDist.get(s);
    }

    public Integer getFailed() {
        return get(Status.FAIL);
    }

    public Integer getSkipped() {
        return get(Status.SKIP);
    }

    public Integer getOthers() {
        return get(Status.WARNING);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy