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.spring.boot.autoconfigure.web;
18  
19  import static org.mockito.ArgumentMatchers.any;
20  import static org.mockito.Mockito.mock;
21  import static org.mockito.Mockito.times;
22  import static org.mockito.Mockito.verify;
23  import static org.mockito.Mockito.when;
24  
25  import org.bremersee.geojson.GeoJsonGeometryFactory;
26  import org.bremersee.geojson.converter.GeometryConverters;
27  import org.junit.jupiter.api.Test;
28  import org.springframework.beans.factory.ObjectProvider;
29  import org.springframework.core.convert.converter.Converter;
30  import org.springframework.format.FormatterRegistry;
31  
32  /**
33   * The geo json web flux configurer test.
34   *
35   * @author Christian Bremer
36   */
37  class GeoJsonWebFluxConfigurerTest {
38  
39    private GeoJsonWebFluxConfigurer newInstance() {
40      //noinspection unchecked
41      ObjectProvider<GeoJsonGeometryFactory> objectProvider = mock(ObjectProvider.class);
42      when(objectProvider.getIfAvailable(any())).thenReturn(new GeoJsonGeometryFactory());
43      return new GeoJsonWebFluxConfigurer(objectProvider);
44    }
45  
46    /**
47     * Init.
48     */
49    @Test
50    void init() {
51      GeoJsonWebFluxConfigurer target = newInstance();
52      target.init();
53    }
54  
55    /**
56     * Add formatters.
57     */
58    @Test
59    void addFormatters() {
60      GeoJsonWebFluxConfigurer target = newInstance();
61      FormatterRegistry formatterRegistry = mock(FormatterRegistry.class);
62      target.addFormatters(formatterRegistry);
63      int wantedNumberOfInvocations = GeometryConverters
64          .getConvertersToRegister(new GeoJsonGeometryFactory())
65          .size();
66      verify(formatterRegistry, times(wantedNumberOfInvocations))
67          .addConverter(any(Converter.class));
68    }
69  }