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 VariableCategoryTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(VariableCategory.class);
        VariableCategory variableCategory1 = getVariableCategorySample1();
        VariableCategory variableCategory2 = new VariableCategory();
        assertThat(variableCategory1).isNotEqualTo(variableCategory2);

        variableCategory2.setId(variableCategory1.getId());
        assertThat(variableCategory1).isEqualTo(variableCategory2);

        variableCategory2 = getVariableCategorySample2();
        assertThat(variableCategory1).isNotEqualTo(variableCategory2);
    }

    @Test
    void variableTest() {
        VariableCategory variableCategory = getVariableCategoryRandomSampleGenerator();
        Variable variableBack = getVariableRandomSampleGenerator();

        variableCategory.addVariable(variableBack);
        assertThat(variableCategory.getVariables()).containsOnly(variableBack);
        assertThat(variableBack.getVariableCategory()).isEqualTo(variableCategory);

        variableCategory.removeVariable(variableBack);
        assertThat(variableCategory.getVariables()).doesNotContain(variableBack);
        assertThat(variableBack.getVariableCategory()).isNull();

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

        variableCategory.setVariables(new HashSet<>());
        assertThat(variableCategory.getVariables()).doesNotContain(variableBack);
        assertThat(variableBack.getVariableCategory()).isNull();
    }

    @Test
    void variableScopeTest() {
        VariableCategory variableCategory = getVariableCategoryRandomSampleGenerator();
        VariableScope variableScopeBack = getVariableScopeRandomSampleGenerator();

        variableCategory.setVariableScope(variableScopeBack);
        assertThat(variableCategory.getVariableScope()).isEqualTo(variableScopeBack);

        variableCategory.variableScope(null);
        assertThat(variableCategory.getVariableScope()).isNull();
    }
}
