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.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.mockito.Mockito;
22  import org.orekit.propagation.SpacecraftState;
23  import org.orekit.propagation.events.handlers.EventHandler;
24  import org.orekit.propagation.events.intervals.AdaptableInterval;
25  
26  class AbstractDetectorTest {
27  
28      @Test
29      void testWithDetectionSettings() {
30          // GIVEN
31          final EventDetectionSettings settings = EventDetectionSettings.getDefaultEventDetectionSettings();
32          final TestDetector testDetector = new TestDetector(settings, null);
33          final AdaptableInterval mockedInterval = Mockito.mock(AdaptableInterval.class);
34          final EventDetectionSettings expectedSettings = new EventDetectionSettings(mockedInterval, 10., 100);
35          // WHEN
36          final TestDetector newDetector = testDetector.withDetectionSettings(expectedSettings);
37          // THEN
38          Assertions.assertEquals(mockedInterval, newDetector.getDetectionSettings().getMaxCheckInterval());
39          Assertions.assertEquals(expectedSettings.getThreshold(), newDetector.getDetectionSettings().getThreshold());
40          Assertions.assertEquals(expectedSettings.getMaxIterationCount(), newDetector.getDetectionSettings().getMaxIterationCount());
41      }
42  
43      private static class TestDetector extends AbstractDetector<TestDetector> {
44  
45          protected TestDetector(EventDetectionSettings eventDetectionSettings, EventHandler handler) {
46              super(eventDetectionSettings, handler);
47          }
48  
49          @Override
50          protected TestDetector create(EventDetectionSettings detectionSettings, EventHandler newHandler) {
51              return new TestDetector(detectionSettings, newHandler);
52          }
53  
54          @Override
55          public double g(SpacecraftState s) {
56              return 0;
57          }
58      }
59  
60  }