package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodSample1;
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodSample2;
import static com.oguerreiro.resilient.domain.PeriodVersionTestSamples.getPeriodVersionRandomSampleGenerator;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

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

class PeriodTest {

  @Test
  void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Period.class);
    Period period1 = getPeriodSample1();
    Period period2 = new Period();
    assertThat(period1).isNotEqualTo(period2);

    period2.setId(period1.getId());
    assertThat(period1).isEqualTo(period2);

    period2 = getPeriodSample2();
    assertThat(period1).isNotEqualTo(period2);
  }

  @Test
  void periodVersionTest() {
    Period period = getPeriodRandomSampleGenerator();
    PeriodVersion periodVersionBack = getPeriodVersionRandomSampleGenerator();

    period.addPeriodVersion(periodVersionBack);
    assertThat(period.getPeriodVersions()).containsOnly(periodVersionBack);
    assertThat(periodVersionBack.getPeriod()).isEqualTo(period);

    period.removePeriodVersion(periodVersionBack);
    assertThat(period.getPeriodVersions()).doesNotContain(periodVersionBack);
    assertThat(periodVersionBack.getPeriod()).isNull();

    period.periodVersions(new ArrayList<>(List.of(periodVersionBack)));
    assertThat(period.getPeriodVersions()).containsOnly(periodVersionBack);
    assertThat(periodVersionBack.getPeriod()).isEqualTo(period);

    period.setPeriodVersions(new ArrayList<>());
    assertThat(period.getPeriodVersions()).doesNotContain(periodVersionBack);
    assertThat(periodVersionBack.getPeriod()).isNull();
  }

}
