package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.UnitTestSamples.*;
import static com.oguerreiro.resilient.domain.UnitTypeTestSamples.*;
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 UnitTypeTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(UnitType.class);
        UnitType unitType1 = getUnitTypeSample1();
        UnitType unitType2 = new UnitType();
        assertThat(unitType1).isNotEqualTo(unitType2);

        unitType2.setId(unitType1.getId());
        assertThat(unitType1).isEqualTo(unitType2);

        unitType2 = getUnitTypeSample2();
        assertThat(unitType1).isNotEqualTo(unitType2);
    }

    @Test
    void unitTest() {
        UnitType unitType = getUnitTypeRandomSampleGenerator();
        Unit unitBack = getUnitRandomSampleGenerator();

        unitType.addUnit(unitBack);
        assertThat(unitType.getUnits()).containsOnly(unitBack);
        assertThat(unitBack.getUnitType()).isEqualTo(unitType);

        unitType.removeUnit(unitBack);
        assertThat(unitType.getUnits()).doesNotContain(unitBack);
        assertThat(unitBack.getUnitType()).isNull();

        unitType.units(new HashSet<>(Set.of(unitBack)));
        assertThat(unitType.getUnits()).containsOnly(unitBack);
        assertThat(unitBack.getUnitType()).isEqualTo(unitType);

        unitType.setUnits(new HashSet<>());
        assertThat(unitType.getUnits()).doesNotContain(unitBack);
        assertThat(unitBack.getUnitType()).isNull();
    }
}
