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.util.formatter; 017 018import org.gbif.api.model.registry.eml.temporal.DateRange; 019import org.gbif.api.model.registry.eml.temporal.SingleDate; 020import org.gbif.api.model.registry.eml.temporal.TemporalCoverage; 021import org.gbif.api.model.registry.eml.temporal.VerbatimTimePeriod; 022 023import org.junit.jupiter.api.Test; 024 025import static org.junit.jupiter.api.Assertions.assertEquals; 026 027public class TemporalCoverageFormatterVisitorTest { 028 029 @Test 030 public void testTemporalCoverageFormatterVisitor(){ 031 TemporalCoverageFormatterVisitor formatter = new TestFormatter(); 032 TemporalCoverage dateRange = new DateRange(); 033 TemporalCoverage singleDate = new SingleDate(); 034 TemporalCoverage verbatimTimePeriod = new VerbatimTimePeriod(); 035 036 assertEquals("dateRange", dateRange.acceptFormatter(formatter)); 037 assertEquals("singleDate", singleDate.acceptFormatter(formatter)); 038 assertEquals("verbatimTimePeriod", verbatimTimePeriod.acceptFormatter(formatter)); 039 } 040 041 /** 042 * Test implementation of TemporalCoverageFormatterVisitor to ensure all format() methods are reachable 043 */ 044 private static class TestFormatter implements TemporalCoverageFormatterVisitor { 045 046 @Override 047 public String format(DateRange t) { 048 return "dateRange"; 049 } 050 051 @Override 052 public String format(SingleDate t) { 053 return "singleDate"; 054 } 055 056 @Override 057 public String format(VerbatimTimePeriod t) { 058 return "verbatimTimePeriod"; 059 } 060 } 061}