package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationRandomSampleGenerator;
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationSample1;
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationSample2;
import static com.oguerreiro.resilient.domain.OrganizationTypeTestSamples.getOrganizationTypeRandomSampleGenerator;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.Set;

import org.junit.jupiter.api.Test;

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

class OrganizationTest {

  @Test
  void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Organization.class);
    Organization organization1 = getOrganizationSample1();
    Organization organization2 = new Organization();
    assertThat(organization1).isNotEqualTo(organization2);

    organization2.setId(organization1.getId());
    assertThat(organization1).isEqualTo(organization2);

    organization2 = getOrganizationSample2();
    assertThat(organization1).isNotEqualTo(organization2);
  }

  @Test
  void childTest() {
    Organization organization = getOrganizationRandomSampleGenerator();
    Organization organizationBack = getOrganizationRandomSampleGenerator();

    organization.addChild(organizationBack);
    assertThat(organization.getChildren()).containsOnly(organizationBack);
    assertThat(organizationBack.getParent()).isEqualTo(organization);

    organization.removeChild(organizationBack);
    assertThat(organization.getChildren()).doesNotContain(organizationBack);
    assertThat(organizationBack.getParent()).isNull();

    organization.children(new ArrayList<>(Set.of(organizationBack)));
    assertThat(organization.getChildren()).containsOnly(organizationBack);
    assertThat(organizationBack.getParent()).isEqualTo(organization);

    organization.setChildren(new ArrayList<>());
    assertThat(organization.getChildren()).doesNotContain(organizationBack);
    assertThat(organizationBack.getParent()).isNull();
  }

  @Test
  void parentTest() {
    Organization organization = getOrganizationRandomSampleGenerator();
    Organization organizationBack = getOrganizationRandomSampleGenerator();

    organization.setParent(organizationBack);
    assertThat(organization.getParent()).isEqualTo(organizationBack);

    organization.parent(null);
    assertThat(organization.getParent()).isNull();
  }

  @Test
  void organizationTypeTest() {
    Organization organization = getOrganizationRandomSampleGenerator();
    OrganizationType organizationTypeBack = getOrganizationTypeRandomSampleGenerator();

    organization.setOrganizationType(organizationTypeBack);
    assertThat(organization.getOrganizationType()).isEqualTo(organizationTypeBack);

    organization.organizationType(null);
    assertThat(organization.getOrganizationType()).isNull();
  }
}
