package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.VariableCategoryTestSamples.*;
import static com.oguerreiro.resilient.domain.VariableScopeTestSamples.*;
import static com.oguerreiro.resilient.domain.VariableTestSamples.*;
import static org.assertj.core.api.Assertions.assertThat;

import com.oguerreiro.resilient.web.rest.TestUtil;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;

class VariableScopeTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(VariableScope.class);
        VariableScope variableScope1 = getVariableScopeSample1();
        VariableScope variableScope2 = new VariableScope();
        assertThat(variableScope1).isNotEqualTo(variableScope2);

        variableScope2.setId(variableScope1.getId());
        assertThat(variableScope1).isEqualTo(variableScope2);

        variableScope2 = getVariableScopeSample2();
        assertThat(variableScope1).isNotEqualTo(variableScope2);
    }

    @Test
    void variableCategoryTest() {
        VariableScope variableScope = getVariableScopeRandomSampleGenerator();
        VariableCategory variableCategoryBack = getVariableCategoryRandomSampleGenerator();

        variableScope.addVariableCategory(variableCategoryBack);
        assertThat(variableScope.getVariableCategories()).containsOnly(variableCategoryBack);
        assertThat(variableCategoryBack.getVariableScope()).isEqualTo(variableScope);

        variableScope.removeVariableCategory(variableCategoryBack);
        assertThat(variableScope.getVariableCategories()).doesNotContain(variableCategoryBack);
        assertThat(variableCategoryBack.getVariableScope()).isNull();

        variableScope.variableCategories(new HashSet<>(Set.of(variableCategoryBack)));
        assertThat(variableScope.getVariableCategories()).containsOnly(variableCategoryBack);
        assertThat(variableCategoryBack.getVariableScope()).isEqualTo(variableScope);

        variableScope.setVariableCategories(new HashSet<>());
        assertThat(variableScope.getVariableCategories()).doesNotContain(variableCategoryBack);
        assertThat(variableCategoryBack.getVariableScope()).isNull();
    }

    @Test
    void variableTest() {
        VariableScope variableScope = getVariableScopeRandomSampleGenerator();
        Variable variableBack = getVariableRandomSampleGenerator();

        variableScope.addVariable(variableBack);
        assertThat(variableScope.getVariables()).containsOnly(variableBack);
        assertThat(variableBack.getVariableScope()).isEqualTo(variableScope);

        variableScope.removeVariable(variableBack);
        assertThat(variableScope.getVariables()).doesNotContain(variableBack);
        assertThat(variableBack.getVariableScope()).isNull();

        variableScope.variables(new HashSet<>(Set.of(variableBack)));
        assertThat(variableScope.getVariables()).containsOnly(variableBack);
        assertThat(variableBack.getVariableScope()).isEqualTo(variableScope);

        variableScope.setVariables(new HashSet<>());
        assertThat(variableScope.getVariables()).doesNotContain(variableBack);
        assertThat(variableBack.getVariableScope()).isNull();
    }
}
