package org.gbif.dwc.terms;

import java.util.HashSet;
import java.util.List;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class GbifTermTest {

  @Test
  public void testTerm() {
    assertEquals("taxonKey", GbifTerm.taxonKey.simpleName());
    assertEquals("http://rs.gbif.org/terms/1.0/taxonKey", GbifTerm.taxonKey.qualifiedName());

    assertEquals("lastInterpreted", GbifTerm.lastInterpreted.simpleName());
    assertEquals("http://rs.gbif.org/terms/1.0/lastInterpreted", GbifTerm.lastInterpreted.qualifiedName());
  }

  @Test
  public void testIsClass() {
    assertTrue(GbifTerm.VernacularName.isClass());
    assertTrue(GbifTerm.Distribution.isClass());
    assertFalse(GbifTerm.datasetKey.isClass());
  }

  @Test
  public void testNumberOfGroups() {
    assertEquals(8, GbifTerm.GROUPS.length);
  }

  /**
   * Test each group contains the expected number of terms, and contains no duplicates.
   */
  @Test
  public void testListByGroup() {
    List<GbifTerm> datasetTerms = GbifTerm.listByGroup(GbifTerm.GROUP_DATASET);
    assertEquals(2, datasetTerms.size());
    assertEquals(2, new HashSet<GbifTerm>(datasetTerms).size());

    List<GbifTerm> occurrenceTerms = GbifTerm.listByGroup(GbifTerm.GROUP_OCCURRENCE);
    assertEquals(13, occurrenceTerms.size());
    assertEquals(13, new HashSet<GbifTerm>(occurrenceTerms).size());

    List<GbifTerm> rowTerms = GbifTerm.listByGroup(GbifTerm.GROUP_ROW_TYPE);
    assertEquals(8, rowTerms.size());
    assertEquals(8, new HashSet<GbifTerm>(rowTerms).size());

    List<GbifTerm> distributionTerms = GbifTerm.listByGroup(GbifTerm.GROUP_SPECIES_DISTRIBUTION_EXTENSION);
    assertEquals(1, distributionTerms.size());
    assertEquals(1, new HashSet<GbifTerm>(distributionTerms).size());

    List<GbifTerm> profileTerms = GbifTerm.listByGroup(GbifTerm.GROUP_SPECIES_PROFILE_EXTENSION);
    assertEquals(10, profileTerms.size());
    assertEquals(10, new HashSet<GbifTerm>(profileTerms).size());

    List<GbifTerm> taxonTerms = GbifTerm.listByGroup(GbifTerm.GROUP_TAXON);
    assertEquals(12, taxonTerms.size());
    assertEquals(12, new HashSet<GbifTerm>(taxonTerms).size());

    List<GbifTerm> crawlingTerms = GbifTerm.listByGroup(GbifTerm.GROUP_CRAWLING);
    assertEquals(3, crawlingTerms.size());
    assertEquals(3, new HashSet<GbifTerm>(crawlingTerms).size());

    List<GbifTerm> vernacularTerms = GbifTerm.listByGroup(GbifTerm.GROUP_VERNACULAR_NAME_EXTENSION);
    assertEquals(3, vernacularTerms.size());
    assertEquals(3, new HashSet<GbifTerm>(vernacularTerms).size());
  }

  @Test
  public void testGroupCoverage() {
    HashSet<GbifTerm> arrayTerms = new HashSet<GbifTerm>();
    for (GbifTerm t : GbifTerm.TAXONOMIC_TERMS) {
      arrayTerms.add(t);
      assertFalse(t.isClass());
      assertEquals(GbifTerm.GROUP_TAXON, t.getGroup());
    }

    for (GbifTerm t : GbifTerm.listByGroup(GbifTerm.GROUP_TAXON)) {
      if (!arrayTerms.contains(t)) {
        assertTrue("Missing taxonomic term in GbifTerm.TAXONOMIC_TERMS: " + t.qualifiedName(), arrayTerms.contains(t));
      }
    }
  }

}

@@ -1359,17 +1359,17 @@
 Equals(1
-3
+4
 , occurr
@@ -1405,17 +1405,17 @@
 Equals(1
-3
+4
 , new Ha

fix GbifTermTest for new term