001/*
002 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.vocabulary;
017
018import org.junit.jupiter.api.Test;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertThrows;
022
023public class KingdomTest {
024
025  @Test
026  public void testGetScientificName() {
027    assertEquals("Plantae", Kingdom.PLANTAE.scientificName());
028    assertEquals("Animalia", Kingdom.ANIMALIA.scientificName());
029    assertEquals("Chromista", Kingdom.CHROMISTA.scientificName());
030    assertEquals("incertae sedis", Kingdom.INCERTAE_SEDIS.scientificName());
031  }
032
033  @Test
034  public void testNubUsageKey() {
035    assertEquals("0", Kingdom.INCERTAE_SEDIS.nubUsageKey());
036    assertEquals("1", Kingdom.ANIMALIA.nubUsageKey());
037    assertEquals("6", Kingdom.PLANTAE.nubUsageKey());
038
039    for (Kingdom k : Kingdom.values()) {
040      assertEquals(String.valueOf(k.ordinal()), k.nubUsageKey());
041    }
042  }
043
044  @Test
045  public void testByKey() {
046    assertEquals(Kingdom.INCERTAE_SEDIS, Kingdom.byNubUsageKey(0));
047    assertEquals(Kingdom.ANIMALIA, Kingdom.byNubUsageKey(1));
048    assertEquals(Kingdom.PLANTAE, Kingdom.byNubUsageKey(6));
049    assertEquals(Kingdom.VIRUSES, Kingdom.byNubUsageKey(8));
050  }
051
052  @Test
053  public void testByKeyException() {
054    assertThrows(IllegalArgumentException.class, () -> Kingdom.byNubUsageKey(9));
055  }
056
057  @Test
058  public void testByKeyException2() {
059    assertThrows(IllegalArgumentException.class, () -> Kingdom.byNubUsageKey(-1));
060  }
061}