001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.api.model.predicate;
015
016import org.junit.jupiter.api.Test;
017
018import static org.junit.jupiter.api.Assertions.assertThrows;
019
020/**
021 * Test class for the GeoDistancePredicate class.
022 */
023public class GeoDistancePredicateTest {
024
025  @Test
026  public void testValidGeoDistance() {
027    // km
028    new GeoDistancePredicate("45", "100", "100km");
029
030    // meters
031    new GeoDistancePredicate("45", "100", "100m");
032
033    // feet
034    new GeoDistancePredicate("45", "100", "10ft");
035  }
036
037  @Test
038  public void testInvalidPoint() {
039    // Illegal latitude
040    assertThrows(
041        IllegalArgumentException.class, () -> new GeoDistancePredicate("180", "100", "100km"));
042
043    // Illegal longitude
044    assertThrows(
045        IllegalArgumentException.class, () -> new GeoDistancePredicate("70", "240", "100km"));
046  }
047
048  @Test
049  public void testInvalidDistanceUnit() {
050    // Wrong distance units
051    assertThrows(
052        IllegalArgumentException.class, () -> new GeoDistancePredicate("60", "100", "100wt"));
053  }
054}