package it.sw.pa.comune.artegna.domain;

import static it.sw.pa.comune.artegna.domain.LiberatoriaTestSamples.*;
import static it.sw.pa.comune.artegna.domain.UtenteAppTestSamples.*;
import static org.assertj.core.api.Assertions.assertThat;

import it.sw.pa.comune.artegna.web.rest.TestUtil;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;

class UtenteAppTest {

    @Test
    void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(UtenteApp.class);
        UtenteApp utenteApp1 = getUtenteAppSample1();
        UtenteApp utenteApp2 = new UtenteApp();
        assertThat(utenteApp1).isNotEqualTo(utenteApp2);

        utenteApp2.setId(utenteApp1.getId());
        assertThat(utenteApp1).isEqualTo(utenteApp2);

        utenteApp2 = getUtenteAppSample2();
        assertThat(utenteApp1).isNotEqualTo(utenteApp2);
    }

    @Test
    void liberatorieTest() {
        UtenteApp utenteApp = getUtenteAppRandomSampleGenerator();
        Liberatoria liberatoriaBack = getLiberatoriaRandomSampleGenerator();

        utenteApp.addLiberatorie(liberatoriaBack);
        assertThat(utenteApp.getLiberatories()).containsOnly(liberatoriaBack);
        assertThat(liberatoriaBack.getUtente()).isEqualTo(utenteApp);

        utenteApp.removeLiberatorie(liberatoriaBack);
        assertThat(utenteApp.getLiberatories()).doesNotContain(liberatoriaBack);
        assertThat(liberatoriaBack.getUtente()).isNull();

        utenteApp.liberatories(new HashSet<>(Set.of(liberatoriaBack)));
        assertThat(utenteApp.getLiberatories()).containsOnly(liberatoriaBack);
        assertThat(liberatoriaBack.getUtente()).isEqualTo(utenteApp);

        utenteApp.setLiberatories(new HashSet<>());
        assertThat(utenteApp.getLiberatories()).doesNotContain(liberatoriaBack);
        assertThat(liberatoriaBack.getUtente()).isNull();
    }
}
