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 testGetVelocity() {
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 Vector3D actualVelocity = testPropagator.getVelocity(date, frame);
58          // THEN
59          final PVCoordinates expectedState = testPropagator.propagate(date).getPVCoordinates(frame);
60          Assertions.assertEquals(expectedState.getVelocity(), actualVelocity);
61      }
62  
63      @Test
64      void testGetPVCoordinates() {
65          // GIVEN
66          final TestPropagator testPropagator = new TestPropagator();
67          final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
68          final Frame frame = FramesFactory.getGCRF();
69          // WHEN
70          final PVCoordinates actualState = testPropagator.getPVCoordinates(date, frame);
71          // THEN
72          final PVCoordinates expectedState = testPropagator.propagate(date).getPVCoordinates(frame);
73          Assertions.assertEquals(expectedState.getPosition(), actualState.getPosition());
74          Assertions.assertEquals(expectedState.getVelocity(), actualState.getVelocity());
75      }
76  
77      private static SpacecraftState mockSpacecraftState(final AbsoluteDate date) {
78          final SpacecraftState mockedSpacecraftState = Mockito.mock(SpacecraftState.class);
79          Mockito.when(mockedSpacecraftState.getDate()).thenReturn(date);
80          final PVCoordinates pvCoordinates = new PVCoordinates(Vector3D.MINUS_I, Vector3D.PLUS_K);
81          final TimeStampedPVCoordinates tspvc = new TimeStampedPVCoordinates(date, pvCoordinates);
82          Mockito.when(mockedSpacecraftState.getPVCoordinates()).thenReturn(tspvc);
83          Mockito.when(mockedSpacecraftState.getPVCoordinates(Mockito.any(Frame.class))).thenReturn(tspvc);
84          Mockito.when(mockedSpacecraftState.getPosition(Mockito.any(Frame.class)))
85                  .thenReturn(pvCoordinates.getPosition());
86          Mockito.when(mockedSpacecraftState.getVelocity()).thenReturn(pvCoordinates.getVelocity());
87          return mockedSpacecraftState;
88      }
89  
90      private static class TestPropagator implements Propagator {
91  
92          @Override
93          public StepHandlerMultiplexer getMultiplexer() {
94              return null;
95          }
96  
97          @Override
98          public EphemerisGenerator getEphemerisGenerator() {
99              return null;
100         }
101 
102         @Override
103         public SpacecraftState getInitialState() {
104             return null;
105         }
106 
107         @Override
108         public void resetInitialState(SpacecraftState state) {
109             // not used in test
110         }
111 
112         @Override
113         public void addAdditionalDataProvider(AdditionalDataProvider<?> additionalDataProvider) {
114             // not used in test
115         }
116 
117         @Override
118         public List<AdditionalDataProvider<?>> getAdditionalDataProviders() {
119             return null;
120         }
121 
122         @Override
123         public boolean isAdditionalDataManaged(String name) {
124             return false;
125         }
126 
127         @Override
128         public String[] getManagedAdditionalData() {
129             return new String[0];
130         }
131 
132         @Override
133         public <T extends EventDetector> void addEventDetector(T detector) {
134             // not used in test
135         }
136 
137         @Override
138         public Collection<EventDetector> getEventDetectors() {
139             return null;
140         }
141 
142         @Override
143         public void clearEventsDetectors() {
144             // not used in test
145         }
146 
147         @Override
148         public AttitudeProvider getAttitudeProvider() {
149             return null;
150         }
151 
152         @Override
153         public void setAttitudeProvider(AttitudeProvider attitudeProvider) {
154             // not used in test
155         }
156 
157         @Override
158         public Frame getFrame() {
159             return FramesFactory.getGCRF();
160         }
161 
162         @Override
163         public SpacecraftState propagate(AbsoluteDate target) {
164             return mockSpacecraftState(target);
165         }
166 
167         @Override
168         public SpacecraftState propagate(AbsoluteDate start, AbsoluteDate target) {
169             return null;
170         }
171     }
172 
173 }