View Javadoc
1   /*
2    * Copyright 2022 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.geojson.converter.deserialization;
18  
19  import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
20  import static org.bremersee.geojson.GeoJsonConstants.GEOMETRY_COLLECTION;
21  import static org.bremersee.geojson.GeoJsonConstants.TYPE;
22  
23  import java.util.Map;
24  import org.assertj.core.api.SoftAssertions;
25  import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
26  import org.junit.jupiter.api.Test;
27  import org.junit.jupiter.api.extension.ExtendWith;
28  import org.locationtech.jts.geom.Geometry;
29  
30  /**
31   * The type Json to geometry converter test.
32   *
33   * @author Christian Bremer
34   */
35  @ExtendWith(SoftAssertionsExtension.class)
36  class JsonToGeometryConverterTest {
37  
38    /**
39     * Convert and expect empty geometry.
40     *
41     * @param softly the softly
42     */
43    @Test
44    void convertAndExpectEmptyGeometry(SoftAssertions softly) {
45      JsonToGeometryConverter target = new JsonToGeometryConverter();
46      Geometry actual = target.convert(Map.of(TYPE, GEOMETRY_COLLECTION));
47      //noinspection unchecked
48      softly.assertThat(actual)
49          .isNotNull();
50      softly.assertThat(actual.getCoordinates())
51          .isEmpty();
52    }
53  
54    /**
55     * Convert and expect illegal argument exception.
56     */
57    @Test
58    void convertAndExpectIllegalArgumentException() {
59      JsonToGeometryConverter target = new JsonToGeometryConverter();
60      assertThatExceptionOfType(IllegalArgumentException.class)
61          .isThrownBy(() -> target.convert(Map.of("IllegalGeometry", new Object())));
62    }
63  }