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 java.util.HashSet;
019import java.util.Set;
020
021import org.junit.jupiter.api.Test;
022
023import static org.junit.jupiter.api.Assertions.assertEquals;
024import static org.junit.jupiter.api.Assertions.assertFalse;
025import static org.junit.jupiter.api.Assertions.assertNull;
026
027public class NomenclaturalStatusTest {
028
029    @Test
030    public void testFromString() {
031        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("conserved"));
032        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("conserved "));
033        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("nom.cons."));
034        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("nomcons"));
035        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("nomen conservandum"));
036        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("orth. cons."));
037        assertEquals(NomenclaturalStatus.CONSERVED, NomenclaturalStatus.fromString("conservandum"));
038
039        assertNull(NomenclaturalStatus.fromString("carla"));
040        assertNull(NomenclaturalStatus.fromString(""));
041        assertNull(NomenclaturalStatus.fromString(null));
042    }
043
044    @Test
045    public void testUniqueness() {
046        Set<String> keys = new HashSet<>();
047        for (NomenclaturalStatus ns : NomenclaturalStatus.values()) {
048            if (ns.getAbbreviatedLabel() != null) {
049                assertFalse(keys.contains(ns.getAbbreviatedLabel()), ns.name());
050                keys.add(ns.getAbbreviatedLabel());
051            }
052
053            if (ns.getLatinLabel() != null) {
054                assertFalse(keys.contains(ns.getLatinLabel()), ns.name());
055                keys.add(ns.getLatinLabel());
056            }
057        }
058    }
059}