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;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.Test;
22  import org.mockito.Mockito;
23  import org.orekit.attitudes.AttitudeProvider;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.propagation.events.EventDetector;
27  import org.orekit.propagation.sampling.StepHandlerMultiplexer;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.utils.PVCoordinates;
30  import org.orekit.utils.TimeStampedPVCoordinates;
31  
32  import java.util.Collection;
33  import java.util.List;
34  
35  class PropagatorTest {
36  
37      @Test
38      void testGetPosition() {
39          // GIVEN
40          final TestPropagator testPropagator = new TestPropagator();
41          final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
42          final Frame frame = FramesFactory.getGCRF();
43          // WHEN
44          final Vector3D actualPosition = testPropagator.getPosition(date, frame);
45          // THEN
46          final PVCoordinates expectedState = testPropagator.propagate(date).getPVCoordinates(frame);
47          Assertions.assertEquals(expectedState.getPosition(), actualPosition);
48      }
49  
50      @Test
51      void testGetPVCoordinates() {
52          // GIVEN
53          final TestPropagator testPropagator = new TestPropagator();
54          final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
55          final Frame frame = FramesFactory.getGCRF();
56          // WHEN
57          final PVCoordinates actualState = testPropagator.getPVCoordinates(date, frame);
58          // THEN
59          final PVCoordinates expectedState = testPropagator.propagate(date).getPVCoordinates(frame);
60          Assertions.assertEquals(expectedState.getPosition(), actualState.getPosition());
61          Assertions.assertEquals(expectedState.getVelocity(), actualState.getVelocity());
62      }
63  
64      private static SpacecraftState mockSpacecraftState(final AbsoluteDate date) {
65          final SpacecraftState mockedSpacecraftState = Mockito.mock(SpacecraftState.class);
66          Mockito.when(mockedSpacecraftState.getDate()).thenReturn(date);
67          final PVCoordinates pvCoordinates = new PVCoordinates(Vector3D.MINUS_I, Vector3D.PLUS_K);
68          final TimeStampedPVCoordinates tspvc = new TimeStampedPVCoordinates(date, pvCoordinates);
69          Mockito.when(mockedSpacecraftState.getPVCoordinates()).thenReturn(tspvc);
70          Mockito.when(mockedSpacecraftState.getPVCoordinates(Mockito.any(Frame.class))).thenReturn(tspvc);
71          Mockito.when(mockedSpacecraftState.getPosition(Mockito.any(Frame.class)))
72                  .thenReturn(pvCoordinates.getPosition());
73          return mockedSpacecraftState;
74      }
75  
76      private static class TestPropagator implements Propagator {
77  
78          @Override
79          public StepHandlerMultiplexer getMultiplexer() {
80              return null;
81          }
82  
83          @Override
84          public EphemerisGenerator getEphemerisGenerator() {
85              return null;
86          }
87  
88          @Override
89          public SpacecraftState getInitialState() {
90              return null;
91          }
92  
93          @Override
94          public void resetInitialState(SpacecraftState state) {
95              // not used in test
96          }
97  
98          @Override
99          public void addAdditionalDataProvider(AdditionalDataProvider<?> additionalDataProvider) {
100             // not used in test
101         }
102 
103         @Override
104         public List<AdditionalDataProvider<?>> getAdditionalDataProviders() {
105             return null;
106         }
107 
108         @Override
109         public boolean isAdditionalDataManaged(String name) {
110             return false;
111         }
112 
113         @Override
114         public String[] getManagedAdditionalData() {
115             return new String[0];
116         }
117 
118         @Override
119         public <T extends EventDetector> void addEventDetector(T detector) {
120             // not used in test
121         }
122 
123         @Override
124         public Collection<EventDetector> getEventDetectors() {
125             return null;
126         }
127 
128         @Override
129         public void clearEventsDetectors() {
130             // not used in test
131         }
132 
133         @Override
134         public AttitudeProvider getAttitudeProvider() {
135             return null;
136         }
137 
138         @Override
139         public void setAttitudeProvider(AttitudeProvider attitudeProvider) {
140             // not used in test
141         }
142 
143         @Override
144         public Frame getFrame() {
145             return null;
146         }
147 
148         @Override
149         public SpacecraftState propagate(AbsoluteDate target) {
150             return mockSpacecraftState(target);
151         }
152 
153         @Override
154         public SpacecraftState propagate(AbsoluteDate start, AbsoluteDate target) {
155             return null;
156         }
157     }
158 
159 }