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.sampling;
18  
19  import org.junit.jupiter.api.Test;
20  import org.mockito.Mockito;
21  import org.orekit.propagation.SpacecraftState;
22  import org.orekit.time.AbsoluteDate;
23  
24  import java.util.List;
25  
26  import static org.junit.jupiter.api.Assertions.*;
27  
28  class PropagationStepRecorderTest {
29  
30      @Test
31      void copyStatesAtConstructionTest() {
32          // GIVEN
33          final PropagationStepRecorder recorder = new PropagationStepRecorder();
34          // WHEN
35          final List<SpacecraftState> states = recorder.copyStates();
36          // THEN
37          assertEquals(0, states.size());
38      }
39  
40      @Test
41      void copyStatesTest() {
42          // GIVEN
43          final PropagationStepRecorder recorder = new PropagationStepRecorder();
44          recorder.handleStep(mockInterpolator());
45          // WHEN
46          recorder.init(mockState(), AbsoluteDate.ARBITRARY_EPOCH);
47          // THEN
48          final List<SpacecraftState> states = recorder.copyStates();
49          assertEquals(0, states.size());
50      }
51  
52      @Test
53      void handleStepTest() {
54          // GIVEN
55          final PropagationStepRecorder recorder = new PropagationStepRecorder();
56          final OrekitStepInterpolator mockedInterpolator = mockInterpolator();
57          final int expectedSize = 10;
58          // WHEN
59          for (int i = 0; i < expectedSize; ++i) {
60              recorder.handleStep(mockedInterpolator);
61          }
62          // WHEN
63          final List<SpacecraftState> states = recorder.copyStates();
64          assertEquals(expectedSize, states.size());
65      }
66  
67      private static OrekitStepInterpolator mockInterpolator() {
68          final SpacecraftState state = mockState();
69          final OrekitStepInterpolator mockedInterpolator = Mockito.mock();
70          Mockito.when(mockedInterpolator.getCurrentState()).thenReturn(state);
71          return mockedInterpolator;
72      }
73  
74      private static SpacecraftState mockState() {
75          return Mockito.mock(SpacecraftState.class);
76      }
77  }