1   /* Copyright 2022-2025 Romain Serra
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.propagation.events;
18  
19  import org.hipparchus.complex.Complex;
20  import org.hipparchus.complex.ComplexField;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  import org.mockito.Mockito;
24  import org.orekit.propagation.FieldSpacecraftState;
25  import org.orekit.propagation.events.handlers.FieldEventHandler;
26  import org.orekit.propagation.events.intervals.FieldAdaptableInterval;
27  
28  class FieldAbstractDetectorTest {
29  
30      @Test
31      void testWithDetectionSettings() {
32          // GIVEN
33          final ComplexField field = ComplexField.getInstance();
34          final FieldEventDetectionSettings<Complex> settings = new FieldEventDetectionSettings<>(field,
35                  EventDetectionSettings.getDefaultEventDetectionSettings());
36          final TestFieldDetector testDetector = new TestFieldDetector(settings, null);
37          final FieldAdaptableInterval mockedInterval = Mockito.mock(FieldAdaptableInterval.class);
38          final FieldEventDetectionSettings<Complex> expectedSettings = new FieldEventDetectionSettings<>(mockedInterval,
39                  Complex.ONE, 100);
40          // WHEN
41          final TestFieldDetector newDetector = testDetector.withDetectionSettings(expectedSettings);
42          // THEN
43          Assertions.assertEquals(mockedInterval, newDetector.getDetectionSettings().getMaxCheckInterval());
44          Assertions.assertEquals(expectedSettings.getThreshold(), newDetector.getDetectionSettings().getThreshold());
45          Assertions.assertEquals(expectedSettings.getMaxIterationCount(), newDetector.getDetectionSettings().getMaxIterationCount());
46      }
47  
48      private static class TestFieldDetector extends FieldAbstractDetector<TestFieldDetector, Complex> {
49  
50          protected TestFieldDetector(FieldEventDetectionSettings<Complex> detectionSettings, FieldEventHandler<Complex> handler) {
51              super(detectionSettings, handler);
52          }
53  
54          @Override
55          protected TestFieldDetector create(FieldEventDetectionSettings<Complex> detectionSettings, FieldEventHandler<Complex> newHandler) {
56              return new TestFieldDetector(detectionSettings, newHandler);
57          }
58  
59          @Override
60          public Complex g(FieldSpacecraftState<Complex> s) {
61              return null;
62          }
63      }
64  }