package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.OutputDataTestSamples.getOutputDataRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.VariableCategoryTestSamples.getVariableCategoryRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.VariableClassTestSamples.getVariableClassRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.VariableScopeTestSamples.getVariableScopeRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableSample1;
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableSample2;
import static com.oguerreiro.resilient.domain.VariableUnitsTestSamples.getVariableUnitsRandomSampleGenerator;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.Test;

import com.oguerreiro.resilient.web.rest.TestUtil;

class VariableTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(Variable.class);
        Variable variable1 = getVariableSample1();
        Variable variable2 = new Variable();
        assertThat(variable1).isNotEqualTo(variable2);

        variable2.setId(variable1.getId());
        assertThat(variable1).isEqualTo(variable2);

        variable2 = getVariableSample2();
        assertThat(variable1).isNotEqualTo(variable2);
    }

    @Test
    void variableUnitsTest() {
        Variable variable = getVariableRandomSampleGenerator();
        VariableUnits variableUnitsBack = getVariableUnitsRandomSampleGenerator();

        variable.addVariableUnits(variableUnitsBack);
        assertThat(variable.getVariableUnits()).containsOnly(variableUnitsBack);
        assertThat(variableUnitsBack.getVariable()).isEqualTo(variable);

        variable.removeVariableUnits(variableUnitsBack);
        assertThat(variable.getVariableUnits()).doesNotContain(variableUnitsBack);
        assertThat(variableUnitsBack.getVariable()).isNull();

        variable.variableUnits(new HashSet<>(Set.of(variableUnitsBack)));
        assertThat(variable.getVariableUnits()).containsOnly(variableUnitsBack);
        assertThat(variableUnitsBack.getVariable()).isEqualTo(variable);

        variable.setVariableUnits(new HashSet<>());
        assertThat(variable.getVariableUnits()).doesNotContain(variableUnitsBack);
        assertThat(variableUnitsBack.getVariable()).isNull();
    }

    @Test
    void baseUnitTest() {
        Variable variable = getVariableRandomSampleGenerator();
        Unit unitBack = getUnitRandomSampleGenerator();

        variable.setBaseUnit(unitBack);
        assertThat(variable.getBaseUnit()).isEqualTo(unitBack);

        variable.baseUnit(null);
        assertThat(variable.getBaseUnit()).isNull();
    }

    @Test
    void variableScopeTest() {
        Variable variable = getVariableRandomSampleGenerator();
        VariableScope variableScopeBack = getVariableScopeRandomSampleGenerator();

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

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

    @Test
    void variableCategoryTest() {
        Variable variable = getVariableRandomSampleGenerator();
        VariableCategory variableCategoryBack = getVariableCategoryRandomSampleGenerator();

        variable.setVariableCategory(variableCategoryBack);
        assertThat(variable.getVariableCategory()).isEqualTo(variableCategoryBack);

        variable.variableCategory(null);
        assertThat(variable.getVariableCategory()).isNull();
    }
}
